Commit 8778ccb5 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "postLoop()" of "Simulation.java", clear the topography as very last step...

In "postLoop()" of "Simulation.java", clear the topography as very last step so that models and output processors can use it before and added "PedestrianTargetReachTimeProcessor"
parent 04f924c0
Pipeline #367880 passed with stages
in 139 minutes and 10 seconds
......@@ -6,8 +6,12 @@
### Added
- Added new output processor "PedestrianTargetReachTimeProcessor" to log the time when an agent reaches its target.
### Changed
- In `postLoop()` of `Simulation.java`, clear the topography as very last step so that models and output processors can use it before.
## v1.15 (2020-11-12)
### Added
......
......@@ -223,7 +223,6 @@ public class Simulation {
private void postLoop() {
simulationState = new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel);
topographyController.postLoop(this.simTimeInSec);
for (Model m : models) {
m.postLoop(simTimeInSec);
......@@ -237,7 +236,10 @@ public class Simulation {
processorManager.postLoop(this.simulationState);
}
// notify remoteManger that simulation ended. If a command waited for the next
// Models and processors require the latest topography for post processing.
// Therefore, reset topography afterwards (I guess resetting the topography was introduced by Stefan).
topographyController.postLoop(this.simTimeInSec);
// Notify remoteManger that simulation ended. If a command waited for the next
// simulation step notify it and execute command with current SimulationState.
setWaitForSimCommand(true); // its save to read the state now.
remoteRunListeners.forEach(RemoteRunListener::lastSimulationStepFinishedListener);
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.scenario.Pedestrian;
import java.util.Locale;
/**
* Log the time when a pedestrian reaches its final target. If a pedestrian does not reach the target
* before the simulation ends, log Double.POSITIVE_INFINITY (i.e., we enter the post loop and the
* topography still holds pedestrians).
*
* Use a simple map with pedestrian.getId() as key and update the value in each simulation step.
* This is a naive and inefficient approach, but it works.
*/
@DataProcessorClass()
public class PedestrianTargetReachTimeProcessor extends DataProcessor<PedestrianIdKey, String> {
public PedestrianTargetReachTimeProcessor() {
super("targetId reachTime");
}
@Override
protected void doUpdate(final SimulationState state) {
state.getTopography().getElements(Pedestrian.class).stream()
.forEach(pedestrian -> {
PedestrianIdKey pedId = new PedestrianIdKey(pedestrian.getId());
int targetId = (pedestrian.hasNextTarget()) ? pedestrian.getNextTargetId() : -1;
String targetAndReachTime = String.format(Locale.US,"%s %s", targetId, state.getSimTimeInSec());
this.putValue(pedId, targetAndReachTime);
});
}
@Override
public void postLoop(final SimulationState state) {
state.getTopography().getElements(Pedestrian.class).stream()
.forEach(pedestrian -> {
PedestrianIdKey pedId = new PedestrianIdKey(pedestrian.getId());
int targetId = (pedestrian.hasNextTarget()) ? pedestrian.getNextTargetId() : -1;
String targetAndReachTime = String.format(Locale.US,"%s %s", targetId, Double.POSITIVE_INFINITY);
this.putValue(pedId, targetAndReachTime);
});
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
}
}
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