Skip to content

Commit a910397

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
improved/fixed targetcheck for min/max
1 parent 49191b9 commit a910397

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorCached.java

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import toe.support;
1616
import toe.typedef;
1717
import toe.typedef.typeOfLogLevel;
18+
import toe.typedef.typeOfTarget;
1819

1920
/**
2021
* Class to simulate real SCPN-Simulation. It uses the SimulationCache with read
@@ -235,7 +236,7 @@ public String getLogfileName() {
235236
return this.logFileName;
236237
}
237238

238-
@Override
239+
@Override
239240
public boolean isOptimumCalculated() {
240241
return (this.calculatedOptimum != null);
241242
}
@@ -276,25 +277,65 @@ public void operationFeedback(String message, typedef.typeOfProcessFeedback feed
276277
switch (feedback) {
277278
case SimulationSuccessful:
278279
ArrayList<SimulationType> simulationResults = this.getListOfCompletedSimulations();
279-
double oldDistance = simulationResults.get(0).getDistanceToTargetValue();
280+
double oldDistance = 0.0;
280281
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-
}
282+
283+
MeasureType targetMeasure = support.getOptimizationMeasure();
284+
typeOfTarget selectedTypeOfTarget = targetMeasure.getTargetTypeOf();
285+
switch (selectedTypeOfTarget) {
286+
case min:
287+
oldDistance = simulationResults.get(0).getMeasureValueByMeasureName(targetMeasure.getMeasureName());
288+
foundOptima.add(simulationResults.get(0));
289+
for (int i = 1; i < simulationResults.size(); i++) {
290+
support.spinInLabel();
291+
support.log("Value of measure is: " + String.valueOf(simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName())), typeOfLogLevel.VERBOSE);
292+
if (oldDistance > simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName())) {
293+
foundOptima.clear();
294+
foundOptima.add(simulationResults.get(i));
295+
oldDistance = simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName());
296+
} else if (Math.abs(oldDistance - simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName())) < support.DEFAULT_TARGET_STEPPING) {
297+
foundOptima.add(simulationResults.get(i));
298+
}
299+
}
300+
//TODO feedback --> set target value in measure-panel
301+
break;
302+
case max:
303+
oldDistance = simulationResults.get(0).getMeasureValueByMeasureName(targetMeasure.getMeasureName());
304+
foundOptima.add(simulationResults.get(0));
305+
for (int i = 1; i < simulationResults.size(); i++) {
306+
support.spinInLabel();
307+
support.log("Value of measure is: " + String.valueOf(simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName())), typeOfLogLevel.VERBOSE);
308+
if (oldDistance < simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName())) {
309+
foundOptima.clear();
310+
foundOptima.add(simulationResults.get(i));
311+
oldDistance = simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName());
312+
} else if (Math.abs(oldDistance - simulationResults.get(i).getMeasureValueByMeasureName(targetMeasure.getMeasureName())) < support.DEFAULT_TARGET_STEPPING) {
313+
foundOptima.add(simulationResults.get(i));
314+
}
315+
}
316+
//TODO feedback --> set target value in measure-panel
317+
break;
318+
case value:
319+
oldDistance = simulationResults.get(0).getDistanceToTargetValue();
320+
foundOptima.add(simulationResults.get(0));
321+
for (int i = 1; i < simulationResults.size(); i++) {
322+
support.spinInLabel();
323+
support.log("Distance is: " + String.valueOf(simulationResults.get(i).getDistanceToTargetValue()), typeOfLogLevel.VERBOSE);
324+
if (oldDistance > simulationResults.get(i).getDistanceToTargetValue()) {
325+
foundOptima.clear();
326+
foundOptima.add(simulationResults.get(i));
327+
oldDistance = simulationResults.get(i).getDistanceToTargetValue();
328+
} else if (Math.abs(oldDistance - simulationResults.get(i).getDistanceToTargetValue()) < support.DEFAULT_TARGET_STEPPING) {
329+
foundOptima.add(simulationResults.get(i));
330+
}
331+
}
332+
break;
293333
}
294334

295335
if (foundOptima.size() < 1) {
296336
//Error checking the target
297337
listener.operationFeedback("Opticheck failed.", typedef.typeOfProcessFeedback.TargetCheckFailed);
338+
support.log("No optimum found, targetcheck failed.", typeOfLogLevel.ERROR);
298339
} else if (foundOptima.size() > 1) {
299340
//Not unique
300341
listener.operationFeedback("Selected Target is not unique There are " + foundOptima.size() + " same targets.", typedef.typeOfProcessFeedback.TargetValueNotUnique);
@@ -303,8 +344,8 @@ public void operationFeedback(String message, typedef.typeOfProcessFeedback feed
303344
//Exactly one optimum with selected target value was found
304345
if (oldDistance > 0.0) {
305346
//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);
347+
listener.operationFeedback("Target is unique, but distance is not 0.0.", typedef.typeOfProcessFeedback.TargetCheckSuccessful);
348+
support.log("Distance to target is: " + oldDistance, typeOfLogLevel.INFO);
308349

309350
} else {
310351
listener.operationFeedback("Target is unique and distance is 0.0!", typedef.typeOfProcessFeedback.TargetCheckSuccessful);

0 commit comments

Comments
 (0)