Commit a7975b84 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

implementation of different pedestrian velocity processors.

parent 9242f483
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
public abstract class APedestrianVelocityProcessor extends DataProcessor<TimestepPedestrianIdKey, Double> {
public APedestrianVelocityProcessor() {
super("velocity");
}
}
......@@ -38,7 +38,7 @@ public class FundamentalDiagramAProcessor extends DataProcessor<TimestepKey, Lis
private double deltaTime;
private double deltaSimTime;
private PedestrianLineCrossProcessor pedestrianLineCrossProcessor;
private PedestrianVelocityProcessor pedestrianVelocityProcessor;
private APedestrianVelocityProcessor pedestrianVelocityProcessor;
public FundamentalDiagramAProcessor() {
super("measurementTime", "deltaTime", "flow", "velocity", "density");
......@@ -50,7 +50,7 @@ public class FundamentalDiagramAProcessor extends DataProcessor<TimestepKey, Lis
AttributesFundamentalDiagramAProcessor att = (AttributesFundamentalDiagramAProcessor) this.getAttributes();
deltaTime = att.getDeltaTime();
pedestrianLineCrossProcessor = (PedestrianLineCrossProcessor) manager.getProcessor(att.getPedestrianLineCrossProcessorId());
pedestrianVelocityProcessor = (PedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
}
@Override
......
......@@ -15,8 +15,8 @@ import java.util.HashMap;
import java.util.Map;
/**
* <p>This processor computes the fundamental diagram by computing an (average) velocity and the density
* over a certain area <tt>measurementArea</tt>. The <tt>velocity</tt> of a pedestrian is the distance walked inside
* <p>This processor computes the fundamental diagram by computing an (average) velocity and the density for each
* pedestrian over a certain area <tt>measurementArea</tt>. The <tt>velocity</tt> of a pedestrian is the distance walked inside
* the <tt>measurementArea</tt> divided by the required time. The <tt>density</tt> of a pedestrian is the integral
* of the number of pedestrians inside the <tt>measurementArea</tt> (integrated over the time) divided by the area
* of the <tt>measurementArea</tt> and the time required to walk through the <tt>measurementArea</tt>. The bound of
......@@ -25,6 +25,8 @@ import java.util.Map;
*
* <p>For more details see zhang-2011 (doi:10.1088/1742-5468/2011/06/P06004) Method B.</p>
*
* <p>Note that this processor does only work if pedestrians do not move multiple times through <tt>measurementArea</tt></p>
*
* @author Benedikt Zoennchen
*/
@DataProcessorClass()
......
......@@ -26,7 +26,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> {
private VRectangle measurementArea;
private PedestrianVelocityProcessor pedestrianVelocityProcessor;
private APedestrianVelocityProcessor pedestrianVelocityProcessor;
public FundamentalDiagramCProcessor() {
super("velocity", "density");
......@@ -37,7 +37,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager);
AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes();
measurementArea = att.getMeasurementArea();
pedestrianVelocityProcessor = (PedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
}
@Override
......
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.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianVelocityByTrajectoryProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import java.util.LinkedList;
/**
* This processor computes the velocity based on pedestrian trajectories i.e. a list of foot steps.
* This might be more accurate than using {@link PedestrianVelocityProcessor} which uses only positions.
* For example in the optimal steps model a pedestrian might move multiple times during one time step.
* Let t = (p1,p2), (p2,p3), and so on, (pn,pn+1) be the trajectory of a pedestrian at the current time step s.
* Then the processor cuts the trajectory based on how much the processor should look into the past which is
* controlled by <tt>backSteps</tt>. By cutting the trajectory is linear interpolated i.e. the cut don't have to be
* at the end or the beginning of a foot step but can be in between. The velocity is equal to the sum of all
* length of foot steps divided by the duration.
*
* @author Benedikt Zoennchen
*
*/
@DataProcessorClass()
public class PedestrianVelocityByTrajectoryProcessor extends APedestrianVelocityProcessor {
private PedestrianTrajectoryProcessor pedestrianTrajectoryProcessor;
private int backSteps;
private LinkedList<Double> lastSimTimes;
public PedestrianVelocityByTrajectoryProcessor() {
super();
setAttributes(new AttributesPedestrianVelocityByTrajectoryProcessor());
this.lastSimTimes = new LinkedList<>();
this.lastSimTimes.add(0.0);
}
@Override
public void doUpdate(final SimulationState state) {
pedestrianTrajectoryProcessor.update(state);
Integer timeStep = state.getStep();
state.getTopography().getElements(Pedestrian.class)
.stream()
.map(ped -> ped.getId())
.forEach(pedId -> putValue(new TimestepPedestrianIdKey(timeStep, pedId), getVelocity(timeStep, state.getSimTimeInSec(), pedId)));
if (lastSimTimes.size() >= backSteps) {
lastSimTimes.removeFirst();
}
lastSimTimes.addLast(state.getSimTimeInSec());
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianVelocityByTrajectoryProcessor attVelProc = (AttributesPedestrianVelocityByTrajectoryProcessor) getAttributes();
this.pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(attVelProc.getPedestrianTrajectoryProcessorId());
this.backSteps = attVelProc.getBackSteps();
this.lastSimTimes = new LinkedList<>();
this.lastSimTimes.add(0.0);
}
private double getVelocity(int timeStep, double currentSimTime, int pedId) {
int pastStep = timeStep - backSteps;
double velocity = 0.0;
if(pastStep >= 1) {
double startTime = lastSimTimes.getFirst();
double endTime = currentSimTime;
double duration = (endTime - startTime);
velocity = pedestrianTrajectoryProcessor.getValue(new PedestrianIdKey(pedId)).cut(startTime, endTime).speed().orElse(0.0);
}
return velocity;
}
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesPedestrianVelocityByTrajectoryProcessor());
}
return super.getAttributes();
}
}
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;
/**
* This processor computes the velocity based on pedestrians simulation velocity. So the
* velocity depends on the model implementation and how the velocity of an agent is updated.
*
* @author Benedikt Zoennchen
*
*/
@DataProcessorClass()
public class PedestrianVelocityDefaultProcessor extends APedestrianVelocityProcessor {
@Override
protected void doUpdate(SimulationState state) {
state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.forEach(p -> putValue(new TimestepPedestrianIdKey(state.getStep(),p.getId()), p.getVelocity().getLength()));
}
@Override
public Double getValue(TimestepPedestrianIdKey key) {
Double velocity = super.getValue(key);
if(velocity == null) {
velocity = 0.0;
}
return velocity;
}
}
......@@ -3,16 +3,13 @@ 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.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianVelocityProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.VTrajectory;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.LinkedList;
import java.util.stream.Stream;
/**
* This processor computes the velocity based on pedestrian positions and the simulation time.
......@@ -25,14 +22,14 @@ import java.util.stream.Stream;
*
*/
@DataProcessorClass()
public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestrianIdKey, Double> {
private PedestrianTrajectoryProcessor pedTrajProc;
public class PedestrianVelocityProcessor extends APedestrianVelocityProcessor {
private PedestrianPositionProcessor pedestrianPositionProcessor;
private int backSteps;
private LinkedList<Double> lastSimTimes;
public PedestrianVelocityProcessor() {
super("velocity");
super();
setAttributes(new AttributesPedestrianVelocityProcessor());
this.lastSimTimes = new LinkedList<>();
this.lastSimTimes.add(0.0);
......@@ -40,7 +37,7 @@ public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestria
@Override
public void doUpdate(final SimulationState state) {
pedTrajProc.update(state);
pedestrianPositionProcessor.update(state);
Integer timeStep = state.getStep();
state.getTopography().getElements(Pedestrian.class)
......@@ -59,7 +56,7 @@ public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestria
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianVelocityProcessor attVelProc = (AttributesPedestrianVelocityProcessor) getAttributes();
this.pedTrajProc = (PedestrianTrajectoryProcessor) manager.getProcessor(attVelProc.getPedestrianTrajectoryProcessorId());
this.pedestrianPositionProcessor = (PedestrianPositionProcessor) manager.getProcessor(attVelProc.getPedestrianPositionProcessorId());
this.backSteps = attVelProc.getBackSteps();
this.lastSimTimes = new LinkedList<>();
this.lastSimTimes.add(0.0);
......@@ -69,20 +66,18 @@ public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestria
int pastStep = timeStep - backSteps;
double velocity = 0.0;
if(pastStep >= 0) {
TimestepPedestrianIdKey keyBefore = new TimestepPedestrianIdKey(pastStep, pedId);
if(pastStep >= 1) {
if (timeStep <= 1)
return 0.0; // For performance
VPoint pastPosition = pedestrianPositionProcessor.getValue(new TimestepPedestrianIdKey(pastStep, pedId));
VPoint position = pedestrianPositionProcessor.getValue(new TimestepPedestrianIdKey(timeStep, pedId));
VTrajectory trajectory = pedTrajProc.getValue(new PedestrianIdKey(pedId));
double startTime = lastSimTimes.getFirst();
double endTime = currentSimTime;
double duration = (endTime - startTime);
if(pastPosition != null) {
double startTime = lastSimTimes.getFirst();
double endTime = currentSimTime;
double duration = (endTime - startTime);
velocity = trajectory.cut(startTime, endTime).speed().orElse(0.0);
return velocity;
velocity = position.subtract(pastPosition).scalarMultiply(1.0 / duration).distanceToOrigin();
}
}
return velocity;
......
......@@ -42,7 +42,7 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timeste
//add ProcessorId of required Processors to current Processor under test
AttributesPedestrianVelocityProcessor attr =
(AttributesPedestrianVelocityProcessor) testedProcessor.getAttributes();
attr.setPedestrianTrajectoryProcessorId(pedPosProcId);
attr.setPedestrianPositionProcessorId(pedPosProcId);
//create required Processor enviroment and add it to current Processor under test
pedPosProcEnv = new PedestrianPositionProcessorTestEnv(pedPosProcId);
......
package org.vadere.state.attributes.processor;
/**
* @author Benedikt Zoennchen
*
*/
public class AttributesPedestrianVelocityByTrajectoryProcessor extends AttributesProcessor {
private int pedestrianTrajectoryProcessorId;
private int backSteps = 1;
public int getPedestrianTrajectoryProcessorId() {
return pedestrianTrajectoryProcessorId;
}
public void setPedestrianTrajectoryProcessorId(int pedestrianTrajectoryProcessorId) {
checkSealed();
this.pedestrianTrajectoryProcessorId = pedestrianTrajectoryProcessorId;
}
public int getBackSteps() {
return this.backSteps;
}
public void setBackSteps(int backSteps) {
checkSealed();
this.backSteps = backSteps;
}
}
......@@ -4,18 +4,17 @@ package org.vadere.state.attributes.processor;
* @author Mario Teixeira Parente
*
*/
public class AttributesPedestrianVelocityProcessor extends AttributesProcessor {
private int pedestrianTrajectoryProcessorId;
private int pedestrianPositionProcessorId;
private int backSteps = 1;
public int getPedestrianTrajectoryProcessorId() {
return pedestrianTrajectoryProcessorId;
public int getPedestrianPositionProcessorId() {
return pedestrianPositionProcessorId;
}
public void setPedestrianTrajectoryProcessorId(int pedestrianTrajectoryProcessorId) {
public void setPedestrianPositionProcessorId(int pedestrianPositionProcessorId) {
checkSealed();
this.pedestrianTrajectoryProcessorId = pedestrianTrajectoryProcessorId;
this.pedestrianPositionProcessorId = pedestrianPositionProcessorId;
}
public int getBackSteps() {
......
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