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;
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.factory.SourceControllerFactory;
import org.vadere.simulator.models.DynamicElementFactory;
......@@ -71,6 +72,7 @@ public class Simulation {
private SimulationResult simulationResult;
private final EventController eventController;
private final EventCognition eventCognition;
private final SalientBehaviorCognition salientBehaviorCognition;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager,
......@@ -102,6 +104,7 @@ public class Simulation {
// "eventController" is final. Therefore, create object here and not in helper method.
this.eventController = new EventController(scenarioStore);
this.eventCognition = new EventCognition();
this.salientBehaviorCognition = new SalientBehaviorCognition(topography);
createControllers(topography, mainModel, random);
......@@ -317,7 +320,9 @@ public class Simulation {
step++;
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
eventCognition.prioritizeEventsForPedestrians(events, pedestrians);
salientBehaviorCognition.setSalientBehaviorForPedestrians(pedestrians, simTimeInSec);
for (Model m : models) {
List<SourceController> stillSpawningSource = this.sourceControllers.stream().filter(s -> !s.isSourceFinished(simTimeInSec)).collect(Collectors.toList());
......
......@@ -5,6 +5,7 @@ import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.events.types.Event;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.LastFootSteps;
import java.util.Collection;
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
* (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
* and then a pedestrian decides to follow a {@link SalientBehavior#COOPERATIVE} behavior.
*/
......@@ -27,11 +28,23 @@ public class SalientBehaviorCognition {
}
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) {
// 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.
// TODO: Maybe, add following variables as attribute to "AttributesAgent".
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;
import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.events.types.Event;
import org.vadere.state.simulation.FootStep;
import org.vadere.state.simulation.LastFootSteps;
import org.vadere.state.simulation.VTrajectory;
import org.vadere.state.types.ScenarioElementType;
......@@ -83,13 +84,6 @@ public class Pedestrian extends Agent {
trajectory = other.trajectory;
}
public void clearFootSteps() {
trajectory.clear();
}
public VTrajectory getFootSteps() {
return trajectory;
}
// Getter
public int getIdAsTarget() {
return this.idAsTarget;
......@@ -111,6 +105,9 @@ public class Pedestrian extends Agent {
public ScenarioElementType getType() {
return ScenarioElementType.PEDESTRIAN;
}
public VTrajectory getFootSteps() {
return trajectory;
}
// Setter
public void setIdAsTarget(int id) { this.idAsTarget = id; }
......@@ -142,6 +139,12 @@ public class Pedestrian extends Agent {
groupSizes.add(size);
}
public void clearFootSteps() {
trajectory.clear();
}
// Overridden Methods
@Override
public Pedestrian clone() {
return new Pedestrian(this);
......
......@@ -23,6 +23,7 @@ public class LastFootSteps {
// Getters
public int getCapacity() { return capacity; }
public ArrayList<FootStep> getFootSteps() { return footSteps; }
public int size() { return footSteps.size(); }
// Methods
public boolean add(FootStep footStep) {
......
......@@ -14,9 +14,11 @@ import java.util.stream.Stream;
public class VTrajectory implements Iterable<FootStep> {
// Variables
private LinkedList<FootStep> footSteps;
private transient LastFootSteps lastFootSteps;
// Constructors
public VTrajectory(){
this(10);
}
......@@ -26,6 +28,16 @@ public class VTrajectory implements Iterable<FootStep> {
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) {
VTrajectory cutting = clone();
cutting.cut(rectangle);
......@@ -162,14 +174,12 @@ public class VTrajectory implements Iterable<FootStep> {
}
public VTrajectory clone() {
LinkedList<FootStep> copy = new LinkedList<>(footSteps);
VTrajectory clone = new VTrajectory();
clone.footSteps = copy;
return clone;
}
VTrajectory newTrajectory = new VTrajectory();
public LinkedList<FootStep> getFootSteps() {
return new LinkedList<>(footSteps);
LinkedList<FootStep> footStepCopy = new LinkedList<>(footSteps);
newTrajectory.footSteps = footStepCopy;
return newTrajectory;
}
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