Commit d8646f68 authored by Marion Goedel's avatar Marion Goedel

Added QueueWidthProcessor (not yet tested).

parent d9d53034
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.TimestepKey;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.attributes.processor.AttributesQueueWidthProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* @author Marion Gödel
*
*/
@DataProcessorClass()
public class QueueWidthProcessor extends DataProcessor<TimestepKey, Double> {
private VPoint referencePoint;
private double maxDist;
private VPoint direction; /* can be either in x-direction [1, 0] or [-1, 0] or in y-direction [0, 1], [0,-1] */
public QueueWidthProcessor() {
super("queueWidth");
setAttributes(new AttributesQueueWidthProcessor());
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesQueueWidthProcessor att = (AttributesQueueWidthProcessor) this.getAttributes();
this.referencePoint = att.getReferencePoint();
this.maxDist = att.getMaxDist();
this.direction = att.getDirection();
}
@Override
protected void doUpdate(final SimulationState state) {
if( Math.abs(direction.getX()) > 0 ) {
double minX = Math.min(referencePoint.getX(), referencePoint.getX() + direction.getX()*maxDist);
double maxX = Math.max(referencePoint.getX(), referencePoint.getX() + direction.getX()*maxDist);
List<Pedestrian> pedQueue = state.getTopography().getElements(Pedestrian.class).stream().
filter(ped -> (ped.getPosition().getX() <= maxX && ped.getPosition().getX() >= minX ) )
.collect(Collectors.toList());
if (pedQueue.size() == 0){
this.putValue(new TimestepKey(state.getStep()), 0.0);
}else{
// according to seitz-2016c
double queue_measure = 0;
for (int i_ped = 0; i_ped < pedQueue.size(); i_ped++){
double delta_y = Math.abs(pedQueue.get(i_ped).getPosition().getX() - referencePoint.getX()); // X and Y are interchanged - compare supplementary material
double delta_x = Math.abs(pedQueue.get(i_ped).getPosition().getY() - referencePoint.getY());
queue_measure += (delta_y)/(1+delta_x);
}
queue_measure = queue_measure/pedQueue.size();
this.putValue(new TimestepKey(state.getStep()), queue_measure);
}
}
/* .map(ped -> new PedestrianIdKey(ped.getId()))
.forEach(key -> this.putValue(key, state.getSimTimeInSec() - pedStartTimeProc.getValue(key))); */
}
/* @Override
public void postLoop(final SimulationState state) {
state.getTopography().getElements(Pedestrian.class).stream()
.map(ped -> new PedestrianIdKey(ped.getId()))
.forEach(key -> this.putValue(key, Double.POSITIVE_INFINITY));
}*/
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesQueueWidthProcessor());
}
return super.getAttributes();
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Marion Gödel
*
*/
public class AttributesQueueWidthProcessor extends AttributesProcessor {
private VPoint referencePoint = new VPoint(0,0);
private double maxDist = 5.0;
private VPoint direction = new VPoint(0, 1);
public VPoint getReferencePoint(){ return referencePoint; }
public double getMaxDist(){ return maxDist; }
public VPoint getDirection(){ return direction; }
public void setReferencePoint(VPoint referencePoint){
checkSealed();
this.referencePoint = referencePoint;
}
public void setReferencePoint(double x, double y){
setReferencePoint(new VPoint(x,y));
}
public void setMaxDist(double maxDist) {
checkSealed();
this.maxDist = maxDist;
}
public void setDirection(VPoint direction){
if( direction.distanceToOrigin() != 1.0 || Math.max(Math.abs(direction.getX()), Math.abs(direction.getY())) != 1.0){
System.out.println("Warning! Only the following vectors are allowed: [1,0],[-1,0],[0,1],[0,-1]. It is continued with [1,0].");
direction = new VPoint(1, 0);
}
this.direction = direction;
}
public void setDirection(double x, double y){
checkSealed();
setDirection(new VPoint(x,y));
}
}
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