Skip to content

Commit 0aad12c

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
fixed target distance compare, added some log output
1 parent 1e33a25 commit 0aad12c

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorBenchmark.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.io.File;
99
import java.util.ArrayList;
1010
import java.util.Calendar;
11-
import toe.SimOptiFactory;
1211
import toe.datamodel.parameter;
1312
import toe.datamodel.SimulationType;
1413
import toe.datamodel.MeasureType;
@@ -33,10 +32,10 @@ public class SimulatorBenchmark extends Thread implements Simulator, SimOptiCall
3332
int status = 0;
3433
boolean log = true;
3534
ArrayList<ArrayList<parameter>> listOfParameterSetsTMP;
36-
boolean isOptimumCalculated = false; // by default optimum coordinates are not calculated
35+
//boolean isOptimumCalculated = false; // by default optimum coordinates are not calculated
3736
boolean cancelAllSimulations = false;//Flag to cancel all simulations
3837
private SimOptiCallback listener = null;
39-
private Simulator mySimulator = null;
38+
private SimulationType calculatedOptimum = null;
4039

4140
/**
4241
* Constructor
@@ -185,7 +184,11 @@ public void run() {
185184
*/
186185
@Override
187186
public SimulationType getCalculatedOptimum(MeasureType targetMeasure) {
188-
return BenchmarkFactory.getBenchmarkFunction().getOptimumSimulation(targetMeasure);
187+
if (calculatedOptimum != null) {
188+
return this.calculatedOptimum;
189+
} else {
190+
return BenchmarkFactory.getBenchmarkFunction().getOptimumSimulation(targetMeasure);
191+
}
189192
}
190193

191194
@Override
@@ -201,7 +204,7 @@ public String getLogfileName() {
201204

202205
@Override
203206
public boolean isOptimumCalculated() {
204-
return isOptimumCalculated;
207+
return (this.calculatedOptimum != null);
205208
}
206209

207210
@Override
@@ -230,10 +233,8 @@ public void startCalculatingOptimum(SimOptiCallback listener) {
230233
//If yes --> warn before simulation
231234
//--> simulate all and check for optimum.
232235
//Same procedure as jButtonStartBatchSimulationActionPerformed in Mainframe
233-
//support.waitForSimulatorAsynchronous(mySimulator, listener);
234-
this.mySimulator = SimOptiFactory.getSimulator();
235-
mySimulator.initSimulator(support.getMainFrame().getListOfParameterSetsToBeWritten(), false);
236-
support.waitForSimulatorAsynchronous(mySimulator, this);
236+
this.initSimulator(support.getMainFrame().getListOfParameterSetsToBeWritten(), false);
237+
support.waitForSimulatorAsynchronous(this, this);
237238

238239
}
239240

@@ -247,25 +248,29 @@ public void stopCalculatingOptimum(SimOptiCallback listener) {
247248
public void discardCalculatedOptimum() {
248249
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
249250
support.log("TBD Implement: discardCalculatedOptimum()", typeOfLogLevel.ERROR);
251+
this.calculatedOptimum = null;
250252
}
251253

252254
@Override
253255
public void operationFeedback(String message, typedef.typeOfProcessFeedback feedback) {
254256
try {
255257
switch (feedback) {
256258
case SimulationSuccessful:
257-
ArrayList<SimulationType> simulationResults = mySimulator.getListOfCompletedSimulations();
259+
ArrayList<SimulationType> simulationResults = this.getListOfCompletedSimulations();
258260
double oldDistance = simulationResults.get(0).getDistanceToTargetValue();
259261
ArrayList<SimulationType> foundOptima = new ArrayList<SimulationType>();
260262
foundOptima.add(simulationResults.get(0));
261263

262264
for (int i = 1; i < simulationResults.size(); i++) {
265+
support.log(String.valueOf(simulationResults.get(i).getDistanceToTargetValue()), typeOfLogLevel.VERBOSE);
263266
if (oldDistance > simulationResults.get(i).getDistanceToTargetValue()) {
264267
foundOptima.clear();
265268
foundOptima.add(simulationResults.get(i));
266-
} else if (oldDistance == simulationResults.get(i).getDistanceToTargetValue()) {
269+
oldDistance = simulationResults.get(i).getDistanceToTargetValue();
270+
} else if (Math.abs(oldDistance - simulationResults.get(i).getDistanceToTargetValue()) < support.DEFAULT_TARGET_STEPPING) {
267271
foundOptima.add(simulationResults.get(i));
268272
}
273+
269274
}
270275

271276
if (foundOptima.size() < 1) {
@@ -274,21 +279,36 @@ public void operationFeedback(String message, typedef.typeOfProcessFeedback feed
274279
} else if (foundOptima.size() > 1) {
275280
//Not unique
276281
listener.operationFeedback("Selected Target is not unique There are " + foundOptima.size() + " same targets.", typedef.typeOfProcessFeedback.TargetValueNotUnique);
277-
support.log("The distance to target is: "+ oldDistance, typeOfLogLevel.INFO);
282+
support.log("The distance to target is: " + oldDistance, typeOfLogLevel.INFO);
278283
} else if (foundOptima.size() == 1) {
279284
//Exactly one optimum with selected target value was found
280285
if (oldDistance > 0.0) {
281286
//distance not zero --> will adapt selected optimum!
282287
listener.operationFeedback("Target is unique, will change target value to match distance of 0.0.", typedef.typeOfProcessFeedback.TargetCheckSuccessful);
283-
support.log("Old distance to target is: "+ oldDistance, typeOfLogLevel.INFO);
288+
support.log("Old distance to target is: " + oldDistance, typeOfLogLevel.INFO);
284289

285290
} else {
286291
listener.operationFeedback("Target is unique and distance is 0.0!", typedef.typeOfProcessFeedback.TargetCheckSuccessful);
287292
}
288293
}
294+
support.log("Target value(s) found at: ", typeOfLogLevel.RESULT);
295+
for (int i = 0; i < foundOptima.size(); i++) {
296+
support.log("Parameterset: " + i, typeOfLogLevel.RESULT);
297+
for (int c = 0; c < foundOptima.get(i).getListOfParameters().size(); c++) {
298+
if (foundOptima.get(i).getListOfParameters().get(c).isIteratable()) {
299+
foundOptima.get(i).getListOfParameters().get(c).printInfo(typeOfLogLevel.INFO);
300+
}
301+
}
302+
if (i == 0) {
303+
support.log("Targetvalue #0 will be used for optimization and statistics.", typeOfLogLevel.RESULT);
304+
}
305+
}
306+
307+
calculatedOptimum = foundOptima.get(0);
308+
289309
//Store simulation results in mainframe for next targetcheck, until table was changed?
290310
//Should be done during batch simulation???
291-
311+
//Store best optimum to be returned by getCalculatedOptimum
292312
break;
293313
case SimulationCanceled:
294314
support.log("Simulation aborted during targetcheck.", typeOfLogLevel.INFO);

0 commit comments

Comments
 (0)