Skip to content

Commit 49191b9

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
copyied targetcehck to benchmark-simulator
added feedback for targetcheck in locla simulator
1 parent b83193d commit 49191b9

File tree

3 files changed

+98
-16
lines changed

3 files changed

+98
-16
lines changed

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void stopCalculatingOptimum(SimOptiCallback listener) {
233233

234234
@Override
235235
public void discardCalculatedOptimum() {
236-
support.log("TBD Implement: discardCalculatedOptimum()", typeOfLogLevel.ERROR);
236+
support.log("CalculatedOptimum will be discarded.", typeOfLogLevel.INFO);
237237
this.calculatedOptimum = null;
238238
}
239239

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorCached.java

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import toe.datamodel.MeasureType;
1414
import toe.helper.SimOptiCallback;
1515
import toe.support;
16+
import toe.typedef;
1617
import toe.typedef.typeOfLogLevel;
1718

1819
/**
@@ -21,14 +22,16 @@
2122
*
2223
* @author Christoph Bodenstein
2324
*/
24-
public class SimulatorCached extends Thread implements Simulator {
25+
public class SimulatorCached extends Thread implements Simulator, SimOptiCallback {
2526

2627
//Temporary simulation cache, to store current simulation results. Results find in this cache are taged as "isCache", other results are tagged as fresh simulations
2728
SimulationCache myTmpSimulationCache = support.getTmpSimulationCache();
2829
ArrayList<SimulationType> myListOfSimulations = null;
2930
final String logFileName;
3031
ArrayList<ArrayList<parameter>> listOfParameterSetsTMP = null;
3132
boolean log = false;
33+
private SimOptiCallback listener = null;
34+
private SimulationType calculatedOptimum = null;
3235

3336
/**
3437
* Constructor
@@ -232,26 +235,105 @@ public String getLogfileName() {
232235
return this.logFileName;
233236
}
234237

235-
@Override
238+
@Override
236239
public boolean isOptimumCalculated() {
237-
return true;
240+
return (this.calculatedOptimum != null);
238241
}
239242

240243
@Override
241244
public void startCalculatingOptimum(SimOptiCallback listener) {
242-
//TODO: implement later
243-
throw new UnsupportedOperationException("Not supported yet.");
245+
this.listener = listener;
246+
//Check if all parametersets are generated (ListOfParameterSetsToBeWritten)
247+
if (support.getMainFrame().getListOfParameterSetsToBeWritten().size() <= support.DEFAULT_MINIMUM_DESIGNSPACE_FOR_OPTIMIZATION) {
248+
support.setStatusText("Not enaugh Parametersets to simulate for target check.");
249+
support.log("No Parametersets to simulate for target check.", typeOfLogLevel.INFO);
250+
listener.operationFeedback("Generate DS first!", typedef.typeOfProcessFeedback.TargetCheckFailed);
251+
return;
252+
} else {
253+
//If not, ask to generate it (not necessary, button is disabled in this case)
254+
}
255+
support.setParameterBase(support.getMainFrame().getParameterBase());
256+
support.setOriginalParameterBase(support.getMainFrame().getParameterBase());
257+
this.initSimulator(support.getMainFrame().getListOfParameterSetsToBeWritten(), false);
258+
support.waitForSimulatorAsynchronous(this, this);
244259
}
245260

246261
@Override
247262
public void stopCalculatingOptimum(SimOptiCallback listener) {
248-
//TODO: implement later
249-
throw new UnsupportedOperationException("Not supported yet.");
263+
listener.operationFeedback("Targetcheck canceled.", typedef.typeOfProcessFeedback.TargetDiscarded);
264+
this.calculatedOptimum = null;
250265
}
251266

252267
@Override
253268
public void discardCalculatedOptimum() {
254-
//TODO: implement later
255-
throw new UnsupportedOperationException("Not supported yet.");
269+
support.log("CalculatedOptimum will be discarded.", typeOfLogLevel.INFO);
270+
this.calculatedOptimum = null;
271+
}
272+
273+
@Override
274+
public void operationFeedback(String message, typedef.typeOfProcessFeedback feedback) {
275+
try {
276+
switch (feedback) {
277+
case SimulationSuccessful:
278+
ArrayList<SimulationType> simulationResults = this.getListOfCompletedSimulations();
279+
double oldDistance = simulationResults.get(0).getDistanceToTargetValue();
280+
ArrayList<SimulationType> foundOptima = new ArrayList<>();
281+
foundOptima.add(simulationResults.get(0));
282+
283+
for (int i = 1; i < simulationResults.size(); i++) {
284+
support.spinInLabel();
285+
support.log(String.valueOf(simulationResults.get(i).getDistanceToTargetValue()), typeOfLogLevel.VERBOSE);
286+
if (oldDistance > simulationResults.get(i).getDistanceToTargetValue()) {
287+
foundOptima.clear();
288+
foundOptima.add(simulationResults.get(i));
289+
oldDistance = simulationResults.get(i).getDistanceToTargetValue();
290+
} else if (Math.abs(oldDistance - simulationResults.get(i).getDistanceToTargetValue()) < support.DEFAULT_TARGET_STEPPING) {
291+
foundOptima.add(simulationResults.get(i));
292+
}
293+
}
294+
295+
if (foundOptima.size() < 1) {
296+
//Error checking the target
297+
listener.operationFeedback("Opticheck failed.", typedef.typeOfProcessFeedback.TargetCheckFailed);
298+
} else if (foundOptima.size() > 1) {
299+
//Not unique
300+
listener.operationFeedback("Selected Target is not unique There are " + foundOptima.size() + " same targets.", typedef.typeOfProcessFeedback.TargetValueNotUnique);
301+
support.log("The distance to target is: " + oldDistance, typeOfLogLevel.INFO);
302+
} else if (foundOptima.size() == 1) {
303+
//Exactly one optimum with selected target value was found
304+
if (oldDistance > 0.0) {
305+
//distance not zero --> will adapt selected optimum!
306+
listener.operationFeedback("Target is unique, will change target value to match distance of 0.0.", typedef.typeOfProcessFeedback.TargetCheckSuccessful);
307+
support.log("Old distance to target is: " + oldDistance, typeOfLogLevel.INFO);
308+
309+
} else {
310+
listener.operationFeedback("Target is unique and distance is 0.0!", typedef.typeOfProcessFeedback.TargetCheckSuccessful);
311+
}
312+
}
313+
support.log("Target value(s) found at: ", typeOfLogLevel.RESULT);
314+
for (int i = 0; i < foundOptima.size(); i++) {
315+
support.log("Parameterset: " + i, typeOfLogLevel.RESULT);
316+
for (int c = 0; c < foundOptima.get(i).getListOfParameters().size(); c++) {
317+
if (foundOptima.get(i).getListOfParameters().get(c).isIteratable()) {
318+
foundOptima.get(i).getListOfParameters().get(c).printInfo(typeOfLogLevel.INFO);
319+
}
320+
}
321+
}
322+
support.log("Targetvalue #0 will be used for optimization and statistics.", typeOfLogLevel.RESULT);
323+
calculatedOptimum = foundOptima.get(0);
324+
break;
325+
case SimulationCanceled:
326+
support.log("Simulation aborted during targetcheck.", typeOfLogLevel.INFO);
327+
listener.operationFeedback("Targetecheck aborted.", typedef.typeOfProcessFeedback.TargetCheckFailed);
328+
break;
329+
default:
330+
support.log("Unexpected feedback from simulator during targetcheck.", typeOfLogLevel.ERROR);
331+
listener.operationFeedback("Unexpected feedback.", typedef.typeOfProcessFeedback.TargetCheckFailed);
332+
}
333+
} catch (Exception e) {
334+
support.log("General error during targetcheck. Maybe Reference to simulator missing?", typeOfLogLevel.ERROR);
335+
listener.operationFeedback("Error during targetcheck.", typedef.typeOfProcessFeedback.TargetCheckFailed);
336+
support.log(e.getMessage(), typeOfLogLevel.ERROR);
337+
}
256338
}
257339
}

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorLocal.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import toe.helper.nativeProcess;
2525
import toe.helper.nativeProcessCallbacks;
2626
import toe.support;
27+
import toe.typedef;
2728
import toe.typedef.typeOfLogLevel;
2829

2930
/**
@@ -362,19 +363,18 @@ public boolean isOptimumCalculated() {
362363

363364
@Override
364365
public void startCalculatingOptimum(SimOptiCallback listener) {
365-
//not needed
366-
throw new UnsupportedOperationException("Not supported yet.");
366+
listener.operationFeedback("Targetcheck not possible.", typedef.typeOfProcessFeedback.TargetCheckFailed);
367+
support.log("Targetcheck not possible for local simulation.", typeOfLogLevel.ERROR);
367368
}
368369

369370
@Override
370371
public void stopCalculatingOptimum(SimOptiCallback listener) {
371-
//not needed
372-
throw new UnsupportedOperationException("Not supported yet.");
372+
listener.operationFeedback("Stop of targetcheck not possible.", typedef.typeOfProcessFeedback.TargetCheckFailed);
373+
support.log("Stop of targetcheck not possible for local simulation.", typeOfLogLevel.ERROR);
373374
}
374375

375376
@Override
376377
public void discardCalculatedOptimum() {
377-
//not needed
378-
//throw new UnsupportedOperationException("Not supported yet.");
378+
support.log("Discard calculated optimum not possible for local simulation.", typeOfLogLevel.ERROR);
379379
}
380380
}

0 commit comments

Comments
 (0)