Commit 0f71c2f1 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "selfcategorization/.../OSMBehaviorController", implemented "changeTargetToSafeZone()"

parent b226ca8e
Pipeline #203573 passed with stages
in 119 minutes and 38 seconds
......@@ -212,6 +212,23 @@
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 3,
"absorbing" : true,
"shape" : {
"x" : 0.6,
"y" : 1.0,
"width" : 0.5,
"height" : 14.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ ],
"absorbingAreas" : [ ],
......@@ -256,7 +273,51 @@
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
} ],
"dynamicElements" : [ ],
"dynamicElements" : [ {
"attributes" : {
"id" : 3,
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"walkingDirectionCalculation" : "BY_TARGET_CENTER",
"walkingDirectionSameIfAngleLessOrEqual" : 45.0
},
"source" : null,
"targetIds" : [ ],
"nextTargetListIndex" : 0,
"isCurrentTargetAnAgent" : false,
"position" : {
"x" : 22.2,
"y" : 4.6
},
"velocity" : {
"x" : 0.0,
"y" : 0.0
},
"freeFlowSpeed" : 1.5462627717320168,
"followers" : [ ],
"idAsTarget" : -1,
"isChild" : false,
"isLikelyInjured" : false,
"psychologyStatus" : {
"mostImportantStimulus" : null,
"perceivedThreat" : null,
"selfCategory" : "TARGET_ORIENTED"
},
"groupIds" : [ ],
"groupSizes" : [ ],
"trajectory" : {
"footSteps" : [ ]
},
"modelPedestrianMap" : null,
"type" : "PEDESTRIAN"
} ],
"attributesPedestrian" : {
"radius" : 0.195,
"densityDependentSpeed" : false,
......@@ -288,4 +349,4 @@
} ]
} ]
}
}
}
\ No newline at end of file
......@@ -7,14 +7,13 @@ import org.vadere.simulator.models.osm.OptimalStepsModel;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.potential.combinedPotentials.CombinedPotentialStrategy;
import org.vadere.simulator.models.potential.combinedPotentials.TargetAttractionStrategy;
import org.vadere.simulator.models.potential.combinedPotentials.TargetRepulsionStrategy;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.ChangeTarget;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.state.scenario.*;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.Vector2D;
......@@ -23,6 +22,7 @@ import org.vadere.util.logging.Logger;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* A class to encapsulate the behavior of a single {@link PedestrianOSM}.
......@@ -120,10 +120,6 @@ public class OSMBehaviorController {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + timeStepInSec);
}
// Watch out: A bang event changes only the "CombinedPotentialStrategy".
// I.e., a new target is set for the agent. The agent does not move here!
// Therefore, trigger only a single bang event and then use "ElapsedTime" afterwards
// to let the agent walk.
public void maximizeDistanceToThreatAndIncreaseSpeed(PedestrianOSM pedestrian, Topography topography) {
Stimulus perceivedThreat = pedestrian.getPerceivedThreat();
......@@ -148,7 +144,43 @@ public class OSMBehaviorController {
}
}
public void reactToTargetChange(PedestrianOSM pedestrian, Topography topography) {
/**
* In dangerous situation humans tend to escape to familiar places (safe zones).
* A pedestrian selects the target which is closest to its source as safe zone.
* Or if pedestrian has no target, select closest target as safe zone.
*/
public void changeTargetToSafeZone(PedestrianOSM pedestrian, Topography topography) {
if (pedestrian.getCombinedPotentialStrategy() instanceof TargetRepulsionStrategy) {
ScenarioElement searchPosition = (pedestrian.getSource() == null) ? pedestrian : pedestrian.getSource();
Target closestTarget = findClosestTarget(topography, searchPosition, (Bang) pedestrian.getPerceivedThreat());
assert closestTarget != null;
if (closestTarget != null) {
pedestrian.setSingleTarget(closestTarget.getId(), false);
}
pedestrian.setCombinedPotentialStrategy(CombinedPotentialStrategy.TARGET_ATTRACTION_STRATEGY);
}
}
private Target findClosestTarget(Topography topography, ScenarioElement scenarioElement, Bang bang) {
VPoint sourceCentroid = scenarioElement.getShape().getCentroid();
List<Target> sortedTargets = topography.getTargets().stream()
.filter(target -> target.getId() != bang.getOriginAsTargetId())
.sorted((target1, target2) -> Double.compare(
sourceCentroid.distance(target1.getShape().getCentroid()),
sourceCentroid.distance(target2.getShape().getCentroid())))
.collect(Collectors.toList());
Target closestTarget = (sortedTargets.isEmpty()) ? null : sortedTargets.get(0);
return closestTarget;
}
public void changeTarget(PedestrianOSM pedestrian, Topography topography) {
Stimulus mostImportantStimulus = pedestrian.getMostImportantStimulus();
if (mostImportantStimulus instanceof ChangeTarget) {
......
......@@ -65,7 +65,7 @@ public class UpdateSchemeEventDriven implements DynamicElementAddListener, Dynam
osmBehaviorController.makeStepToTarget(pedestrian, topography);
}
} else if (pedestrian.getSelfCategory() == SelfCategory.OUTSIDE_THREAT_AREA) {
// TODO: Change target to safe zone (i.e., use closest target) and "makeStepToTarget()".
osmBehaviorController.changeTargetToSafeZone(pedestrian, topography);
osmBehaviorController.makeStepToTarget(pedestrian, topography);
} else if (pedestrian.getSelfCategory() == SelfCategory.WAIT) {
osmBehaviorController.wait(pedestrian, timeStepInSec);
......@@ -73,7 +73,7 @@ public class UpdateSchemeEventDriven implements DynamicElementAddListener, Dynam
osmBehaviorController.maximizeDistanceToThreatAndIncreaseSpeed(pedestrian, topography);
osmBehaviorController.makeStepToTarget(pedestrian, topography);
} else if (pedestrian.getSelfCategory() == SelfCategory.CHANGE_TARGET) {
osmBehaviorController.reactToTargetChange(pedestrian, topography);
osmBehaviorController.changeTarget(pedestrian, topography);
// Set time of next step. Otherwise, the internal OSM event queue hangs endlessly.
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
......
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