Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 6ecd3422 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Added two new output processors ("PedestrianMostImportantEventProcessor" and...

Added two new output processors ("PedestrianMostImportantEventProcessor" and "PedestrianEventProcessor") and use them in "TrajectoryReader".
parent 1a477fa7
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"files" : [ { "files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile", "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories", "filename" : "postvis.trajectories",
"processors" : [ 1, 2 ] "processors" : [ 1, 2, 5 ]
}, { }, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile", "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "overlaps.csv", "filename" : "overlaps.csv",
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
"attributes" : { "attributes" : {
"pedestrianOverlapProcessorId" : 3 "pedestrianOverlapProcessorId" : 3
} }
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSalientBehaviorProcessor",
"id" : 5
} ], } ],
"isTimestamped" : true, "isTimestamped" : true,
"isWriteMetaData" : false "isWriteMetaData" : false
......
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.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
/**
* Save most important event of a pedestrian in each time step in an own column.
*/
@DataProcessorClass()
public class PedestrianMostImportantEventProcessor extends DataProcessor<TimestepPedestrianIdKey, String> {
public PedestrianMostImportantEventProcessor() {
super("mostImportantEvent");
}
@Override
public void doUpdate(final SimulationState state) {
Collection<Pedestrian> pedestrians = state.getTopography().getElements(Pedestrian.class);
pedestrians.forEach(pedestrian -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()),
pedestrian.getMostImportantEvent().toStringForOutputProcessor())
);
}
}
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.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
/**
* Save salient behavior of a pedestrian in each time step in an own column.
*/
@DataProcessorClass()
public class PedestrianSalientBehaviorProcessor extends DataProcessor<TimestepPedestrianIdKey, String> {
public PedestrianSalientBehaviorProcessor() {
super("salientBehavior");
}
@Override
public void doUpdate(final SimulationState state) {
Collection<Pedestrian> pedestrians = state.getTopography().getElements(Pedestrian.class);
pedestrians.forEach(pedestrian -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()),
pedestrian.getSalientBehavior().toString())
);
}
}
...@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull; ...@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.Scenario; import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor; import org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor;
import org.vadere.state.attributes.scenario.AttributesAgent; import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep; import org.vadere.state.simulation.FootStep;
...@@ -44,6 +45,7 @@ public class TrajectoryReader { ...@@ -44,6 +45,7 @@ public class TrajectoryReader {
private static final String SPLITTER = " "; private static final String SPLITTER = " ";
private static Logger logger = Logger.getLogger(IOVadere.class); private static Logger logger = Logger.getLogger(IOVadere.class);
private Path trajectoryFilePath; private Path trajectoryFilePath;
private AttributesAgent attributesPedestrian; private AttributesAgent attributesPedestrian;
private Set<String> pedestrianIdKeys; private Set<String> pedestrianIdKeys;
...@@ -54,7 +56,8 @@ public class TrajectoryReader { ...@@ -54,7 +56,8 @@ public class TrajectoryReader {
private Set<String> groupIdKeys; private Set<String> groupIdKeys;
private Set<String> groupSizeKeys; private Set<String> groupSizeKeys;
private Set<String> stridesKeys; private Set<String> stridesKeys;
private Set<String> mostImportantEventKeys;
private Set<String> salientBehaviorKeys;
private int pedIdIndex; private int pedIdIndex;
private int stepIndex; private int stepIndex;
...@@ -64,6 +67,8 @@ public class TrajectoryReader { ...@@ -64,6 +67,8 @@ public class TrajectoryReader {
private int groupIdIndex; private int groupIdIndex;
private int groupSizeIndex; private int groupSizeIndex;
private int stridesIndex; private int stridesIndex;
private int mostImportantEventIndex;
private int salientBehaviorIndex;
public TrajectoryReader(final Path trajectoryFilePath, final Scenario scenario) { public TrajectoryReader(final Path trajectoryFilePath, final Scenario scenario) {
this(trajectoryFilePath, scenario.getAttributesPedestrian()); this(trajectoryFilePath, scenario.getAttributesPedestrian());
...@@ -84,6 +89,8 @@ public class TrajectoryReader { ...@@ -84,6 +89,8 @@ public class TrajectoryReader {
groupIdKeys = new HashSet<>(); groupIdKeys = new HashSet<>();
groupSizeKeys = new HashSet<>(); groupSizeKeys = new HashSet<>();
stridesKeys = new HashSet<>(); stridesKeys = new HashSet<>();
mostImportantEventKeys = new HashSet<>();
salientBehaviorKeys = new HashSet<>();
//should be set via Processor.getHeader //should be set via Processor.getHeader
pedestrianIdKeys.add("id"); pedestrianIdKeys.add("id");
...@@ -97,6 +104,8 @@ public class TrajectoryReader { ...@@ -97,6 +104,8 @@ public class TrajectoryReader {
groupSizeKeys.add("groupSize"); groupSizeKeys.add("groupSize");
stridesKeys.add("strides"); stridesKeys.add("strides");
stridesKeys.add("footSteps"); stridesKeys.add("footSteps");
mostImportantEventKeys.add("mostImportantEvent");
salientBehaviorKeys.add("salientBehavior");
pedIdIndex = -1; pedIdIndex = -1;
stepIndex = -1; stepIndex = -1;
...@@ -106,7 +115,8 @@ public class TrajectoryReader { ...@@ -106,7 +115,8 @@ public class TrajectoryReader {
groupIdIndex = -1; groupIdIndex = -1;
groupSizeIndex = -1; groupSizeIndex = -1;
stridesIndex = -1; stridesIndex = -1;
mostImportantEventIndex = -1;
salientBehaviorIndex = -1;
} }
public Map<Step, List<Agent>> readFile() throws IOException { public Map<Step, List<Agent>> readFile() throws IOException {
...@@ -131,12 +141,14 @@ public class TrajectoryReader { ...@@ -131,12 +141,14 @@ public class TrajectoryReader {
targetIdIndex = index; targetIdIndex = index;
} else if (groupIdKeys.contains(columns[index])){ } else if (groupIdKeys.contains(columns[index])){
groupIdIndex = index; groupIdIndex = index;
} } else if (groupSizeKeys.contains(columns[index])){
else if (groupSizeKeys.contains(columns[index])){
groupSizeIndex = index; groupSizeIndex = index;
} } else if(stridesKeys.contains(columns[index])) {
else if(stridesKeys.contains(columns[index])) {
stridesIndex = index; stridesIndex = index;
} else if (mostImportantEventKeys.contains(columns[index])) {
mostImportantEventIndex = index;
} else if (salientBehaviorKeys.contains(columns[index])) {
salientBehaviorIndex = index;
} }
} }
try { try {
...@@ -233,6 +245,15 @@ public class TrajectoryReader { ...@@ -233,6 +245,15 @@ public class TrajectoryReader {
} }
} }
if (mostImportantEventIndex != -1) {
// TODO: Convert string (in column) to event object (this requires a factory) and call ped.setMostImportantEvent(...).
}
if (salientBehaviorIndex != -1) {
SalientBehavior salientBehavior = SalientBehavior.valueOf(rowTokens[salientBehaviorIndex]);
ped.setSalientBehavior(salientBehavior);
}
return Pair.create(new Step(step), ped); return Pair.create(new Step(step), ped);
} }
} }
...@@ -98,4 +98,8 @@ public abstract class Event { ...@@ -98,4 +98,8 @@ public abstract class Event {
return string; return string;
} }
public String toStringForOutputProcessor() {
return this.getClass().getSimpleName();
}
} }
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