1717import java .io .BufferedReader ;
1818import java .io .File ;
1919import java .io .FileReader ;
20- import java .io . IOException ;
20+ import java .math . BigInteger ;
2121import java .util .ArrayList ;
2222import java .util .Collections ;
2323import java .util .Comparator ;
@@ -37,7 +37,10 @@ public class SimulationCache {
3737//ArrayList<MeasureType> MeasureList;
3838 private ArrayList <SimulationType > simulationList ;
3939 private int localSimulationCounter = 0 ;
40- private String tmpHash = "" ;
40+ //Variables for search in simulationCache
41+ private BigInteger tmpHash = BigInteger .ZERO ;
42+ private SimulationType tmpSimulation ;
43+ private ArrayList <MeasureType > myTmpList = new ArrayList ();
4144
4245 public SimulationCache () {
4346 //this.MeasureList = new ArrayList<MeasureType>();
@@ -299,21 +302,17 @@ public boolean checkIfAllParameterMatchTable(parameterTableModel myTableModel) {
299302 * It will just compare the hash values of the sorted parameterLists!
300303 *
301304 * @param parameterList given Set of Parameters to by virtually simulated
302- * @return ArrayList of MeasureTypes
305+ * @return ArrayList of MeasureTypes, null if not found
303306 */
304307 public ArrayList <MeasureType > getAllMeasuresWithParameterList (ArrayList <parameter > parameterList ) {
305- SimulationType tmpSimulation ;
306- ArrayList <MeasureType > myTmpList = new ArrayList ();
308+ myTmpList = null ;
307309 tmpHash = support .getHashStringForParameterList (parameterList );
308- //support.log(tmpHash + " = Needle.", typeOfLogLevel.VERBOSE);
309310
310- //support.log("Size of All Measures from File: "+MeasureList.size());
311- //Go through all Measures, find the one with the same parameterlist
311+ //Go through all Simulations, find the one with the same parameterlist
312312 for (int i = 0 ; i < this .getSimulationList ().size (); i ++) {
313313 tmpSimulation = this .getSimulationList ().get (i );
314- //if (compareParameterList(parameterList, tmpSimulation.getListOfParameters())) {
315- if (tmpHash .equals (tmpSimulation .getHashString ())) {
316- myTmpList = tmpSimulation .getMeasures (); //assuming cache-file did not have experiments with same Parameterset
314+ if (tmpHash .equals (tmpSimulation .getHashValue ())) {
315+ myTmpList = tmpSimulation .getMeasures ();
317316 }
318317 }
319318 return myTmpList ;
@@ -352,10 +351,12 @@ public int compare(Double[] a, Double[] b) {
352351 //}
353352 //indexOfZeroDistance should contain the index of the Distance >=0
354353 ArrayList <MeasureType > listOfMeasureWithGivenParameters = this .getAllMeasuresWithParameterList (this .getSimulationList ().get (distArrayList .get (indexOfZeroDistance )[1 ].intValue ()).getListOfParameters ());
355- if (listOfMeasureWithGivenParameters .size () > 0 ) {
354+ if (listOfMeasureWithGivenParameters != null ) {
355+ if (listOfMeasureWithGivenParameters .size () > 0 ) {
356356
357- this .setLocalSimulationCounter (this .getLocalSimulationCounter () + 1 );
358- return (this .getParserFromListOfMeasures (listOfMeasureWithGivenParameters ));
357+ this .setLocalSimulationCounter (this .getLocalSimulationCounter () + 1 );
358+ return (this .getSimulationFromListOfMeasures (listOfMeasureWithGivenParameters ));
359+ }
359360 }
360361 return null ;
361362 }
@@ -483,7 +484,9 @@ private parameter findParameterInListByName(String name, ArrayList<parameter> li
483484 */
484485 public ArrayList <SimulationType > getListOfCompletedSimulationParsers (ArrayList <ArrayList <parameter >> parameterSetList , int simulationCounter ) {
485486 setLocalSimulationCounter (simulationCounter );
486- ArrayList <SimulationType > myParserList = new ArrayList <SimulationType >();
487+ ArrayList <SimulationType > myParserList = new ArrayList <>();
488+ ArrayList <MeasureType > listOfMeasureWithGivenParameters ;
489+ ArrayList <parameter > parameterSet ;
487490
488491 support .log ("Updating all simulation hash values." , typeOfLogLevel .INFO );
489492 for (int i = 0 ; i < this .getSimulationList ().size (); i ++) {
@@ -497,30 +500,28 @@ public ArrayList<SimulationType> getListOfCompletedSimulationParsers(ArrayList<A
497500
498501 //for (ArrayList<parameter> parameterSet : parameterSetList) {
499502 for (int i = 0 ; i < parameterSetList .size (); i ++) {
500- ArrayList < parameter > parameterSet = parameterSetList .get (i );
503+ parameterSet = parameterSetList .get (i );
501504
502- //Create Arraylist from array of parameters
503- /*ArrayList<parameter> tmpParameterList = new ArrayList<parameter>();
504- for (parameter myParameter : parameterSet) {
505- tmpParameterList.add(myParameter);
506- }*/
507505 support .spinInLabel ();
508506
509507 support .setStatusText ("Searching in cache: " + i * 100 / parameterSetList .size () + " %" );
510508 //Get local simulation results
511- ArrayList < MeasureType > listOfMeasureWithGivenParameters = this .getAllMeasuresWithParameterList (parameterSet );
512- support . log ( "Size of ParameterList: " + parameterSet . size () + " results in " + listOfMeasureWithGivenParameters . size () + " Measurements." , typeOfLogLevel . VERBOSE );
509+ listOfMeasureWithGivenParameters = this .getAllMeasuresWithParameterList (parameterSet );
510+
513511 //append if listSize is > 0
514- if (listOfMeasureWithGivenParameters .size () > 0 ) {
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 .getParserFromListOfMeasures (listOfMeasureWithGivenParameters );
521- tmpParser .setListOfParameters (parameterSet );
522- myParserList .add (tmpParser );
523- simulationCounter ++;
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+ }
524525 }
525526 if (support .isCancelEverything ()) {
526527 return myParserList ;
@@ -539,16 +540,16 @@ public ArrayList<SimulationType> getListOfCompletedSimulationParsers(ArrayList<A
539540 * SimulationType
540541 * @return one SimulationType-object
541542 */
542- private SimulationType getParserFromListOfMeasures (ArrayList <MeasureType > mList ) {
543+ private SimulationType getSimulationFromListOfMeasures (ArrayList <MeasureType > mList ) {
543544 if (mList .size () > 0 ) {
544- SimulationType tmpParser = new SimulationType ();
545+ SimulationType tmpSimulation = new SimulationType ();
545546 for (int i = 0 ; i < mList .size (); i ++) {
546- tmpParser .setMeasures (mList );
547- //tmpParser .setSimulationTime(mList.get(i).getSimulationTime());
548- //tmpParser .setCPUTime(support.getInt(mList.get(i).getCPUTime()));
547+ tmpSimulation .setMeasures (mList );
548+ //tmpSimulation .setSimulationTime(mList.get(i).getSimulationTime());
549+ //tmpSimulation .setCPUTime(support.getInt(mList.get(i).getCPUTime()));
549550 }
550- tmpParser .setIsFromCache (true );
551- return tmpParser ;
551+ tmpSimulation .setIsFromCache (true );
552+ return tmpSimulation ;
552553 }
553554 return null ;
554555 }
0 commit comments