Commit e218e7b1 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

In "Pedestrian", encapsulated psychology-related attributes into new class...

In "Pedestrian", encapsulated psychology-related attributes into new class "AttributesAgentPsychology"

Also updated "TargetVersionV1_5" to reflect this change.
parent 197b5cf9
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.vadere.annotation.factories.migrationassistant.MigrationTransformation;
import org.vadere.simulator.entrypoints.Version;
......@@ -45,7 +46,27 @@ import org.vadere.simulator.projects.migration.jsontranformation.SimpleJsonTrans
* - "useSalientBehavior" to "usePsychologyLayer" under "attributesSimulation" node
* - "FootStepMostImportantEventProcessor" to "FootStepMostImportantStimulusProcessor"
* - "FootStepSalientBehaviorProcessor" to "FootStepSelfCategoryProcessor"
* - "salientBehavior" in "dynamicElements" node
* - "salientBehavior" to "selfCategory" in "dynamicElement" nodes
*
* After renaming, encapsulate two psychology-related attributes into
* a new "psychlogy" node in "dynamicElement" nodes:
* - mostImportantStimulus
* - selfCategory
*
* A resctructured dynamic element node looks like this:
* <pre>
* {
* ...
* "psychology" : {
* "mostImportantStimulus" : {
* "type" : "ElapsedTime"
* },
* "selfCategory" : "TARGET_ORIENTED"
* },
* ...
* "type" : "PEDESTRIAN"
* }
* </pre>
*/
@MigrationTransformation(targetVersionLabel = "1.5")
public class TargetVersionV1_5 extends SimpleJsonTransformation {
......@@ -71,6 +92,8 @@ public class TargetVersionV1_5 extends SimpleJsonTransformation {
renameOutputProcessorSalientBehavior(node);
renameSalientBehaviorInDynamicElements(node);
createNewPsychologyNodeInDynamicElements(node);
return node;
}
......@@ -220,4 +243,39 @@ public class TargetVersionV1_5 extends SimpleJsonTransformation {
}
}
private void createNewPsychologyNodeInDynamicElements(JsonNode node) throws MigrationException {
String newNodeName = "psychology";
String[] nodeNamesToMove = new String[] {
"mostImportantStimulus",
"selfCategory"
};
JsonNode dynamicElementsNode = path(node, "scenario/topography/dynamicElements");
if (dynamicElementsNode.isArray()) {
for (JsonNode dynamicElementNode : dynamicElementsNode) {
// Create parent node for the nodes which will be moved
ObjectNode psychologyNode = JsonNodeFactory.instance.objectNode();
for (String nodeName : nodeNamesToMove) {
JsonNode nodeToMove = path(dynamicElementNode, nodeName);
if (!nodeToMove.isMissingNode()) {
psychologyNode.set(nodeName, nodeToMove);
remove(dynamicElementNode, nodeName);
}
}
// If new parent node is not empty, add it to the current "dynamicElement".
// Otherwise, the "psychology" node will be added by the Jackson library
// automatically.
if (psychologyNode.elements().hasNext()) {
((ObjectNode)dynamicElementNode).set(newNodeName, psychologyNode);
}
}
}
}
}
package org.vadere.state.attributes.scenario;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
public class AttributesAgentPsychology {
// Member Variables
private Stimulus mostImportantStimulus;
private SelfCategory selfCategory;
// Constructors
public AttributesAgentPsychology() {
this(null, SelfCategory.TARGET_ORIENTED);
}
public AttributesAgentPsychology(Stimulus mostImportantStimulus, SelfCategory selfCategory) {
this.mostImportantStimulus = mostImportantStimulus;
this.selfCategory = selfCategory;
}
// Getter
public Stimulus getMostImportantStimulus() { return mostImportantStimulus; }
public SelfCategory getSelfCategory() { return selfCategory; }
// Setter
public void setMostImportantStimulus(Stimulus mostImportantStimulus) {
this.mostImportantStimulus = mostImportantStimulus;
}
public void setSelfCategory(SelfCategory selfCategory) {
this.selfCategory = selfCategory;
}
}
package org.vadere.state.scenario;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesAgentPsychology;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.simulation.FootStep;
......@@ -24,9 +25,11 @@ public class Pedestrian extends Agent {
private int idAsTarget; // TODO should actually be an attribute or a member of a subclass
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 SelfCategory selfCategory;
private AttributesAgentPsychology psychology;
private LinkedList<Integer> groupIds; // TODO should actually be an attribute or a member of a subclass
private LinkedList<Integer> groupSizes;
/**
* trajectory is a list of foot steps a pedestrian made during the duration of one time step.
* For all non event driven models this is exactly one foot step. For the event driven update
......@@ -38,7 +41,6 @@ public class Pedestrian extends Agent {
/** This list stores the last n footsteps. I.e., this list is NOT cleared after each simulation loop like "trajectory" variable. */
private transient FootstepHistory footstepHistory;
private LinkedList<Integer> groupSizes;
private Map<Class<? extends ModelPedestrian>, ModelPedestrian> modelPedestrianMap;
private ScenarioElementType type = ScenarioElementType.PEDESTRIAN; // TODO used at all? For JSON de-/serialization? Car does NOT have this field. remove if unused!
......@@ -58,8 +60,7 @@ public class Pedestrian extends Agent {
idAsTarget = -1;
isChild = false;
isLikelyInjured = false;
mostImportantStimulus = null;
selfCategory = SelfCategory.TARGET_ORIENTED;
psychology = new AttributesAgentPsychology(null, SelfCategory.TARGET_ORIENTED);
groupIds = new LinkedList<>();
groupSizes = new LinkedList<>();
modelPedestrianMap = new HashMap<>();
......@@ -73,8 +74,10 @@ public class Pedestrian extends Agent {
idAsTarget = other.idAsTarget;
isChild = other.isChild;
isLikelyInjured = other.isLikelyInjured;
mostImportantStimulus = other.mostImportantStimulus;
selfCategory = other.selfCategory;
psychology = new AttributesAgentPsychology();
psychology.setMostImportantStimulus(other.getMostImportantStimulus());
psychology.setSelfCategory(other.getSelfCategory());
if (other.groupIds != null) {
groupIds = new LinkedList<>(other.groupIds);
......@@ -99,8 +102,8 @@ public class Pedestrian extends Agent {
public boolean isLikelyInjured() {
return isLikelyInjured;
}
public Stimulus getMostImportantStimulus() { return mostImportantStimulus; }
public SelfCategory getSelfCategory() { return selfCategory; }
public Stimulus getMostImportantStimulus() { return psychology.getMostImportantStimulus(); }
public SelfCategory getSelfCategory() { return psychology.getSelfCategory(); }
public LinkedList<Integer> getGroupIds() { return groupIds; }
public LinkedList<Integer> getGroupSizes() {
return groupSizes;
......@@ -147,8 +150,8 @@ public class Pedestrian extends Agent {
public void setLikelyInjured(boolean likelyInjured) {
this.isLikelyInjured = likelyInjured;
}
public void setMostImportantStimulus(Stimulus mostImportantStimulus) { this.mostImportantStimulus = mostImportantStimulus; }
public void setSelfCategory(SelfCategory selfCategory) { this.selfCategory = selfCategory; }
public void setMostImportantStimulus(Stimulus mostImportantStimulus) { psychology.setMostImportantStimulus(mostImportantStimulus); }
public void setSelfCategory(SelfCategory selfCategory) { psychology.setSelfCategory(selfCategory); }
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