Commit ddcd3966 authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Refactor, doc, and outline a smarter algorithm

parent 7688aaf7
......@@ -7,24 +7,56 @@ import org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeP
import org.vadere.state.scenario.Pedestrian;
/**
* Problems with this class:
*
* - evacuation time is saved on every update (inefficient)
* - only works if agents are deleted at their targets
*
* A more better way could be implemented using target listener. In this case it
* is important to check that the target is the agent's final (last) target.
*
* @author Mario Teixeira Parente
* @author Jakob Schöttl
*
*/
public class PedestrianEvacuationTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
private PedestrianStartTimeProcessor pedStTimeProc;
private PedestrianStartTimeProcessor pedStartTimeProc;
public PedestrianEvacuationTimeProcessor() {
super("evacuationTime");
}
@Override
public void init(final ProcessorManager manager) {
AttributesPedestrianEvacuationTimeProcessor att = (AttributesPedestrianEvacuationTimeProcessor) this.getAttributes();
pedStartTimeProc = (PedestrianStartTimeProcessor) manager.getProcessor(att.getPedestrianStartTimeProcessorId());
}
// @Override
// public void preLoop(SimulationState state) {
// final TargetListener targetListener = new TargetListener() {
// @Override
// public void reachedTarget(Target target, Agent agent) {
// final PedestrianIdKey pedKey = new PedestrianIdKey(agent.getId());
// final double timeUntilTargetReached = state.getSimTimeInSec() - pedStartTimeProc.getValue(pedKey);
// System.out.println(timeUntilTargetReached);
// setValue(pedKey, timeUntilTargetReached);
// }
// };
//
// for (Target target : state.getTopography().getTargets()) {
// target.addListener(targetListener);
// }
// }
@Override
protected void doUpdate(final SimulationState state) {
this.pedStTimeProc.update(state);
pedStartTimeProc.update(state);
state.getTopography().getElements(Pedestrian.class).stream()
.map(ped -> new PedestrianIdKey(ped.getId()))
.forEach(key -> this.setValue(key, state.getSimTimeInSec() - this.pedStTimeProc.getValue(key)));
.forEach(key -> this.setValue(key, state.getSimTimeInSec() - pedStartTimeProc.getValue(key)));
}
@Override
......@@ -34,9 +66,4 @@ public class PedestrianEvacuationTimeProcessor extends DataProcessor<PedestrianI
.forEach(key -> this.setValue(key, Double.NaN));
}
@Override
public void init(final ProcessorManager manager) {
AttributesPedestrianEvacuationTimeProcessor att = (AttributesPedestrianEvacuationTimeProcessor) this.getAttributes();
this.pedStTimeProc = (PedestrianStartTimeProcessor) manager.getProcessor(att.getPedestrianStartTimeProcessorId());
}
}
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