88package toe .simulation ;
99
1010import java .util .ArrayList ;
11+ import java .util .Iterator ;
1112import toe .datamodel .parameter ;
1213import toe .datamodel .SimulationType ;
1314import toe .support ;
2122 */
2223public 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