Commit 73c02c94 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Use class "SalientBehaviorCognition" in "Simulation".

parent 23220a13
Pipeline #103240 passed with stages
in 135 minutes and 29 seconds
package org.vadere.simulator.control; package org.vadere.simulator.control;
import org.vadere.simulator.control.cognition.EventCognition; import org.vadere.simulator.control.cognition.EventCognition;
import org.vadere.simulator.control.cognition.SalientBehaviorCognition;
import org.vadere.simulator.control.events.EventController; import org.vadere.simulator.control.events.EventController;
import org.vadere.simulator.control.factory.SourceControllerFactory; import org.vadere.simulator.control.factory.SourceControllerFactory;
import org.vadere.simulator.models.DynamicElementFactory; import org.vadere.simulator.models.DynamicElementFactory;
...@@ -71,6 +72,7 @@ public class Simulation { ...@@ -71,6 +72,7 @@ public class Simulation {
private SimulationResult simulationResult; private SimulationResult simulationResult;
private final EventController eventController; private final EventController eventController;
private final EventCognition eventCognition; private final EventCognition eventCognition;
private final SalientBehaviorCognition salientBehaviorCognition;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore, public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager, List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager,
...@@ -102,6 +104,7 @@ public class Simulation { ...@@ -102,6 +104,7 @@ public class Simulation {
// "eventController" is final. Therefore, create object here and not in helper method. // "eventController" is final. Therefore, create object here and not in helper method.
this.eventController = new EventController(scenarioStore); this.eventController = new EventController(scenarioStore);
this.eventCognition = new EventCognition(); this.eventCognition = new EventCognition();
this.salientBehaviorCognition = new SalientBehaviorCognition(topography);
createControllers(topography, mainModel, random); createControllers(topography, mainModel, random);
...@@ -317,7 +320,9 @@ public class Simulation { ...@@ -317,7 +320,9 @@ public class Simulation {
step++; step++;
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class); Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
eventCognition.prioritizeEventsForPedestrians(events, pedestrians); eventCognition.prioritizeEventsForPedestrians(events, pedestrians);
salientBehaviorCognition.setSalientBehaviorForPedestrians(pedestrians, simTimeInSec);
for (Model m : models) { for (Model m : models) {
List<SourceController> stillSpawningSource = this.sourceControllers.stream().filter(s -> !s.isSourceFinished(simTimeInSec)).collect(Collectors.toList()); List<SourceController> stillSpawningSource = this.sourceControllers.stream().filter(s -> !s.isSourceFinished(simTimeInSec)).collect(Collectors.toList());
......
...@@ -5,6 +5,7 @@ import org.vadere.state.behavior.SalientBehavior; ...@@ -5,6 +5,7 @@ import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.events.types.Event; import org.vadere.state.events.types.Event;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.LastFootSteps;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -13,7 +14,7 @@ import java.util.List; ...@@ -13,7 +14,7 @@ import java.util.List;
* The SalientBehaviorCognition class should provide logic to change the salient behavior of a pedestrian * The SalientBehaviorCognition class should provide logic to change the salient behavior of a pedestrian
* (e.g., change to cooperative behavior when no movement is possible for n steps). * (e.g., change to cooperative behavior when no movement is possible for n steps).
* *
* Watch out: The {@link EventCognition} should be finished before using methods in this class because usually * Watch out: The {@link EventCognition} should be finished before using methods in this class because, usually,
* first an event occurs and then pedestrians decide about their behavior. E.g., first a {@link BangEvent} occurs * first an event occurs and then pedestrians decide about their behavior. E.g., first a {@link BangEvent} occurs
* and then a pedestrian decides to follow a {@link SalientBehavior#COOPERATIVE} behavior. * and then a pedestrian decides to follow a {@link SalientBehavior#COOPERATIVE} behavior.
*/ */
...@@ -27,11 +28,23 @@ public class SalientBehaviorCognition { ...@@ -27,11 +28,23 @@ public class SalientBehaviorCognition {
} }
public void setSalientBehaviorForPedestrians(Collection<Pedestrian> pedestrians, double simTimeInSec) { public void setSalientBehaviorForPedestrians(Collection<Pedestrian> pedestrians, double simTimeInSec) {
// TODO: Set salient behavior for each pedestrian individually based on the most important event and/or if
// the pedestrian could not move for several time steps.
for (Pedestrian pedestrian : pedestrians) { for (Pedestrian pedestrian : pedestrians) {
// TODO: Set salient behavior for each pedestrian individually based on the most important event and/or if // TODO: Maybe, add following variables as attribute to "AttributesAgent".
// the pedestrian could not move for several time steps. int requiredFootSteps = 5;
double requiredSpeedInMetersPerSecondToBeCooperative = 0.05;
LastFootSteps lastFootSteps = pedestrian.getFootSteps().getLastFootSteps();
// TODO: Use pedestrian.getFootSteps() to calculate average velocity for last if (lastFootSteps.size() >= requiredFootSteps) { // Adapt behavior only if we have seen some footsteps in the past
if (lastFootSteps.getAverageSpeedInMeterPerSecond() <= requiredSpeedInMetersPerSecondToBeCooperative) {
pedestrian.setSalientBehavior(SalientBehavior.COOPERATIVE);
} else {
pedestrian.setSalientBehavior(SalientBehavior.TARGET_ORIENTED);
}
}
} }
} }
} }
...@@ -4,6 +4,7 @@ import org.vadere.state.attributes.scenario.AttributesAgent; ...@@ -4,6 +4,7 @@ import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.behavior.SalientBehavior; import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.events.types.Event; import org.vadere.state.events.types.Event;
import org.vadere.state.simulation.FootStep; import org.vadere.state.simulation.FootStep;
import org.vadere.state.simulation.LastFootSteps;
import org.vadere.state.simulation.VTrajectory; import org.vadere.state.simulation.VTrajectory;
import org.vadere.state.types.ScenarioElementType; import org.vadere.state.types.ScenarioElementType;
...@@ -83,13 +84,6 @@ public class Pedestrian extends Agent { ...@@ -83,13 +84,6 @@ public class Pedestrian extends Agent {
trajectory = other.trajectory; trajectory = other.trajectory;
} }
public void clearFootSteps() {
trajectory.clear();
}
public VTrajectory getFootSteps() {
return trajectory;
}
// Getter // Getter
public int getIdAsTarget() { public int getIdAsTarget() {
return this.idAsTarget; return this.idAsTarget;
...@@ -111,6 +105,9 @@ public class Pedestrian extends Agent { ...@@ -111,6 +105,9 @@ public class Pedestrian extends Agent {
public ScenarioElementType getType() { public ScenarioElementType getType() {
return ScenarioElementType.PEDESTRIAN; return ScenarioElementType.PEDESTRIAN;
} }
public VTrajectory getFootSteps() {
return trajectory;
}
// Setter // Setter
public void setIdAsTarget(int id) { this.idAsTarget = id; } public void setIdAsTarget(int id) { this.idAsTarget = id; }
...@@ -142,6 +139,12 @@ public class Pedestrian extends Agent { ...@@ -142,6 +139,12 @@ public class Pedestrian extends Agent {
groupSizes.add(size); groupSizes.add(size);
} }
public void clearFootSteps() {
trajectory.clear();
}
// Overridden Methods
@Override @Override
public Pedestrian clone() { public Pedestrian clone() {
return new Pedestrian(this); return new Pedestrian(this);
......
...@@ -23,6 +23,7 @@ public class LastFootSteps { ...@@ -23,6 +23,7 @@ public class LastFootSteps {
// Getters // Getters
public int getCapacity() { return capacity; } public int getCapacity() { return capacity; }
public ArrayList<FootStep> getFootSteps() { return footSteps; } public ArrayList<FootStep> getFootSteps() { return footSteps; }
public int size() { return footSteps.size(); }
// Methods // Methods
public boolean add(FootStep footStep) { public boolean add(FootStep footStep) {
......
...@@ -14,9 +14,11 @@ import java.util.stream.Stream; ...@@ -14,9 +14,11 @@ import java.util.stream.Stream;
public class VTrajectory implements Iterable<FootStep> { public class VTrajectory implements Iterable<FootStep> {
// Variables
private LinkedList<FootStep> footSteps; private LinkedList<FootStep> footSteps;
private transient LastFootSteps lastFootSteps; private transient LastFootSteps lastFootSteps;
// Constructors
public VTrajectory(){ public VTrajectory(){
this(10); this(10);
} }
...@@ -26,6 +28,16 @@ public class VTrajectory implements Iterable<FootStep> { ...@@ -26,6 +28,16 @@ public class VTrajectory implements Iterable<FootStep> {
lastFootSteps = new LastFootSteps(lastFootStepCapacity); lastFootSteps = new LastFootSteps(lastFootStepCapacity);
} }
// Getters
public LinkedList<FootStep> getFootSteps() {
return new LinkedList<>(footSteps);
}
public LastFootSteps getLastFootSteps() {
return lastFootSteps;
}
// Methods
public Optional<Double> speed(@NotNull final VRectangle rectangle) { public Optional<Double> speed(@NotNull final VRectangle rectangle) {
VTrajectory cutting = clone(); VTrajectory cutting = clone();
cutting.cut(rectangle); cutting.cut(rectangle);
...@@ -162,14 +174,12 @@ public class VTrajectory implements Iterable<FootStep> { ...@@ -162,14 +174,12 @@ public class VTrajectory implements Iterable<FootStep> {
} }
public VTrajectory clone() { public VTrajectory clone() {
LinkedList<FootStep> copy = new LinkedList<>(footSteps); VTrajectory newTrajectory = new VTrajectory();
VTrajectory clone = new VTrajectory();
clone.footSteps = copy;
return clone;
}
public LinkedList<FootStep> getFootSteps() { LinkedList<FootStep> footStepCopy = new LinkedList<>(footSteps);
return new LinkedList<>(footSteps); newTrajectory.footSteps = footStepCopy;
return newTrajectory;
} }
public VTrajectory cut(final double startTime, final double endTime) { public VTrajectory cut(final double startTime, final double endTime) {
......
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