Commit 9c3017ed authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Renamed enum "SalientBehavior" to "SocialCategory" and renamed all dependent code

parent ebbd1706
......@@ -6,7 +6,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.io.ColumnNames;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.behavior.SalientBehavior;
import org.vadere.state.psychology.cognition.SocialCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.psychology.perception.types.StimulusFactory;
import org.vadere.state.scenario.Agent;
......@@ -55,7 +55,7 @@ public class TableTrajectoryFootStep {
public final int groupSizeCol;
private final int mostImportantStimulusCol;
private final int salientBehaviorCol;
private final int socialCategoryCol;
public static final int agentDFPedIdCol = 0;
public static final int birthTimeCol = 1;
......@@ -85,7 +85,7 @@ public class TableTrajectoryFootStep {
groupIdCol = columnNames.getGroupIdCol(dataFrame);
groupSizeCol = columnNames.getGroupSizeCol(dataFrame);
mostImportantStimulusCol = columnNames.getMostImportantEventCol(dataFrame);
salientBehaviorCol = columnNames.getSalientBehaviorCol(dataFrame);
socialCategoryCol = columnNames.getSalientBehaviorCol(dataFrame);
this.trajectoryDataFrame = dataFrame;
......@@ -143,10 +143,10 @@ public class TableTrajectoryFootStep {
pedestrian.setMostImportantStimulus(stimulus);
}
if(salientBehaviorCol != ColumnNames.NOT_SET_COLUMN_INDEX_IDENTIFIER) {
String salientBehaviorEnumName = row.getString(mostImportantStimulusCol);
SalientBehavior salientBehavior = SalientBehavior.valueOf(salientBehaviorEnumName);
pedestrian.setSalientBehavior(salientBehavior);
if(socialCategoryCol != ColumnNames.NOT_SET_COLUMN_INDEX_IDENTIFIER) {
String socialCategoryEnumName = row.getString(socialCategoryCol);
SocialCategory socialCategory = SocialCategory.valueOf(socialCategoryEnumName);
pedestrian.setSocialCategory(socialCategory);
}
return pedestrian;
......
package org.vadere.simulator.control;
import org.vadere.simulator.control.psychology.perception.StimulusProcessor;
import org.vadere.simulator.control.psychology.behavior.SalientBehaviorProcessor;
import org.vadere.simulator.control.psychology.cognition.SocialCategoryProcessor;
import org.vadere.simulator.control.psychology.perception.StimulusController;
import org.vadere.simulator.control.factory.SourceControllerFactory;
import org.vadere.simulator.models.DynamicElementFactory;
......@@ -80,7 +80,7 @@ public class Simulation {
private SimulationResult simulationResult;
private final StimulusController stimulusController;
private final StimulusProcessor stimulusProcessor;
private final SalientBehaviorProcessor salientBehaviorProcessor;
private final SocialCategoryProcessor socialCategoryProcessor;
private final ScenarioCache scenarioCache;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
......@@ -118,7 +118,7 @@ public class Simulation {
// "stimulusController" is final. Therefore, create object here and not in helper method.
this.stimulusController = new StimulusController(scenarioStore);
this.stimulusProcessor = new StimulusProcessor();
this.salientBehaviorProcessor = new SalientBehaviorProcessor(topography);
this.socialCategoryProcessor = new SocialCategoryProcessor(topography);
createControllers(topography, mainModel, random);
......@@ -390,7 +390,7 @@ public class Simulation {
stimulusProcessor.prioritizeStimuliForPedestrians(stimuli, pedestrians);
if (attributesSimulation.isUsePsychologyLayer()) {
salientBehaviorProcessor.setSalientBehaviorForPedestrians(pedestrians, simTimeInSec);
socialCategoryProcessor.setSocialCategoryOfPedestrian(pedestrians, simTimeInSec);
}
for (Model m : models) {
......
package org.vadere.simulator.control.psychology.behavior;
package org.vadere.simulator.control.psychology.cognition;
import org.vadere.simulator.control.psychology.perception.StimulusProcessor;
import org.vadere.state.psychology.cognition.SocialCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.behavior.SalientBehavior;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.FootstepHistory;
......@@ -10,25 +10,27 @@ import org.vadere.state.simulation.FootstepHistory;
import java.util.Collection;
/**
* The SalientBehaviorProcessor 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).
* The SocialCategoryProcessor class should provide logic to change the social
* category of a pedestrian (e.g., change to cooperative if no movement is
* possible for n steps).
*
* Watch out: The {@link StimulusProcessor} 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 Bang} occurs
* and then a pedestrian decides to follow a {@link SalientBehavior#COOPERATIVE} behavior.
* Watch out: The {@link StimulusProcessor} should be finished before using
* methods in this class because, usually, first a stimulus is processed and
* then pedestrians decide which behavior to follow. E.g., first a {@link Bang}
* occurs and then a pedestrian decides to follow a {@link SocialCategory#TARGET_ORIENTED}
* behavior.
*/
public class SalientBehaviorProcessor {
public class SocialCategoryProcessor {
/** The salient behavior depends also on the surrounding environment. */
/** The social category may also depend on the surrounding environment. */
private Topography topography;
public SalientBehaviorProcessor(Topography topography) {
public SocialCategoryProcessor(Topography topography) {
this.topography = topography;
}
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.
public void setSocialCategoryOfPedestrian(Collection<Pedestrian> pedestrians, double simTimeInSec) {
// TODO: Include more (pedestrian) attributes into decision process.
for (Pedestrian pedestrian : pedestrians) {
// TODO: Maybe, add following variables as attribute to "AttributesAgent".
......@@ -37,12 +39,14 @@ public class SalientBehaviorProcessor {
FootstepHistory footstepHistory = pedestrian.getFootstepHistory();
if (footstepHistory.size() >= requiredFootSteps) { // Adapt behavior only if we have seen some footsteps in the past
// Adapt category only if we have seen some footsteps in the past
if (footstepHistory.size() >= requiredFootSteps) {
if (footstepHistory.getAverageSpeedInMeterPerSecond() <= requiredSpeedInMetersPerSecondToBeCooperative) {
pedestrian.setSalientBehavior(SalientBehavior.COOPERATIVE);
pedestrian.setSocialCategory(SocialCategory.COOPERATIVE);
} else {
// TODO Maybe, check if area directed to target is free for a step (only then change to "TARGET_ORIENTED").
pedestrian.setSalientBehavior(SalientBehavior.TARGET_ORIENTED);
// TODO: Maybe, check if area directed to target is free for a step
// (only then change to "TARGET_ORIENTED").
pedestrian.setSocialCategory(SocialCategory.TARGET_ORIENTED);
}
}
}
......
......@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.potential.combinedPotentials.CombinedPotentialStrategy;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.behavior.SalientBehavior;
import org.vadere.state.psychology.cognition.SocialCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.ChangeTarget;
import org.vadere.state.psychology.perception.types.Stimulus;
......@@ -133,7 +133,7 @@ public class OSMBehaviorController {
if (closestPedestrians.size() > 0) {
for (Pedestrian closestPedestrian : closestPedestrians) {
if(pedestrian.hasNextTarget()) {
boolean closestPedIsCooperative = closestPedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE;
boolean closestPedIsCooperative = closestPedestrian.getSocialCategory() == SocialCategory.COOPERATIVE;
boolean targetOrientationDiffers = false;
// TODO: Use "pedestrian.getTargetGradient()" instead of "calculateAngleBetweenTargets()".
......
......@@ -3,7 +3,7 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.OSMBehaviorController;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.psychology.behavior.SalientBehavior;
import org.vadere.state.psychology.cognition.SocialCategory;
import org.vadere.state.psychology.perception.types.*;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -54,12 +54,12 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
if (mostImportantStimulus instanceof ElapsedTime) {
double stepDuration = pedestrian.getDurationNextStep();
if (pedestrian.getSalientBehavior() == SalientBehavior.TARGET_ORIENTED) {
if (pedestrian.getSocialCategory() == SocialCategory.TARGET_ORIENTED) {
// this can cause problems if the pedestrian desired speed is 0 (see speed adjuster)
pedestrian.updateNextPosition();
osmBehaviorController.makeStep(pedestrian, topography, stepDuration);
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + stepDuration);
} else if (pedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE) {
} else if (pedestrian.getSocialCategory() == SocialCategory.COOPERATIVE) {
// this call will also invoke setTimeOfNextStep
PedestrianOSM candidate = osmBehaviorController.findSwapCandidate(pedestrian, topography);
//TODO: Benedikt Kleinmeier:
......
......@@ -3,7 +3,7 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.OSMBehaviorController;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.psychology.behavior.SalientBehavior;
import org.vadere.state.psychology.cognition.SocialCategory;
import org.vadere.state.psychology.perception.types.*;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -55,9 +55,9 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
if (mostImportantStimulus instanceof ElapsedTime) {
pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
pedestrian.clearStrides();
if (pedestrian.getSalientBehavior() == SalientBehavior.TARGET_ORIENTED) {
if (pedestrian.getSocialCategory() == SocialCategory.TARGET_ORIENTED) {
useTimeCredit(pedestrian, timeStepInSec);
} else if (pedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE) {
} else if (pedestrian.getSocialCategory() == SocialCategory.COOPERATIVE) {
PedestrianOSM candidate = osmBehaviorController.findSwapCandidate(pedestrian, topography);
if(candidate != null) {
candidate.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
......
......@@ -3,7 +3,6 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.EventtimePedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.state.simulation.VTrajectory;
......@@ -11,13 +10,15 @@ import org.vadere.state.simulation.VTrajectory;
import java.util.Collection;
/**
* Save salient behavior of a pedestrian in each time step in an own column.
* Save social category of a pedestrian in each time step in an own column.
*/
@DataProcessorClass()
public class FootStepSalientBehaviorProcessor extends DataProcessor<EventtimePedestrianIdKey, String> {
public class FootStepSocialCategoryProcessor extends DataProcessor<EventtimePedestrianIdKey, String> {
public FootStepSalientBehaviorProcessor() {
super("salientBehavior");
public static String HEADER = "socialCategory";
public FootStepSocialCategoryProcessor() {
super(HEADER);
}
@Override
......@@ -26,7 +27,7 @@ public class FootStepSalientBehaviorProcessor extends DataProcessor<EventtimePed
for(Pedestrian p : pedestrians){
VTrajectory traj = p.getTrajectory();
String slaientBehavior = p.getSalientBehavior().toString();
String slaientBehavior = p.getSocialCategory().toString();
for(FootStep fs : traj.getFootSteps()){
this.putValue(new EventtimePedestrianIdKey(fs.getStartTime(), p.getId()), slaientBehavior);
}
......
......@@ -21,7 +21,7 @@ public final class ColumnNames {
private Set<String> startTimeKeys;
private Set<String> endTimeKeys;
private Set<String> mostImportantStimulusKeys;
private Set<String> salientBehaviorKeys;
private Set<String> socialCategoryKeys;
private List<Set<String>> keys;
public static final int NOT_SET_COLUMN_INDEX_IDENTIFIER = -1;
......@@ -46,7 +46,7 @@ public final class ColumnNames {
groupIdKeys = new HashSet<>();
groupSizeKeys = new HashSet<>();
mostImportantStimulusKeys = new HashSet<>();
salientBehaviorKeys = new HashSet<>();
socialCategoryKeys = new HashSet<>();
startTimeKeys = new HashSet<>();
endTimeKeys = new HashSet<>();
......@@ -68,7 +68,7 @@ public final class ColumnNames {
groupIdKeys.add("groupId");
groupSizeKeys.add("groupSize");
mostImportantStimulusKeys.add("mostImportantStimulus");
salientBehaviorKeys.add("salientBehavior");
socialCategoryKeys.add("socialCategory");
keys.add(pedestrianIdKeys);
keys.add(startX);
......@@ -79,13 +79,13 @@ public final class ColumnNames {
keys.add(groupIdKeys);
keys.add(groupSizeKeys);
keys.add(mostImportantStimulusKeys);
keys.add(salientBehaviorKeys);
keys.add(socialCategoryKeys);
keys.add(startTimeKeys);
keys.add(endTimeKeys);
}
public int getSalientBehaviorCol(@NotNull final Table dataFrame) {
return getColId(dataFrame, salientBehaviorKeys);
return getColId(dataFrame, socialCategoryKeys);
}
public int getMostImportantEventCol(@NotNull final Table dataFrame) {
......
......@@ -44,6 +44,8 @@ import org.vadere.simulator.projects.migration.jsontranformation.SimpleJsonTrans
* Also, rename
* - "useSalientBehavior" to "usePsychologyLayer" under "attributesSimulation" node
* - "FootStepMostImportantEventProcessor" to "FootStepMostImportantStimulusProcessor"
* - "FootStepSalientBehaviorProcessor" to "FootStepSocialCategoryProcessor"
* - "salientBehavior" in "dynamicElements" node
*/
@MigrationTransformation(targetVersionLabel = "1.5")
public class JsonTransformationV1_4ToV1_5 extends SimpleJsonTransformation {
......@@ -66,6 +68,8 @@ public class JsonTransformationV1_4ToV1_5 extends SimpleJsonTransformation {
renameMostImportantEventInDynamicElements(node);
renameUseSalientBehavior(node);
renameOutputProcessorMostImportantEvent(node);
renameOutputProcessorSalientBehavior(node);
renameSalientBehaviorInDynamicElements(node);
return node;
}
......@@ -173,6 +177,17 @@ public class JsonTransformationV1_4ToV1_5 extends SimpleJsonTransformation {
String oldName = "FootStepMostImportantEventProcessor";
String newName = "FootStepMostImportantStimulusProcessor";
renameOutputProcessor(node, oldName, newName);
}
private void renameOutputProcessorSalientBehavior(JsonNode node) throws MigrationException {
String oldName = "FootStepSalientBehaviorProcessor";
String newName = "FootStepSocialCategoryProcessor";
renameOutputProcessor(node, oldName, newName);
}
private void renameOutputProcessor(JsonNode node, String oldName, String newName) throws MigrationException {
JsonNode processorsNode = path(node, "processWriters/processors");
if (processorsNode.isArray()) {
......@@ -188,4 +203,21 @@ public class JsonTransformationV1_4ToV1_5 extends SimpleJsonTransformation {
}
}
private void renameSalientBehaviorInDynamicElements(JsonNode node) throws MigrationException {
String oldName = "salientBehavior";
String newName = "socialCategory";
JsonNode dynamicElementsNode = path(node, "scenario/topography/dynamicElements");
if (dynamicElementsNode.isArray()) {
for (JsonNode dynamicElementNode : dynamicElementsNode) {
JsonNode salientBehaviorNode = path(dynamicElementNode, "salientBehavior");
if (!salientBehaviorNode.isMissingNode()) {
renameField((ObjectNode)dynamicElementNode, oldName, newName);
}
}
}
}
}
package org.vadere.state.psychology.behavior;
/**
* A pedestrian follows one of these behaviors during the simulation.
* Please note that the behavior of a pedestrian can change during the simulation.
*/
public enum SalientBehavior {
TARGET_ORIENTED, COOPERATIVE
}
package org.vadere.state.psychology.cognition;
/**
* A pedestrian uses these social categories to derive a specific behavior.
* E.g., if a pedestrian is "COOPERATIVE", the pedestrian swaps places
* with other "COOPERATIVE" pedestrians.
*
* Watch out: The social category of a pedestrian can change during a simulation.
*/
public enum SocialCategory {
TARGET_ORIENTED, COOPERATIVE
}
package org.vadere.state.scenario;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.behavior.SalientBehavior;
import org.vadere.state.psychology.cognition.SocialCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.simulation.FootStep;
import org.vadere.state.simulation.FootstepHistory;
......@@ -25,7 +25,7 @@ public class Pedestrian extends Agent {
private boolean isChild; // TODO should actually be an attribute or a member of a subclass
private boolean isLikelyInjured; // TODO should actually be an attribute or a member of a subclass
private Stimulus mostImportantStimulus; /** Evaluated in each time step in "EventCognition". */
private SalientBehavior salientBehavior;
private SocialCategory socialCategory;
private LinkedList<Integer> groupIds; // TODO should actually be an attribute or a member of a subclass
/**
* trajectory is a list of foot steps a pedestrian made during the duration of one time step.
......@@ -59,7 +59,7 @@ public class Pedestrian extends Agent {
isChild = false;
isLikelyInjured = false;
mostImportantStimulus = null;
salientBehavior = SalientBehavior.TARGET_ORIENTED;
socialCategory = SocialCategory.TARGET_ORIENTED;
groupIds = new LinkedList<>();
groupSizes = new LinkedList<>();
modelPedestrianMap = new HashMap<>();
......@@ -74,7 +74,7 @@ public class Pedestrian extends Agent {
isChild = other.isChild;
isLikelyInjured = other.isLikelyInjured;
mostImportantStimulus = other.mostImportantStimulus;
salientBehavior = other.salientBehavior;
socialCategory = other.socialCategory;
if (other.groupIds != null) {
groupIds = new LinkedList<>(other.groupIds);
......@@ -100,7 +100,7 @@ public class Pedestrian extends Agent {
return isLikelyInjured;
}
public Stimulus getMostImportantStimulus() { return mostImportantStimulus; }
public SalientBehavior getSalientBehavior() { return salientBehavior; }
public SocialCategory getSocialCategory() { return socialCategory; }
public LinkedList<Integer> getGroupIds() { return groupIds; }
public LinkedList<Integer> getGroupSizes() {
return groupSizes;
......@@ -148,7 +148,7 @@ public class Pedestrian extends Agent {
this.isLikelyInjured = likelyInjured;
}
public void setMostImportantStimulus(Stimulus mostImportantStimulus) { this.mostImportantStimulus = mostImportantStimulus; }
public void setSalientBehavior(SalientBehavior salientBehavior) { this.salientBehavior = salientBehavior; }
public void setSocialCategory(SocialCategory socialCategory) { this.socialCategory = socialCategory; }
public void setGroupIds(LinkedList<Integer> groupIds) {
this.groupIds = groupIds;
}
......
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