Skip to content

Commit 89b5f92

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
distributed simulation will no longer use temporary xml parameter files.
tmp solution
1 parent 6fe4a38 commit 89b5f92

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorDistributed.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
import java.io.File;
1515
import java.io.FileWriter;
16+
import java.math.BigInteger;
1617
import java.util.ArrayList;
1718
import java.util.Calendar;
19+
import java.util.HashMap;
1820
import javax.xml.parsers.DocumentBuilder;
1921
import javax.xml.parsers.DocumentBuilderFactory;
2022
import javax.xml.transform.Transformer;
@@ -49,6 +51,7 @@ public class SimulatorDistributed extends Thread implements Simulator {
4951

5052
String logFileName = "";
5153
ArrayList< ArrayList<parameter>> listOfParameterSets;
54+
private HashMap<String, ArrayList<parameter>> listOfParametersetsByFileNameHashmap = new HashMap<>();
5255
ArrayList<SimulationType> listOfCompletedSimulationParsers;
5356
ArrayList<String> listOfUnproccessedFilesNames;
5457
String originalFilename;
@@ -80,6 +83,7 @@ public SimulatorDistributed() {
8083
public void run() {
8184
client = HttpFactory.getHttpClient();
8285
boolean uploadSuccessful;//To handle upload errors
86+
ArrayList<parameter> actualParameterSet;
8387

8488
support.log("Web-Simulation-Thread started to simulate " + listOfParameterSets.size() + " simulations.", typeOfLogLevel.INFO);
8589
if (support.isDistributedSimulationAvailable()) {
@@ -97,7 +101,7 @@ public void run() {
97101
if (cancelSimulations) {
98102
return;
99103
}
100-
ArrayList<parameter> actualParameterSet = listOfParameterSets.get(i);//get actual parameterset
104+
actualParameterSet = listOfParameterSets.get(i);//get actual parameterset
101105

102106
String actualParameterFileName = createLocalSimulationFile(actualParameterSet, support.getGlobalSimulationCounter());//create actual SCPN xml-file and save it in tmp-folder
103107
File file = new File(actualParameterFileName);
@@ -120,14 +124,18 @@ public void run() {
120124
}
121125
//add the file to the unprocessed files names
122126
listOfUnproccessedFilesNames.add(support.removeExtention(file.getName()));
127+
listOfParametersetsByFileNameHashmap.put(support.removeExtention(file.getName()), actualParameterSet);
128+
support.log("Used xml-filename in hashmap: " + support.removeExtention(file.getName()), typeOfLogLevel.VERBOSE);
129+
support.del(file);//delete tmp xml-file
123130
support.incGlobalSimulationCounter();
124131
if (support.isCancelEverything()) {
125132
break;
126133
}
127134
}
128135
}
129136
} catch (Exception e) {
130-
support.log("Error while creating local simulation file or log-file.", typeOfLogLevel.ERROR);
137+
support.log("Error while uploading simulations to server.", typeOfLogLevel.ERROR);
138+
support.log(e.getMessage(), typeOfLogLevel.ERROR);
131139
}
132140
//end of the first phase which is uploading the XML files
133141

@@ -166,6 +174,15 @@ public void run() {
166174
fileWriter.close();
167175
actualSimulationLogFile = exportFileName;
168176

177+
String[] tmpArrayToGetSimulationCounter=filenameWithoutExtension.split("n_");
178+
tmpArrayToGetSimulationCounter = tmpArrayToGetSimulationCounter[1].split("_Max");
179+
180+
181+
//create the xml-file again for parsing, tmp solution
182+
support.log("Used xml-filename on network: " + filenameWithoutExtension, typeOfLogLevel.VERBOSE);
183+
actualParameterSet = listOfParametersetsByFileNameHashmap.get(filenameWithoutExtension);
184+
createLocalSimulationFile(actualParameterSet, new Integer(tmpArrayToGetSimulationCounter[0]));
185+
169186
Parser myParser = new Parser();
170187
SimulationType myResults = myParser.parse(actualSimulationLogFile);//parse Log-file and xml-file
171188

0 commit comments

Comments
 (0)