Skip to content

Commit 70933f6

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
fixed start-of-distributed-simulator-issue
minor refactoring/renaming
1 parent a070eca commit 70933f6

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

TimeNETOptimizationEnvironment/src/toe/simulation/SimulationCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ private parameter findParameterInListByName(String name, ArrayList<parameter> li
482482
* @param simulationCounter Counter of Simulations
483483
* @return List of parsers with Simulation-Results, like in real simulation
484484
*/
485-
public ArrayList<SimulationType> getListOfCompletedSimulationParsers(ArrayList<ArrayList<parameter>> parameterSetList, int simulationCounter) {
485+
public ArrayList<SimulationType> getListOfCompletedSimulations(ArrayList<ArrayList<parameter>> parameterSetList, int simulationCounter) {
486486
setLocalSimulationCounter(simulationCounter);
487487
ArrayList<SimulationType> myParserList = new ArrayList<>();
488488
ArrayList<MeasureType> listOfMeasureWithGivenParameters;

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorCached.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public SimulatorCached() {
4343
@Override
4444
public void initSimulator(ArrayList<ArrayList<parameter>> listOfParameterSetsTMP, boolean log) {
4545
if (mySimulationCache != null) {
46-
this.myListOfSimulations = mySimulationCache.getListOfCompletedSimulationParsers(listOfParameterSetsTMP, support.getGlobalSimulationCounter());
46+
this.myListOfSimulations = mySimulationCache.getListOfCompletedSimulations(listOfParameterSetsTMP, support.getGlobalSimulationCounter());
4747
support.setGlobalSimulationCounter(support.getGlobalSimulationCounter() + myListOfSimulations.size());
4848
} else {
4949
support.log("No local Simulation file loaded. Simulation not possible.", typeOfLogLevel.ERROR);

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorCachedLocal.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package toe.simulation;
99

1010
import java.util.ArrayList;
11+
import java.util.Iterator;
1112
import toe.datamodel.parameter;
1213
import toe.datamodel.SimulationType;
1314
import toe.support;
@@ -21,7 +22,7 @@
2122
*/
2223
public class SimulatorCachedLocal extends SimulatorCached {
2324

24-
private ArrayList<SimulationType> myListOfSimulationParsers = null;
25+
private ArrayList<SimulationType> myListOfCompletedSimulations = null;
2526
private int status;
2627
private final Simulator myLocalSimulator = getNoCacheSimulator();
2728
private ArrayList< ArrayList<parameter>> remainingParametersets = new ArrayList<>();
@@ -45,7 +46,7 @@ public SimulatorCachedLocal() {
4546
@Override
4647
public void initSimulator(ArrayList< ArrayList<parameter>> listOfParameterSetsTMP, boolean log) {
4748

48-
this.myListOfSimulationParsers = null;
49+
this.myListOfCompletedSimulations = null;
4950
remainingParametersets = new ArrayList<>();
5051
status = 0;
5152
this.listOfParameterSetsTMP = listOfParameterSetsTMP;
@@ -63,35 +64,43 @@ public void initSimulator(ArrayList< ArrayList<parameter>> listOfParameterSetsTM
6364
public void run() {
6465
if (mySimulationCache != null) {
6566
support.log("Will load available results from simulation cache.", typeOfLogLevel.INFO);
66-
this.myListOfSimulationParsers = mySimulationCache.getListOfCompletedSimulationParsers(listOfParameterSetsTMP, support.getGlobalSimulationCounter());
67+
this.myListOfCompletedSimulations = mySimulationCache.getListOfCompletedSimulations(listOfParameterSetsTMP, support.getGlobalSimulationCounter());
6768
} else {
6869
support.log("No local Simulation file loaded. Will build my own cache from scratch.", typeOfLogLevel.INFO);
6970
this.mySimulationCache = support.getMySimulationCache();
7071
}
7172

72-
if (this.myListOfSimulationParsers == null) {
73+
if (this.myListOfCompletedSimulations == null) {
7374
support.log("No Simulation found in local Cache. Starting simulation.", typeOfLogLevel.INFO);
74-
this.myListOfSimulationParsers = new ArrayList<>();
75+
this.myListOfCompletedSimulations = new ArrayList<>();
7576
}
7677

77-
status = myListOfSimulationParsers.size() * 100 / listOfParameterSetsTMP.size();
78-
support.setStatusText("Simulating " + myListOfSimulationParsers.size() + "/" + listOfParameterSetsTMP.size());
78+
status = myListOfCompletedSimulations.size() * 100 / listOfParameterSetsTMP.size();
79+
support.setStatusText("Simulating " + myListOfCompletedSimulations.size() + "/" + listOfParameterSetsTMP.size());
7980
//Increase Simulationcounter only if Simulation results are found in cache
8081
//Local or benchmark-simulators will update the counter on their own
81-
support.setGlobalSimulationCounter(support.getGlobalSimulationCounter() + myListOfSimulationParsers.size());
82+
support.setGlobalSimulationCounter(support.getGlobalSimulationCounter() + myListOfCompletedSimulations.size());
8283

83-
if (this.myListOfSimulationParsers.size() < listOfParameterSetsTMP.size()) {
84+
if (this.myListOfCompletedSimulations.size() < listOfParameterSetsTMP.size()) {
8485
support.log("Some simulations were missing in cache. Will simulate them local/distributed.", typeOfLogLevel.INFO);
8586

8687
for (ArrayList<parameter> myParameterset : listOfParameterSetsTMP) {
8788
remainingParametersets.add(myParameterset);
8889
}
8990

90-
for (ArrayList<parameter> myParameterset : listOfParameterSetsTMP) {
91-
for (SimulationType myListOfSimulationParser : this.myListOfSimulationParsers) {
91+
ArrayList<parameter> myParameterset;
92+
for (int i = 0; i < listOfParameterSetsTMP.size(); i++) {
93+
myParameterset = listOfParameterSetsTMP.get(i);
94+
support.spinInLabel();
95+
support.setStatusText("Build new List: " + i * 100 / listOfParameterSetsTMP.size() + " %");
96+
//for (ArrayList<parameter> myParameterset : listOfParameterSetsTMP) {
97+
for (SimulationType myListOfSimulationParser : this.myListOfCompletedSimulations) {
9298
if (this.mySimulationCache.compareParameterList(myListOfSimulationParser.getListOfParametersFittedToBaseParameterset(), myParameterset)) {
9399
remainingParametersets.remove(myParameterset);
94100
}
101+
if (support.isCancelEverything()) {
102+
return;
103+
}
95104
}
96105
}
97106
support.log("Size of Remaining ParameterList is " + remainingParametersets.size(), typeOfLogLevel.INFO);
@@ -100,30 +109,29 @@ public void run() {
100109
if (support.isCancelEverything()) {
101110
return;
102111
}
103-
myLocalSimulator.initSimulator(remainingParametersets, false);
104-
//support.waitForEndOfSimulator(myLocalSimulator, support.getGlobalSimulationCounter(), support.DEFAULT_TIMEOUT);
105112

106113
synchronized (myLocalSimulator) {
107114
try {
115+
myLocalSimulator.initSimulator(remainingParametersets, false);
108116
myLocalSimulator.wait();
109117
} catch (InterruptedException ex) {
110118
support.log("Problem waiting for end of non-cache-simulator.", typeOfLogLevel.ERROR);
111119
}
112120
}
113121

114-
myListOfSimulationParsers.addAll(myLocalSimulator.getListOfCompletedSimulationParsers());
115-
status = myListOfSimulationParsers.size() * 100 / listOfParameterSetsTMP.size();
122+
myListOfCompletedSimulations.addAll(myLocalSimulator.getListOfCompletedSimulationParsers());
123+
status = myListOfCompletedSimulations.size() * 100 / listOfParameterSetsTMP.size();
116124

117-
support.log("Size of resultList is " + myListOfSimulationParsers.size(), typeOfLogLevel.INFO);
125+
support.log("Size of resultList is " + myListOfCompletedSimulations.size(), typeOfLogLevel.INFO);
118126

119127
this.mySimulationCache.addListOfSimulationsToCache(myLocalSimulator.getListOfCompletedSimulationParsers());
120128
support.log("Size of SimulationCache: " + this.mySimulationCache.getCacheSize(), typeOfLogLevel.INFO);
121129
}
122130

123-
if (this.myListOfSimulationParsers != null) {
124-
support.log("Adding " + myListOfSimulationParsers.size() + " Results to logfile.", typeOfLogLevel.INFO);
131+
if (this.myListOfCompletedSimulations != null) {
132+
support.log("Adding " + myListOfCompletedSimulations.size() + " Results to logfile.", typeOfLogLevel.INFO);
125133
//Print out a log file
126-
support.addLinesToLogFileFromListOfParser(myListOfSimulationParsers, logFileName);
134+
support.addLinesToLogFileFromListOfParser(myListOfCompletedSimulations, logFileName);
127135
support.log("SimulationCounter is now: " + support.getGlobalSimulationCounter(), typeOfLogLevel.INFO);
128136
}
129137

@@ -162,7 +170,7 @@ public Simulator getNoCacheSimulator() {
162170
*/
163171
@Override
164172
public ArrayList<SimulationType> getListOfCompletedSimulationParsers() {
165-
return this.myListOfSimulationParsers;
173+
return this.myListOfCompletedSimulations;
166174
}
167175

168176
/**

0 commit comments

Comments
 (0)