Commit d95d636d authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

Integrate EvacuationTimeProcessor

parent b85f7002
......@@ -11,6 +11,7 @@
"attributes" : {
"expectedResult" : "SUCCESS",
"optimizationMetricProcessorId" : 2,
"testEvacuationProcessorId" : 3,
"maxMeanPointDistance" : 0.0,
"maxMeanDifferenceFuncValue" : 0.0,
"infoMinPointDistanceL2" : 0.0,
......@@ -23,6 +24,33 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianMetricOptimizationProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.tests.TestEvacuationTimeProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesTestEvacuationTimeProcessor",
"attributes" : {
"expectedResult" : "SUCCESS",
"evacuationTimeProcessorId" : 4,
"maximalEvacuationTime" : 200.0,
"minimalEvacuationTime" : 0.0
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.EvacuationTimeProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor",
"attributes" : {
"pedestrianEvacuationTimeProcessorId" : 5
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianEvacuationTimeProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 6
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......@@ -82,7 +110,7 @@
}
},
"attributesSimulation" : {
"finishTime" : 80.0,
"finishTime" : 200.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.0,
"writeSimulationData" : true,
......
......@@ -11,6 +11,7 @@
"attributes" : {
"expectedResult" : "SUCCESS",
"optimizationMetricProcessorId" : 2,
"testEvacuationProcessorId" : 3,
"maxMeanPointDistance" : 0.0,
"maxMeanDifferenceFuncValue" : 0.0,
"infoMinPointDistanceL2" : 0.0,
......@@ -23,6 +24,33 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianMetricOptimizationProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.tests.TestEvacuationTimeProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesTestEvacuationTimeProcessor",
"attributes" : {
"expectedResult" : "SUCCESS",
"evacuationTimeProcessorId" : 4,
"maximalEvacuationTime" : 300.0,
"minimalEvacuationTime" : 0.0
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.EvacuationTimeProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor",
"attributes" : {
"pedestrianEvacuationTimeProcessorId" : 5
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianEvacuationTimeProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 6
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......
......@@ -11,6 +11,7 @@
"attributes" : {
"expectedResult" : "SUCCESS",
"optimizationMetricProcessorId" : 2,
"testEvacuationProcessorId" : 3,
"maxMeanPointDistance" : 0.0,
"maxMeanDifferenceFuncValue" : 0.0,
"infoMinPointDistanceL2" : 0.0,
......@@ -23,6 +24,33 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianMetricOptimizationProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.tests.TestEvacuationTimeProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesTestEvacuationTimeProcessor",
"attributes" : {
"expectedResult" : "SUCCESS",
"evacuationTimeProcessorId" : 4,
"maximalEvacuationTime" : 200.0,
"minimalEvacuationTime" : 0.0
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.EvacuationTimeProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor",
"attributes" : {
"pedestrianEvacuationTimeProcessorId" : 5
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianEvacuationTimeProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 6
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......
......@@ -11,6 +11,7 @@
"attributes" : {
"expectedResult" : "SUCCESS",
"optimizationMetricProcessorId" : 2,
"testEvacuationProcessorId" : 3,
"maxMeanPointDistance" : 0.0,
"maxMeanDifferenceFuncValue" : 0.0,
"infoMinPointDistanceL2" : 0.0,
......@@ -23,6 +24,33 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianMetricOptimizationProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.tests.TestEvacuationTimeProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesTestEvacuationTimeProcessor",
"attributes" : {
"expectedResult" : "SUCCESS",
"evacuationTimeProcessorId" : 4,
"maximalEvacuationTime" : 200.0,
"minimalEvacuationTime" : 0.0
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.EvacuationTimeProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor",
"attributes" : {
"pedestrianEvacuationTimeProcessorId" : 5
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianEvacuationTimeProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 6
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......
......@@ -2,16 +2,10 @@ package org.vadere.simulator.models.osm.optimization;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.apache.commons.math.FunctionEvaluationException;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.logging.Logger;
/**
* Abstract Base Class for StepCircleOptimizer.
......@@ -31,7 +25,7 @@ public abstract class StepCircleOptimizer {
protected StepCircleOptimizer(){
// TODO: read if the metric should be computed from a config file, see issue #243
this.computeMetric = true;
this.computeMetric = false;
if(this.computeMetric){
this.currentMetricValues = new ArrayList<>();
......@@ -63,38 +57,13 @@ public abstract class StepCircleOptimizer {
return computeMetric;
}
private SolutionPair bruteForceOptimalValue(final PedestrianOSM pedestrian){
//TODO move this function (rename!) to StepCircleOptimizerDiscrete
var reachableArea = new VCircle(pedestrian.getPosition(), pedestrian.getFreeFlowStepSize());
var potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrian);
potentialEvaluationFunction.setStepSize(reachableArea.getRadius());
var bruteForceMethod = new StepCircleOptimizerDiscrete(0, new Random());
//VPoint optimalPoint = bruteForceMethod.getNextPosition(pedestrian, getReachablePositions2(pedestrian, reachableArea, pedestrian.getPosition()),
VPoint optimalPoint = bruteForceMethod.getNextPosition(pedestrian, getReachablePositions(reachableArea),
reachableArea.getRadius(), true);
double optimalFuncValue; // -1 = invalid number
try{
optimalFuncValue = potentialEvaluationFunction.getValue(optimalPoint);
}catch (Exception e) {
Logger.getLogger(StepCircleOptimizerDiscrete.class).error("Potential evaluation for computing the brute " +
"force solution threw error. Setting value to invalid (-1).");
optimalFuncValue = -1;
}
System.out.println("BF: " + optimalPoint.toString() + "minimum value " + optimalFuncValue);
return new SolutionPair(optimalPoint, optimalFuncValue);
}
protected void computeAndAddBruteForceSolutionMetric(final PedestrianOSM pedestrian,
final SolutionPair foundSolution){
var bruteForceSolution = bruteForceOptimalValue(pedestrian);
var bruteForceSolution = new
StepCircleOptimizerDiscrete(0.0, new Random()).computeBruteForceSolution(pedestrian);
// TODO: maybe time of nextStep is not the actual correct one, possibly adapt
// TODO: maybe time of nextStep is not the actual correct one, possibly adapt , see #242 and !66
var optimizationMetric = new OptimizationMetric(pedestrian.getId(), pedestrian.getTimeOfNextStep(),
bruteForceSolution.point, bruteForceSolution.funcValue, foundSolution.point, foundSolution.funcValue);
......@@ -108,63 +77,4 @@ public abstract class StepCircleOptimizer {
public void clearMetricValues(){
this.currentMetricValues = new ArrayList<>();
}
private static List<VPoint> getReachablePositions(VCircle reachableArea){
// NOTE: numberPointsOfLargestCircle and numberOfCircles are parameters with a trade off between runtime and
// precision of brute force solution
//TODO move this function (rename!) to StepCircleOptimizerDiscrete
return GeometryUtils.getDiscDiscretizationPoints(
null,
false,
reachableArea,
1000,
10000,
0,
2.0 * Math.PI);
}
private static List<VPoint> getReachablePositions2(PedestrianOSM pedestrianOSM, VCircle reachableArea, VPoint centerPoint) {
final int nrLines = 2000; // both have to be larger than 2
final int nrPointsPerLine = 2000;
final double intervalXDirection = 2 * reachableArea.getRadius() / (nrPointsPerLine - 1);
final double intervalYDirection = 2 * reachableArea.getRadius() / (nrLines - 1);
var potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrianOSM);
potentialEvaluationFunction.setStepSize(reachableArea.getRadius());
VPoint refPoint = new VPoint(centerPoint.x - reachableArea.getRadius(), centerPoint.y + reachableArea.getRadius());
//VPoint endLine = new VPoint(position.x + radius, position.y + radius);
VPoint currentBestPoint = pedestrianOSM.getPosition();
double currentBest = Double.MAX_VALUE;
List<VPoint> returnList = new ArrayList<>();
try{
for (int i = 0; i < nrLines; ++i) {
for (int j = 0; j < nrPointsPerLine; ++j) {
VPoint currentPoint = new VPoint(refPoint.x + intervalXDirection * j, refPoint.y);
if(currentPoint.distance(centerPoint) <= reachableArea.getRadius()){
returnList.add(currentPoint.clone());
double currentEval = potentialEvaluationFunction.getPotential(currentPoint);
if(currentEval <= currentBest){
currentBest = currentEval;
currentBestPoint = currentPoint.clone();
}
}
}
refPoint.y -= intervalYDirection;
}
}catch(FunctionEvaluationException e){
e.printStackTrace();
}
System.out.println("BF2:" + currentBestPoint.toString() + " value = " + currentBest);
return returnList;
}
}
......@@ -3,6 +3,7 @@ package org.vadere.simulator.models.osm.optimization;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.attributes.models.AttributesOSM;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.types.MovementType;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VCircle;
......@@ -11,6 +12,7 @@ import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.util.logging.Logger;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
......@@ -69,7 +71,7 @@ public class StepCircleOptimizerDiscrete extends StepCircleOptimizer {
nextPos = currentPosition;
}
} catch (Exception e) {
Logger.getLogger(StepCircleOptimizerDiscrete.class).error("Potential evaluation threw an topographyError.");
Logger.getLogger(StepCircleOptimizerDiscrete.class).error("Potential evaluation threw an error: " + e.getMessage());
}
}
......@@ -81,6 +83,28 @@ public class StepCircleOptimizerDiscrete extends StepCircleOptimizer {
return nextPos;
}
public SolutionPair computeBruteForceSolution(final PedestrianOSM pedestrian){
// SolutionPair is defined in super class
var reachableArea = new VCircle(pedestrian.getPosition(), pedestrian.getFreeFlowStepSize());
var potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrian);
potentialEvaluationFunction.setStepSize(reachableArea.getRadius());
VPoint optimalPoint = getNextPosition(pedestrian, getBruteForcePointsCircles(reachableArea),
reachableArea.getRadius(), true);
double optimalFuncValue; // -1 = invalid number
try{
optimalFuncValue = potentialEvaluationFunction.getValue(optimalPoint);
}catch (Exception e) {
Logger.getLogger(StepCircleOptimizerDiscrete.class).error("Potential evaluation for computing the brute " +
"force solution threw error. Setting value to invalid (-1).");
optimalFuncValue = -1;
}
return new SolutionPair(optimalPoint, optimalFuncValue);
}
public StepCircleOptimizer clone() {
return new StepCircleOptimizerDiscrete(movementThreshold, random);
}
......@@ -135,6 +159,49 @@ public class StepCircleOptimizerDiscrete extends StepCircleOptimizer {
}
private static List<VPoint> getBruteForcePointsCircles(VCircle reachableArea){
// NOTE: numberPointsOfLargestCircle and numberOfCircles are parameters with a trade off between runtime and
// precision of brute force solution
return GeometryUtils.getDiscDiscretizationPoints(
null,
false,
reachableArea,
100,
2000,
0,
2.0 * Math.PI);
}
private static List<VPoint> getBruteForcePointsLines(VCircle reachableArea) {
/* Just an alternative to the getBruteForcePointsCircles (which is recommended to use).*/
// both have to be larger than 2
final int nrLines = 2000;
final int nrPointsPerLine = 2000;
VPoint centerPoint = reachableArea.getCenter();
final double intervalXDirection = 2 * reachableArea.getRadius() / (nrPointsPerLine - 1);
final double intervalYDirection = 2 * reachableArea.getRadius() / (nrLines - 1);
VPoint refPoint = new VPoint(centerPoint.x - reachableArea.getRadius(), centerPoint.y + reachableArea.getRadius());
List<VPoint> returnList = new ArrayList<>();
for (int i = 0; i < nrLines; ++i) {
for (int j = 0; j < nrPointsPerLine; ++j) {
VPoint currentPoint = new VPoint(refPoint.x + intervalXDirection * j, refPoint.y);
if(currentPoint.distance(centerPoint) <= reachableArea.getRadius()){
returnList.add(currentPoint.clone());
}
}
refPoint.y -= intervalYDirection;
}
return returnList;
}
/**
* The maximum deviation from the last movement direction given the current speed.
* See seitz-2016 PhD-thesis equation 4.6
......
......@@ -16,7 +16,7 @@ import java.util.Map;
import java.util.Random;
/**
* The Class StepCircleOptimizerNelderMead.
* The class StepCircleOptimizerNelderMead.
*
*/
public class StepCircleOptimizerNelderMead extends StepCircleOptimizer {
......@@ -25,11 +25,9 @@ public class StepCircleOptimizerNelderMead extends StepCircleOptimizer {
.getLogger(StepCircleOptimizerNelderMead.class);
private final Random random;
private Map<PedestrianOSM, VPoint> lastSolution;
public StepCircleOptimizerNelderMead(Random random) {
this.random = random;
this.lastSolution = new HashMap<>();
}
@Override
......@@ -132,7 +130,6 @@ public class StepCircleOptimizerNelderMead extends StepCircleOptimizer {
if(getIsComputeMetric()){
// See merge request !65
System.out.println("NM: " + new VPoint(minimum[0], minimum[1]).toString() + "minimum value " + minimumValue);
this.computeAndAddBruteForceSolutionMetric(pedestrian,
new SolutionPair(new VPoint(minimum[0], minimum[1]), minimumValue));
}
......
......@@ -32,6 +32,7 @@ import static java.util.Map.entry;
public class TestOptimizationMetricNelderMeadProcessor extends TestProcessor {
private PedestrianMetricOptimizationProcessor pedestrianMetricOptimizationProcessor;
private TestEvacuationTimeProcessor testEvacuationTimeProcessor;
private String scenarioName;
public TestOptimizationMetricNelderMeadProcessor() {
......@@ -47,9 +48,19 @@ public class TestOptimizationMetricNelderMeadProcessor extends TestProcessor {
this.scenarioName = null;
AttributesTestOptimizationMetricProcessor att = this.getAttributes();
pedestrianMetricOptimizationProcessor =
(PedestrianMetricOptimizationProcessor) manager.getProcessor(
att.getOptimizationMetricProcessorId());
(PedestrianMetricOptimizationProcessor) manager.getProcessor(att.getOptimizationMetricProcessorId());
testEvacuationTimeProcessor =
(TestEvacuationTimeProcessor) manager.getProcessor(att.getTestEvacuationProcessorId());
}
@Override
public void preLoop(SimulationState state) {
pedestrianMetricOptimizationProcessor.preLoop(state);
testEvacuationTimeProcessor.preLoop(state);
}
@Override
......@@ -64,17 +75,17 @@ public class TestOptimizationMetricNelderMeadProcessor extends TestProcessor {
}
pedestrianMetricOptimizationProcessor.update(state);
}
@Override
public void preLoop(SimulationState state) {
pedestrianMetricOptimizationProcessor.preLoop(state);
testEvacuationTimeProcessor.update(state);
}
@Override
public void postLoop(SimulationState state) {
// Check if every agent reached the target
testEvacuationTimeProcessor.postLoop(state);
Map<EventtimePedestrianIdKey, OptimizationMetric> processorData = pedestrianMetricOptimizationProcessor.getData();
// Check how the metric changed compared to the set values
Map<EventtimePedestrianIdKey, OptimizationMetric> processorData =
pedestrianMetricOptimizationProcessor.getData();
ArrayList<Double> pointDistanceL2Values = new ArrayList<>();
ArrayList<Double> differenceFuncValues = new ArrayList<>();
......
......@@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
public class AttributesTestOptimizationMetricProcessor extends AttributesTestProcessor {
private int optimizationMetricProcessorId;
private int testEvacuationProcessorId;
/** Following have to be fulfilled (i.e. the mean has to be below this. If the mean increases the value, the
* processor will fail. */
......@@ -31,6 +32,10 @@ public class AttributesTestOptimizationMetricProcessor extends AttributesTestPro
return optimizationMetricProcessorId;
}
public int getTestEvacuationProcessorId() {
return testEvacuationProcessorId;
}
public double getMaxMeanPointDistance() {
return maxMeanPointDistance;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment