Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 2fe334bb authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

before changing the velocity processor.

parent 5f80dd44
......@@ -6,6 +6,7 @@ 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.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramCProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -25,6 +26,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> {
private VRectangle measurementArea;
private PedestrianVelocityProcessor pedestrianVelocityProcessor;
public FundamentalDiagramCProcessor() {
super("velocity", "density");
......@@ -35,6 +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());
}
@Override
......@@ -52,6 +55,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
@Override
protected void doUpdate(SimulationState state) {
pedestrianVelocityProcessor.update(state);
long N = state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.filter(pedestrian -> measurementArea.contains(pedestrian.getPosition()))
......@@ -59,7 +63,10 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
double velocity = state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.filter(pedestrian -> measurementArea.contains(pedestrian.getPosition()))
.mapToDouble(pedestrian -> pedestrian.getVelocity().getLength())
.mapToDouble(pedestrian ->
//pedestrian.getVelocity().getLength()
pedestrianVelocityProcessor.getValue(new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()))
)
.sum();
if(N == 0) {
......
......@@ -27,6 +27,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double, Double>> {
private IntegralVoronoiAlgorithm integralVoronoiAlgorithm;
private PedestrianVelocityProcessor pedestrianVelocityProcessor;
public FundamentalDiagramDProcessor() {
super("velocity", "density");
......
......@@ -25,6 +25,7 @@ import java.util.stream.Stream;
@DataProcessorClass()
public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestrianIdKey, Double> {
private PedestrianPositionProcessor pedPosProc;
//private PedestrianTrajectoryProcessor
private int backSteps;
private LinkedList<Double> lastSimTimes;
......@@ -47,10 +48,10 @@ public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestria
.forEach(pedId -> putValue(new TimestepPedestrianIdKey(timeStep, pedId), getVelocity(timeStep, state.getSimTimeInSec(), pedId)));
if (lastSimTimes.size() >= backSteps) {
lastSimTimes.removeLast();
lastSimTimes.removeFirst();
}
lastSimTimes.addFirst(state.getSimTimeInSec());
lastSimTimes.addLast(state.getSimTimeInSec());
}
@Override
......@@ -66,16 +67,23 @@ public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestria
}
private double getVelocity(int timeStep, double currentSimTime, int pedId) {
TimestepPedestrianIdKey keyBefore = new TimestepPedestrianIdKey(timeStep - backSteps > 0 ? timeStep - backSteps : 1, pedId);
if (timeStep <= 1 || !pedPosProc.hasValue(keyBefore))
return 0.0; // For performance
int pastStep = timeStep - backSteps;
double velocity = 0.0;
if(pastStep >= 0) {
TimestepPedestrianIdKey keyBefore = new TimestepPedestrianIdKey(pastStep, pedId);
VPoint posBefore = pedPosProc.getValue(keyBefore);
VPoint posNow = pedPosProc.getValue(new TimestepPedestrianIdKey(timeStep, pedId));
double duration = (currentSimTime - lastSimTimes.getFirst());
if (timeStep <= 1 || !pedPosProc.hasValue(keyBefore))
return 0.0; // For performance
double velocity = duration > 0 ? posNow.subtract(posBefore).scalarMultiply(1 / duration).distanceToOrigin() : 0;
VPoint posBefore = pedPosProc.getValue(keyBefore);
VPoint posNow = pedPosProc.getValue(new TimestepPedestrianIdKey(timeStep, pedId));
double duration = (currentSimTime - lastSimTimes.getFirst());
velocity = duration > 0 ? posNow.subtract(posBefore).scalarMultiply(1 / duration).distanceToOrigin() : 0;
return velocity;
}
return velocity;
}
......
......@@ -4,6 +4,16 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class AttributesFundamentalDiagramCProcessor extends AttributesAreaProcessor {
private VRectangle measurementArea;
private int pedestrianVelocityProcessorId;
public int getPedestrianVelocityProcessorId() {
return pedestrianVelocityProcessorId;
}
public void setPedestrianVelocityProcessorId(int pedestrianVelocityProcessorId) {
checkSealed();
this.pedestrianVelocityProcessorId = pedestrianVelocityProcessorId;
}
public VRectangle getMeasurementArea() {
return measurementArea;
......
......@@ -5,6 +5,16 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class AttributesFundamentalDiagramDProcessor extends AttributesAreaProcessor {
private VRectangle measurementArea;
private VRectangle voronoiArea;
private int pedestrianVelocityProcessorId;
public int getPedestrianVelocityProcessorId() {
return pedestrianVelocityProcessorId;
}
public void setPedestrianVelocityProcessorId(int pedestrianVelocityProcessorId) {
checkSealed();
this.pedestrianVelocityProcessorId = pedestrianVelocityProcessorId;
}
public VRectangle getMeasurementArea() {
return measurementArea;
......
......@@ -88,7 +88,7 @@ public class VTrajectory implements Iterable<FootStep> {
public VTrajectory cut(@NotNull final VRectangle rectangle) {
LinkedList<FootStep> newFootSteps = new LinkedList<>();
boolean inside = rectangle.contains(footSteps.peekFirst().getStart());
boolean inside = !footSteps.isEmpty() ? rectangle.contains(footSteps.peekFirst().getStart()) : false;
for(FootStep footStep : footSteps) {
if(footStep.intersects(rectangle)) {
......
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