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

Implemented "SimpleCognitionModel" and documented existing cognition models

parent ffeeb4f3
...@@ -7,6 +7,15 @@ import org.vadere.state.simulation.FootstepHistory; ...@@ -7,6 +7,15 @@ import org.vadere.state.simulation.FootstepHistory;
import java.util.Collection; import java.util.Collection;
/**
* The {@link CooperativeCognitionModel} makes a pedestrian cooperative if its
* average speed falls below a certain threshold. I.e., usually the agent
* could not move for some time steps. For example, in case of other
* counter-flowing agents.
*
* {@link SelfCategory#COOPERATIVE} should motivate pedestrians to swap places
* instead of blindly walking to a target and colliding with other pedestrians.
*/
public class CooperativeCognitionModel implements ICognitionModel { public class CooperativeCognitionModel implements ICognitionModel {
private Topography topography; private Topography topography;
...@@ -19,7 +28,7 @@ public class CooperativeCognitionModel implements ICognitionModel { ...@@ -19,7 +28,7 @@ public class CooperativeCognitionModel implements ICognitionModel {
@Override @Override
public void update(Collection<Pedestrian> pedestrians) { public void update(Collection<Pedestrian> pedestrians) {
for (Pedestrian pedestrian : pedestrians) { for (Pedestrian pedestrian : pedestrians) {
// TODO: Maybe, add following variables as attribute to new class "AttributesCognition". // TODO: Maybe, add following variables as attributes to new class "AttributesCognition".
int requiredFootSteps = 2; int requiredFootSteps = 2;
double requiredSpeedInMetersPerSecondToBeCooperative = 0.05; double requiredSpeedInMetersPerSecondToBeCooperative = 0.05;
......
...@@ -20,7 +20,7 @@ import java.util.Collection; ...@@ -20,7 +20,7 @@ import java.util.Collection;
* different scenarios (by specifying in the JSON file). * different scenarios (by specifying in the JSON file).
* *
* The <code>initialize</code> method must be called before usage! * The <code>initialize</code> method must be called before usage!
* This interface defines a callbacks for the simulation loop. * This interface defines callbacks for the simulation loop.
* It's implementations define the major part of the simulation model's logic. * It's implementations define the major part of the simulation model's logic.
* *
* This approach is similar to the {@link Model} interface for locomotion models. * This approach is similar to the {@link Model} interface for locomotion models.
...@@ -28,8 +28,8 @@ import java.util.Collection; ...@@ -28,8 +28,8 @@ import java.util.Collection;
* Watch out: The perception phase should be finished before using * Watch out: The perception phase should be finished before using
* methods in this class because, usually, first a stimulus is processed and * methods in this class because, usually, first a stimulus is processed and
* then pedestrians decide which behavior to follow. E.g., first a {@link Threat} * then pedestrians decide which behavior to follow. E.g., first a {@link Threat}
* occurs and then a pedestrian decides to follow a {@link SelfCategory#TARGET_ORIENTED} * is recognized and then a pedestrian decides to follow a
* behavior. * {@link SelfCategory#INSIDE_THREAT_AREA} behavior.
*/ */
public interface ICognitionModel { public interface ICognitionModel {
......
package org.vadere.simulator.control.psychology.cognition;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.*;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import java.util.Collection;
/**
* The {@link SimpleCognitionModel} just passes the perceived stimulus to the
* behavioral/locomotion layer without further processing.
*/
public class SimpleCognitionModel implements ICognitionModel {
private Topography topography;
@Override
public void initialize(Topography topography) {
this.topography = topography;
}
@Override
public void update(Collection<Pedestrian> pedestrians) {
for (Pedestrian pedestrian : pedestrians) {
Stimulus stimulus = pedestrian.getMostImportantStimulus();
SelfCategory nextSelfCategory;
if (stimulus instanceof ChangeTarget) {
nextSelfCategory = SelfCategory.CHANGE_TARGET;
} else if (stimulus instanceof Threat) {
nextSelfCategory = SelfCategory.INSIDE_THREAT_AREA;
} else if (stimulus instanceof Wait || stimulus instanceof WaitInArea) {
nextSelfCategory = SelfCategory.WAIT;
} else if (stimulus instanceof ElapsedTime) {
nextSelfCategory = SelfCategory.TARGET_ORIENTED;
} else {
throw new IllegalArgumentException(String.format("Stimulus \"%s\" not supported by \"%s\"",
stimulus.getClass().getSimpleName(),
this.getClass().getSimpleName()));
}
pedestrian.setSelfCategory(nextSelfCategory);
}
}
}
...@@ -2,9 +2,9 @@ package org.vadere.simulator.control.psychology.cognition; ...@@ -2,9 +2,9 @@ package org.vadere.simulator.control.psychology.cognition;
import org.vadere.state.psychology.cognition.GroupMembership; import org.vadere.state.psychology.cognition.GroupMembership;
import org.vadere.state.psychology.cognition.SelfCategory; import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Threat;
import org.vadere.state.psychology.perception.types.ElapsedTime; import org.vadere.state.psychology.perception.types.ElapsedTime;
import org.vadere.state.psychology.perception.types.Stimulus; import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.psychology.perception.types.Threat;
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.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
...@@ -20,7 +20,7 @@ import java.util.stream.Collectors; ...@@ -20,7 +20,7 @@ import java.util.stream.Collectors;
* <ol> * <ol>
* <li>Is pedestrian inside threat area.</li> * <li>Is pedestrian inside threat area.</li>
* <li>Is pedestrian outside threat area.</li> * <li>Is pedestrian outside threat area.</li>
* <li>If pedestrian outside threat area, test if other pedestrians are nearby * <li>If pedestrian is outside threat area, test if other pedestrians are nearby
* who have perceived the threat. If so, imitate their behavior if they are in-group members.</li> * who have perceived the threat. If so, imitate their behavior if they are in-group members.</li>
* </ol> * </ol>
*/ */
......
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