Commit 79832611 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Implemented first (rudimentary) working version of...

Implemented first (rudimentary) working version of "SalientBehavior.COOPERATIVE" in "OSMBehaviorController" and "UpdateSchemeEventDriven" (but visualization seems to be broken).
parent 823c1d83
...@@ -73,9 +73,7 @@ public class OSMBehaviorController { ...@@ -73,9 +73,7 @@ public class OSMBehaviorController {
pedestrian.setVelocity(pedVelocity); pedestrian.setVelocity(pedVelocity);
} }
/** // strides and foot steps have no influence on the simulation itself, i.e. they are saved to analyse trajectories
* strides and foot steps have no influence on the simulation itself, i.e. they are saved to analyse trajectories
*/
pedestrian.getStrides().add(Pair.of(currentPosition.distance(nextPosition), timeOfNextStep)); pedestrian.getStrides().add(Pair.of(currentPosition.distance(nextPosition), timeOfNextStep));
pedestrian.getFootSteps().add(new FootStep(currentPosition, nextPosition, timeOfNextStep, entTimeOfStep)); pedestrian.getFootSteps().add(new FootStep(currentPosition, nextPosition, timeOfNextStep, entTimeOfStep));
} }
...@@ -121,10 +119,16 @@ public class OSMBehaviorController { ...@@ -121,10 +119,16 @@ public class OSMBehaviorController {
*/ */
public void swapWithClosestCooperativePedestrian(PedestrianOSM pedestrian, Topography topography) { public void swapWithClosestCooperativePedestrian(PedestrianOSM pedestrian, Topography topography) {
if (pedestrian.hasNextTarget() == false) { // Ignore pedestrians with no targets. 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; return;
} }
List<Pedestrian> closestPedestrians = getClosestPedestriansWhichAreCloserToTarget(pedestrian, topography); List<Pedestrian> closestPedestrians = getClosestPedestriansWhichAreCloserToTarget(pedestrian, topography);
boolean pedestriansSwapped = false;
if (closestPedestrians.size() > 0) { if (closestPedestrians.size() > 0) {
for (Pedestrian closestPedestrian : closestPedestrians) { for (Pedestrian closestPedestrian : closestPedestrians) {
...@@ -133,18 +137,26 @@ public class OSMBehaviorController { ...@@ -133,18 +137,26 @@ public class OSMBehaviorController {
boolean targetOrientationDiffers = true; boolean targetOrientationDiffers = true;
if (closestPedIsCooperative && targetOrientationDiffers) { if (closestPedIsCooperative && targetOrientationDiffers) {
swapPedestrians(pedestrian, closestPedestrian); swapPedestrians(pedestrian, (PedestrianOSM)closestPedestrian, topography);
pedestriansSwapped = true;
break; break;
} }
} }
} }
if (pedestriansSwapped == false) { // Try to perform a regular step
// 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());
}
} }
@NotNull @NotNull
private List<Pedestrian> getClosestPedestriansWhichAreCloserToTarget(PedestrianOSM pedestrian, Topography topography) { private List<Pedestrian> getClosestPedestriansWhichAreCloserToTarget(PedestrianOSM pedestrian, Topography topography) {
VPoint positionOfPedestrian = pedestrian.getPosition(); VPoint positionOfPedestrian = pedestrian.getPosition();
// TODO Maybe, extract search radius as configurable attribute.
List<Pedestrian> closestPedestrians = topography.getSpatialMap(Pedestrian.class) List<Pedestrian> closestPedestrians = topography.getSpatialMap(Pedestrian.class)
.getObjects(positionOfPedestrian, pedestrian.getRadius() * 5); .getObjects(positionOfPedestrian, pedestrian.getRadius() * 5);
...@@ -207,16 +219,17 @@ public class OSMBehaviorController { ...@@ -207,16 +219,17 @@ public class OSMBehaviorController {
return angleInRadian; return angleInRadian;
} }
private void swapPedestrians(Pedestrian pedestrian1, Pedestrian pedestrian2) { private void swapPedestrians(PedestrianOSM pedestrian1, PedestrianOSM pedestrian2, Topography topography) {
// TODO Use "makeStep()" to swap both pedestrians to avoid // TODO Use "makeStep()" to swap both pedestrians to avoid
// "java.lang.AssertionError: Number of pedestrians in LinkedCellGrid does not match number of pedestrians in topography". // "java.lang.AssertionError: Number of pedestrians in LinkedCellGrid does not match number of pedestrians in topography".
/*
VPoint newPosition = pedestrian2.getPosition().clone(); VPoint newPosition = pedestrian2.getPosition().clone();
VPoint oldPosition = pedestrian1.getPosition().clone(); VPoint oldPosition = pedestrian1.getPosition().clone();
pedestrian1.setPosition(newPosition); pedestrian1.setNextPosition(newPosition);
pedestrian2.setPosition(oldPosition); pedestrian2.setNextPosition(oldPosition);
*/
makeStep(pedestrian1, topography, pedestrian1.getDurationNextStep());
makeStep(pedestrian2, topography, pedestrian2.getDurationNextStep());
} }
} }
...@@ -60,14 +60,12 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM { ...@@ -60,14 +60,12 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
} }
// TODO Make a code review with Bene here and check if everything works as expected. // TODO Make a code review with Bene here and check if everything works as expected.
// this can cause problems if the pedestrian desired speed is 0 (see speed adjuster) if (pedestrian.getSalientBehavior() == SalientBehavior.TARGET_ORIENTED) {
pedestrian.updateNextPosition(); // this can cause problems if the pedestrian desired speed is 0 (see speed adjuster)
double stepDuration = pedestrian.getDurationNextStep(); pedestrian.updateNextPosition();
osmBehaviorController.makeStep(pedestrian, topography, pedestrian.getDurationNextStep());
osmBehaviorController.makeStep(pedestrian, topography, stepDuration); pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + stepDuration); } else if (pedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE) {
if (pedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE) {
osmBehaviorController.swapWithClosestCooperativePedestrian(pedestrian, topography); osmBehaviorController.swapWithClosestCooperativePedestrian(pedestrian, topography);
} }
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) { } else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
......
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