2121import java .util .ArrayList ;
2222import java .util .Collections ;
2323import java .util .Comparator ;
24+ import java .util .HashMap ;
2425import javax .swing .JOptionPane ;
2526import toe .typedef .typeOfLogLevel ;
2627
@@ -41,10 +42,12 @@ public class SimulationCache {
4142 private BigInteger tmpHash = BigInteger .ZERO ;
4243 private SimulationType tmpSimulation ;
4344 private ArrayList <MeasureType > myTmpList = new ArrayList ();
45+ private HashMap <BigInteger , SimulationType > simulationHashmap ;
4446
4547 public SimulationCache () {
4648 //this.MeasureList = new ArrayList<MeasureType>();
47- this .simulationList = new ArrayList <SimulationType >();
49+ this .simulationList = new ArrayList <>();
50+ this .simulationHashmap = new HashMap <>();
4851 }
4952
5053 public boolean parseSimulationCacheFile (String filename , ArrayList <MeasureType > listOfMeasures , parameterTableModel myParameterTableModel , MainFrame myParentFrame ) {
@@ -214,7 +217,8 @@ public boolean parseSimulationCacheFile(String filename, ArrayList<MeasureType>
214217 //this.MeasureList.add(tmpSimulation);
215218
216219 }
217- getSimulationList ().add (tmpSimulation );
220+ //getSimulationList().add(tmpSimulation);
221+ addSimulationToCache (tmpSimulation );
218222 }
219223
220224 //Do not reformat Parameter-Table
@@ -480,57 +484,38 @@ private parameter findParameterInListByName(String name, ArrayList<parameter> li
480484 *
481485 * @param parameterSetList List of Parameter-Arrays to be "simulated"
482486 * @param simulationCounter Counter of Simulations
487+ * @param listOfUnknownParametersets given by reference, this list will
488+ * contain all parametersets not found in cache
483489 * @return List of parsers with Simulation-Results, like in real simulation
484490 */
485- public ArrayList <SimulationType > getListOfCompletedSimulations (ArrayList <ArrayList <parameter >> parameterSetList , int simulationCounter ) {
491+ public ArrayList <SimulationType > getListOfCompletedSimulations (ArrayList <ArrayList <parameter >> parameterSetList , int simulationCounter , ArrayList < ArrayList < parameter >> listOfUnknownParametersets ) {
486492 setLocalSimulationCounter (simulationCounter );
487- ArrayList <SimulationType > myParserList = new ArrayList <>();
488- ArrayList <MeasureType > listOfMeasureWithGivenParameters ;
493+ ArrayList <SimulationType > mySimulationList = new ArrayList <>();
489494 ArrayList <parameter > parameterSet ;
490495
491- support .log ("Updating all simulation hash values." , typeOfLogLevel .INFO );
492- for (int i = 0 ; i < this .getSimulationList ().size (); i ++) {
493- this .getSimulationList ().get (i ).updateHashString ();
494- support .setStatusText ("Updating Hashs: " + i * 100 / this .getSimulationList ().size () + " %" );
495- if (support .isCancelEverything ()) {
496- return null ;
497- }
498- }
499- support .log ("All hash values in cache up to date." , typeOfLogLevel .VERBOSE );
500-
501- //for (ArrayList<parameter> parameterSet : parameterSetList) {
502496 for (int i = 0 ; i < parameterSetList .size (); i ++) {
503497 parameterSet = parameterSetList .get (i );
504498
505499 support .spinInLabel ();
506-
507500 support .setStatusText ("Searching in cache: " + i * 100 / parameterSetList .size () + " %" );
508- //Get local simulation results
509- listOfMeasureWithGivenParameters = this .getAllMeasuresWithParameterList (parameterSet );
510-
511- //append if listSize is > 0
512- if (listOfMeasureWithGivenParameters != null ) {
513- if (listOfMeasureWithGivenParameters .size () > 0 ) {
514- /*
515- SimulationType tmpParser=new SimulationType();
516- tmpParser.setMeasures(listOfMeasureWithGivenParameters);
517- tmpParser.setSimulationTime(listOfMeasureWithGivenParameters.get(i).getSimulationTime());
518- tmpParser.setCPUTime(support.getInt(listOfMeasureWithGivenParameters.get(i).getCPUTime()));
519- */
520- SimulationType tmpParser = this .getSimulationFromListOfMeasures (listOfMeasureWithGivenParameters );
521- tmpParser .setListOfParameters (parameterSet );
522- myParserList .add (tmpParser );
523- simulationCounter ++;
524- }
501+
502+ //Get cached simulation results
503+ SimulationType foundSimulation = simulationHashmap .get (support .getHashStringForParameterList (parameterSet ));
504+ if (foundSimulation != null ) {
505+ mySimulationList .add (foundSimulation );
506+ simulationCounter ++;
507+ } else {
508+ listOfUnknownParametersets .add (parameterSet );
525509 }
510+
526511 if (support .isCancelEverything ()) {
527- return myParserList ;
512+ return mySimulationList ;
528513 }
529514 }
530- if (myParserList .isEmpty ()) {
515+ if (mySimulationList .isEmpty ()) {
531516 return null ;
532517 }
533- return myParserList ;
518+ return mySimulationList ;
534519 }
535520
536521 /**
@@ -588,7 +573,9 @@ public void addListOfSimulationsToCache(ArrayList<SimulationType> SimulationList
588573 * @param SimulationToAdd Simulation to be added
589574 */
590575 public void addSimulationToCache (SimulationType SimulationToAdd ) {
591- this .getSimulationList ().add (SimulationToAdd );
576+ SimulationToAdd .updateHashString ();
577+ //this.getSimulationList().add(SimulationToAdd);
578+ simulationHashmap .put (SimulationToAdd .getHashValue (), SimulationToAdd );
592579 }
593580
594581 /**
@@ -621,6 +608,6 @@ public ArrayList<SimulationType> getSimulationList() {
621608 * @return Size of SimulationList
622609 */
623610 public int getCacheSize () {
624- return this . simulationList .size ();
611+ return simulationList .size ();
625612 }
626613}
0 commit comments