2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 837ecc13 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

Merge branch 'master' of https://gitlab.lrz.de/vadere/vadere

parents f4f9d6ff 77cb5e47
......@@ -7,6 +7,7 @@
### Added
### Changed
- `PedestrianFootStepProcessor` interpolates the pedestrian's foot step to obtain a more precise position.
# v1.4 (2019-09-05)
......
......@@ -256,12 +256,7 @@ if __name__ == "__main__":
if args.scenario is None:
passed_and_failed_scenarios_model = run_all_model_tests()
if not result_dict_has_failed_tests(passed_and_failed_scenarios_model):
passed_and_failed_scenarios_optimization = run_all_optimization_tests()
else:
print("Skipping optimization tests...")
passed_and_failed_scenarios_optimization = {"failed": [], "passed": [], "failed_summary": []} # empty
passed_and_failed_scenarios_optimization = run_all_optimization_tests()
# Make a summery of all scenario files
all_passed_and_failed_scenarios = result_dict_merge(passed_and_failed_scenarios_model,
......
......@@ -198,7 +198,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
double maxDistance = Math.sqrt(model.getTopography().getBounds().getWidth() * model.getTopography().getBounds().getWidth() +
model.getTopography().getBounds().getHeight() * model.getTopography().getBounds().getHeight());
colorHelper = new ColorHelper((int)(maxDistance * 0.7));
colorHelper = new ColorHelper((int)(maxDistance));
for (int x = 0; x < potentialFieldImage.getWidth(); x++) {
for (int y = 0; y < potentialFieldImage.getHeight(); y++) {
......
......@@ -113,7 +113,7 @@ public class OnlinevisualizationRenderer extends SimulationRenderer {
*/
private Stream<VPoint> getFootStepsPosition(@NotNull final Agent agent) {
if(agent instanceof Pedestrian) {
return ((Pedestrian) agent).getFootSteps().stream().map(footStep -> footStep.getStart());
return ((Pedestrian) agent).getTrajectory().stream().map(footStep -> footStep.getStart());
}
else {
return Stream.of(agent.getPosition());
......
......@@ -205,7 +205,7 @@ public class TextView extends JPanel implements IJsonView {
if (scenarioChecker != null){
scenarioChecker.checkScenario(currentScenario);
}
} catch (Exception e) {
} catch (IOException e) {
ScenarioPanel.setActiveJsonParsingErrorMsg(attributeType.name() + " tab:\n" + e.getMessage());
jsonValidIndicator.setInvalid();
}
......
......@@ -12,14 +12,14 @@
"expectedResult" : "SUCCESS",
"optimizationMetricProcessorId" : 2,
"testEvacuationProcessorId" : 3,
"maxMeanPointDistance" : 0.07522399192836575,
"maxMeanDifferenceFuncValue" : 0.023848826871958207,
"maxMeanPointDistance" : 0.07720166933228925,
"maxMeanDifferenceFuncValue" : 0.02530975248920717,
"infoMinPointDistanceL2" : 0.0,
"infoMaxPointDistanceL2" : 1.564386140233547,
"infoMinFuncDifference" : -7.357495880544462E-6,
"infoMaxFuncDifference" : 0.33222591981368765,
"infoStddevPointDistance" : 0.09544596760319345,
"infoStddevDifferenceFuncValue" : 0.0336543527990736
"infoMaxPointDistanceL2" : 1.243960344866288,
"infoMinFuncDifference" : -6.8591881827728685E-6,
"infoMaxFuncDifference" : 0.2874895188283819,
"infoStddevPointDistance" : 0.10083846350068452,
"infoStddevDifferenceFuncValue" : 0.032918942463911124
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianMetricOptimizationProcessor",
......
......@@ -12,14 +12,14 @@
"expectedResult" : "SUCCESS",
"optimizationMetricProcessorId" : 2,
"testEvacuationProcessorId" : 3,
"maxMeanPointDistance" : 0.06743253584052734,
"maxMeanDifferenceFuncValue" : 0.03762845011019873,
"maxMeanPointDistance" : 0.0709316978693857,
"maxMeanDifferenceFuncValue" : 0.034637431592363405,
"infoMinPointDistanceL2" : 0.0,
"infoMaxPointDistanceL2" : 1.1908766074958799,
"infoMinFuncDifference" : -0.007825774248588324,
"infoMaxFuncDifference" : 3.1836042315887085,
"infoStddevPointDistance" : 0.11888918094737598,
"infoStddevDifferenceFuncValue" : 0.14690668533173323
"infoMaxPointDistanceL2" : 1.326056350852655,
"infoMinFuncDifference" : -0.010140720593533104,
"infoMaxFuncDifference" : 2.113085584226426,
"infoStddevPointDistance" : 0.12198739340543781,
"infoStddevDifferenceFuncValue" : 0.09742478889202222
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianMetricOptimizationProcessor",
......
......@@ -2,7 +2,6 @@ Density.measurementRadius = 15
Density.measurementScale = 10.0
Density.standardDeviation = 0.5
Gui.dataProcessingViewMode = json
Gui.lastSavePoint = /home/daniel
Gui.toolbar.size = 40
Messages.language = en
Pedestrian.radius = 0.195
......@@ -16,9 +15,6 @@ PostVis.maxFramePerSecond = 30
PostVis.maxNumberOfSaveDirectories = 5
PostVis.minCellWidth = 0.01
ProjectView.cellWidth = 1.0
ProjectView.defaultDirectory = /home/daniel/REPOS/vadere/VadereModelTests/TestOSM
ProjectView.defaultDirectoryAttributes = /home/daniel
ProjectView.defaultDirectoryScenarios = /home/daniel
ProjectView.icon.height.value = 35
ProjectView.icon.width.value = 35
ProjectView.maxCellWidth = 10.0
......@@ -30,5 +26,4 @@ SettingsDialog.showLogo = false
SettingsDialog.snapshotDirectory.path = .
Testing.stepCircleOptimization.compareBruteForceSolution = true
TopographyCreator.dotRadius = 0.5
History.lastUsedProject = /home/daniel/REPOS/vadere/VadereModelTests/TestOSM/vadere.project
History.recentProjects = /home/daniel/REPOS/vadere/VadereModelTests/TestOSM/vadere.project,/home/daniel/REPOS/vadere/VadereModelTests/TestNelderMead,/home/daniel/REPOS/vadere/VadereModelTests/TestOSM,/home/daniel/REPOS/vadere/VadereModelTests/TestOSMGroup,/home/daniel/REPOS/vadere/VadereModelTests/TestOSMGroup/vadere.project
......@@ -66,6 +66,7 @@ public class PedestrianBHM extends Pedestrian {
this.random = random;
this.attributesBHM = attributesBHM;
this.topography = topography;
this.timeOfNextStep = INVALID_NEXT_EVENT_TIME;
this.setVelocity(new Vector2D(0, 0));
......@@ -170,27 +171,31 @@ public class PedestrianBHM extends Pedestrian {
}
// for the first step after creation, timeOfNextStep has to be initialized
if (getTimeOfNextStep() == 0) {
if (getTimeOfNextStep() == INVALID_NEXT_EVENT_TIME) {
timeOfNextStep = currentTimeInSec;
return;
}
durationNextStep = stepLength / getFreeFlowSpeed();
double startTimeStep = timeOfNextStep;
double endTimeStep = timeOfNextStep + durationNextStep;
timeOfNextStep = endTimeStep;
Event mostImportantEvent = getMostImportantEvent();
VPoint position = getPosition();
if (mostImportantEvent instanceof ElapsedTimeEvent) {
updateTargetDirection();
nextPosition = navigation.getNavigationPosition();
makeStep();
timeOfNextStep += durationNextStep;
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
timeOfNextStep += durationNextStep;
// do nothing
} else {
throw new UnsupportedEventException(mostImportantEvent, this.getClass());
}
FootStep currentFootstep = new FootStep(position, getPosition(), timeOfNextStep, timeOfNextStep + durationNextStep);
getFootSteps().add(currentFootstep);
FootStep currentFootstep = new FootStep(position, getPosition(), startTimeStep, endTimeStep);
getTrajectory().add(currentFootstep);
getFootstepHistory().add(currentFootstep);
}
......
......@@ -34,7 +34,7 @@ public class TargetDirectionGeoGradient implements TargetDirection {
VPoint gradient2 = targetPotentialField.getTargetPotentialGradient(position.add(gradient1.setMagnitude(stepLength)), pedestrianBHM).multiply(-1.0);
if(gradient2.distanceToOrigin() > GeometryUtils.DOUBLE_EPS && UtilsBHM.angle(gradient1, gradient2) < maxAngleBetweenGradients) {
logger.info("gradient direction");
//logger.info("gradient direction");
return gradient1.norm();
}
}
......
......@@ -13,7 +13,6 @@ import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.FootStep;
import org.vadere.simulator.utils.cache.ScenarioCache;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
......@@ -113,7 +112,7 @@ public class BiomechanicsModel implements MainModel {
agent.clearFootSteps();
FootStep currentFootstep = new FootStep(positions.get(i), agent.getPosition(), lastSimTimeInSec, simTimeInSec);
agent.getFootSteps().add(currentFootstep);
agent.getTrajectory().add(currentFootstep);
agent.getFootstepHistory().add(currentFootstep);
}
......
......@@ -130,7 +130,7 @@ public abstract class ODEModel<T extends DynamicElement, TAttributes extends Att
pedestrian.clearFootSteps();
FootStep currentFootstep = new FootStep(positions.get(i), pedestrian.getPosition(), lastSimTimeInSec, simTimeInSec);
pedestrian.getFootSteps().add(currentFootstep);
pedestrian.getTrajectory().add(currentFootstep);
pedestrian.getFootstepHistory().add(currentFootstep);
}
}
......
......@@ -2,6 +2,7 @@ package org.vadere.simulator.models.osm;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.potential.combinedPotentials.CombinedPotentialStrategy;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.behavior.SalientBehavior;
......@@ -11,9 +12,9 @@ import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.FootStep;
import org.vadere.state.simulation.VTrajectory;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.util.math.MathUtil;
import java.util.LinkedList;
import java.util.List;
......@@ -58,7 +59,7 @@ public class OSMBehaviorController {
// end time
double stepEndTime = pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep();
assert stepEndTime >= stepStartTime && stepEndTime >= 0.0 && stepStartTime >= 0.0;
assert stepEndTime >= stepStartTime && stepEndTime >= 0.0 && stepStartTime >= 0.0 : stepEndTime + "<" + stepStartTime;
if (nextPosition.equals(currentPosition)) {
pedestrian.setTimeCredit(0);
......@@ -81,12 +82,14 @@ public class OSMBehaviorController {
pedestrian.getStrides().add(Pair.of(currentPosition.distance(nextPosition), stepStartTime));
FootStep currentFootstep = new FootStep(currentPosition, nextPosition, stepStartTime, stepEndTime);
pedestrian.getFootSteps().add(currentFootstep);
pedestrian.getTrajectory().add(currentFootstep);
pedestrian.getFootstepHistory().add(currentFootstep);
}
public void wait(PedestrianOSM pedestrian) {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
public void wait(PedestrianOSM pedestrian, double timeStepInSec) {
// Satisfy event-driven and sequential update scheme.
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + timeStepInSec);
pedestrian.setTimeCredit(0);
}
// Watch out: A bang event changes only the "CombinedPotentialStrategy".
......@@ -114,6 +117,9 @@ public class OSMBehaviorController {
* Try to swap the given pedestrian with the closest cooperative pedestrian.
* Carry out the following steps:
*
* TODO: Refactoring, this class should not have access to the event queue. Idea: use "old" events which will be ignored i.e.
* one agent might have multiple events in the queue.
*
* <ol>
* <li>Use topography to find a close pedestrian within step circle which is closer to target than the given pedestrian.</li>
* <li>Check if candidate is SalientBehavior.COOPERATIVE.</li>
......@@ -124,13 +130,12 @@ public class OSMBehaviorController {
* @param pedestrian The pedestrian which would like to swap the position.
* @param topography The topography is required to find the neighbors of the given pedestrian.
*/
public void swapWithClosestCooperativePedestrian(PedestrianOSM pedestrian, Topography topography) {
/*public void swapWithClosestCooperativePedestrian(PedestrianOSM pedestrian, Topography topography, PriorityQueue<PedestrianOSM> queue) {
if (pedestrian.hasNextTarget() == false) { // Ignore pedestrians with no targets.
// this can cause problems if the pedestrian desired speed is 0 (see speed adjuster)
pedestrian.updateNextPosition();
makeStep(pedestrian, topography, pedestrian.getDurationNextStep());
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
return;
}
......@@ -150,7 +155,7 @@ public class OSMBehaviorController {
}
if (closestPedIsCooperative && targetOrientationDiffers) {
swapPedestrians(pedestrian, (PedestrianOSM)closestPedestrian, topography);
swapPedestrians(pedestrian, (PedestrianOSM)closestPedestrian, topography, queue);
pedestriansSwapped = true;
break;
}
......@@ -163,6 +168,37 @@ public class OSMBehaviorController {
makeStep(pedestrian, topography, pedestrian.getDurationNextStep());
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
}*/
@Nullable
public PedestrianOSM findSwapCandidate(PedestrianOSM pedestrian, Topography topography) {
List<Pedestrian> closestPedestrians = getClosestPedestriansWhichAreCloserToTarget(pedestrian, topography);
if (closestPedestrians.size() > 0) {
for (Pedestrian closestPedestrian : closestPedestrians) {
if(pedestrian.hasNextTarget()) {
boolean closestPedIsCooperative = closestPedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE;
boolean targetOrientationDiffers = false;
// TODO: Use "pedestrian.getTargetGradient()" instead of "calculateAngleBetweenTargets()".
double angleInRadian = calculateAngleBetweenTargets(pedestrian, closestPedestrian, topography);
if (angleInRadian == -1 || Math.toDegrees(angleInRadian) > pedestrian.getAttributes().getTargetOrientationAngleThreshold()) {
targetOrientationDiffers = true;
}
if (closestPedIsCooperative && targetOrientationDiffers) {
return (PedestrianOSM)closestPedestrian;
}
} else {
if(!closestPedestrian.hasNextTarget()) {
return (PedestrianOSM)closestPedestrian;
}
}
}
}
return null;
}
@NotNull
......@@ -245,7 +281,7 @@ public class OSMBehaviorController {
return vectorPedestrianToTarget;
}
private void swapPedestrians(PedestrianOSM pedestrian1, PedestrianOSM pedestrian2, Topography topography) {
public void swapPedestrians(PedestrianOSM pedestrian1, PedestrianOSM pedestrian2, Topography topography) {
VPoint newPosition = pedestrian2.getPosition().clone();
VPoint oldPosition = pedestrian1.getPosition().clone();
......@@ -254,13 +290,33 @@ public class OSMBehaviorController {
// Use "makeStep()" to swap both pedestrians to avoid "java.lang.AssertionError:
// Number of pedestrians in LinkedCellGrid does not match number of pedestrians in topography".
makeStep(pedestrian1, topography, pedestrian1.getDurationNextStep());
makeStep(pedestrian2, topography, pedestrian2.getDurationNextStep());
double startTimeStep = pedestrian1.getTimeOfNextStep();
double durationStep = Math.max(pedestrian1.getDurationNextStep(), pedestrian2.getDurationNextStep());
double endTimeStep = startTimeStep + durationStep;
// here we interrupt the current footstep of pedestrian 2 to sync it to pedestrian 1
// this is only required for the sequential update scheme since pedestrian 2 might have done some steps in this time step and
// is ahead (with respect to the time) of pedestrian 1. We remove those steps which is not a good solution!
if(!pedestrian2.getTrajectory().isEmpty()) {
// the agent was standing still, otherwise this should not be allowed
pedestrian2.getTrajectory().adjustEndTime(startTimeStep);
}
// Note: Here we manipulate a pedestrian which is contained in the queue sorted by timeOfNextStep!
pedestrian1.setTimeOfNextStep(startTimeStep);
pedestrian2.setTimeOfNextStep(startTimeStep);
makeStep(pedestrian1, topography, durationStep);
makeStep(pedestrian2, topography, durationStep);
// TODO The experiment showed that speed decreased (to half of free-flow velocity).
// Therefore, use "pedestrian.getDurationNextStep() * 2".
pedestrian1.setTimeOfNextStep(pedestrian1.getTimeOfNextStep() + pedestrian1.getDurationNextStep());
pedestrian2.setTimeOfNextStep(pedestrian2.getTimeOfNextStep() + pedestrian2.getDurationNextStep());
}
pedestrian1.setTimeOfNextStep(endTimeStep);
pedestrian2.setTimeOfNextStep(endTimeStep);
pedestrian1.setTimeCredit(pedestrian1.getTimeCredit() - durationStep);
// assert pedestrian1.getTimeCredit() >= 0.0;
pedestrian2.setTimeCredit(pedestrian1.getTimeCredit());
}
}
......@@ -82,7 +82,7 @@ public class PedestrianOSM extends Pedestrian {
this.speedAdjusters = speedAdjusters;
this.stepSizeAdjusters = new LinkedList<>();
this.relevantPedestrians = new HashSet<>();
this.timeCredit = 0;
this.timeOfNextStep = INVALID_NEXT_EVENT_TIME;
this.setVelocity(new Vector2D(0, 0));
......
......@@ -12,10 +12,13 @@ import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.math.MathUtil;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Set;
/**
* @author Benedikt Zoennchen
......@@ -30,7 +33,7 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
this.topography = topography;
this.pedestrianEventsQueue = new PriorityQueue<>(100, new ComparatorPedestrianOSM());
this.pedestrianEventsQueue.addAll(topography.getElements(PedestrianOSM.class));
osmBehaviorController = new OSMBehaviorController();
this.osmBehaviorController = new OSMBehaviorController();
}
@Override
......@@ -50,28 +53,41 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
}
protected void update(@NotNull final PedestrianOSM pedestrian, final double timeStepInSec, final double currentTimeInSec) {
// for the first step after creation, timeOfNextStep has to be initialized
if (pedestrian.getTimeOfNextStep() == Pedestrian.INVALID_NEXT_EVENT_TIME) {
pedestrian.setTimeOfNextStep(currentTimeInSec);
return;
}
Event mostImportantEvent = pedestrian.getMostImportantEvent();
if (mostImportantEvent instanceof ElapsedTimeEvent) {
VPoint oldPosition = pedestrian.getPosition();
double stepDuration = pedestrian.getDurationNextStep();
// for the first step after creation, timeOfNextStep has to be initialized
if (pedestrian.getTimeOfNextStep() == 0) {
pedestrian.setTimeOfNextStep(currentTimeInSec - timeStepInSec);
}
if (pedestrian.getSalientBehavior() == SalientBehavior.TARGET_ORIENTED) {
// this can cause problems if the pedestrian desired speed is 0 (see speed adjuster)
pedestrian.updateNextPosition();
osmBehaviorController.makeStep(pedestrian, topography, stepDuration);
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + stepDuration);
} else if (pedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE) {
osmBehaviorController.swapWithClosestCooperativePedestrian(pedestrian, topography);
// this call will also invoke setTimeOfNextStep
PedestrianOSM candidate = osmBehaviorController.findSwapCandidate(pedestrian, topography);
//TODO: Benedikt Kleinmeier:
if(candidate != null) {
//if(Math.abs(pedestrian.getTimeOfNextStep() - candidate.getTimeOfNextStep()) < MathUtil.EPSILON) {
pedestrianEventsQueue.remove(candidate);
osmBehaviorController.swapPedestrians(pedestrian, candidate, topography);
pedestrianEventsQueue.add(candidate);
/*} else {
pedestrian.setTimeOfNextStep(candidate.getTimeOfNextStep());
}*/
} else {
pedestrian.updateNextPosition();
osmBehaviorController.makeStep(pedestrian, topography, pedestrian.getDurationNextStep());
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
}
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
osmBehaviorController.wait(pedestrian);
osmBehaviorController.wait(pedestrian, timeStepInSec);
} else if (mostImportantEvent instanceof BangEvent) {
osmBehaviorController.reactToBang(pedestrian, topography);
......
......@@ -190,8 +190,8 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
}
private boolean hasChanged() {
//System.out.println(pedestrianOSM.getFootSteps().getFootSteps().size());
return pedestrianOSM.getFootSteps().isEmpty() || pedestrianOSM.getFootSteps().getFootSteps().peekLast().length() > 0;
//System.out.println(pedestrianOSM.getTrajectory().getTrajectory().size());
return pedestrianOSM.getTrajectory().isEmpty() || pedestrianOSM.getTrajectory().getFootSteps().peekLast().length() > 0;
}
@Override
......
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