Commit 00f626d2 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add ControllerProvider to SimulationState

parent c6332395
Pipeline #434083 passed with stages
in 121 minutes and 7 seconds
package org.vadere.simulator.control.simulation;
import org.vadere.simulator.control.scenarioelements.AbsorbingAreaController;
import org.vadere.simulator.control.scenarioelements.SourceController;
import org.vadere.simulator.control.scenarioelements.TargetChangerController;
import org.vadere.simulator.control.scenarioelements.TargetController;
import org.vadere.simulator.control.scenarioelements.TeleporterController;
import org.vadere.simulator.control.scenarioelements.TopographyController;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import java.util.Collection;
public interface ControllerProvider {
Collection<SourceController> getSourceControllers();
Collection<TargetController> getTargetControllers();
Collection<TargetChangerController> getTargetChangerControllers();
Collection<AbsorbingAreaController> getAbsorbingAreaControllers();
TeleporterController getTeleporterController();
TopographyController getTopographyController();
ProcessorManager getProcessorManager();
}
......@@ -43,30 +43,6 @@ public class OfflineSimulation {
this.trajectories = null;
this.simulationStates = null;
/*this.trajectories = pedestriansByStep
.entrySet()
.stream()
.flatMap(entry -> entry.getValue().stream())
.map(ped -> ped.getId())
.distinct()
.map(id -> new Trajectory(pedestriansByStep, id, vadere.getAttributesSimulation().getSimTimeStepLength()))
.collect(Collectors.toMap(t -> t.getPedestrianId(), t -> t));
topographyController.prepareTopography();
simulationStates = pedestriansByStep.keySet().stream().sorted().map(step -> generateSimulationState(step))
.collect(Collectors.toList());*/
}
private SimulationState generateSimulationState(final Step step) {
Topography topography = topographyController.getTopography().clone();
topography.reset();
// add pedestrians to the topography
trajectories.values().stream()
.filter(t -> t.isAlive(step.getStepNumber()))
.map(t -> t.getAgent(step.getStepNumber()))
.filter(opt -> opt.isPresent()).forEach(opt -> topography.addElement(opt.get()));
return new SimulationState(vadere.getName(), topography, vadere.getScenarioStore(),
(step.getStepNumber()-1) * vadere.getAttributesSimulation().getSimTimeStepLength(), step.getStepNumber(), null);
}
private void prepareOutput() {
......
......@@ -33,7 +33,7 @@ import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class Simulation {
public class Simulation implements ControllerProvider{
private static Logger logger = Logger.getLogger(Simulation.class);
......@@ -222,7 +222,7 @@ public class Simulation {
}
private void postLoop() {
simulationState = new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel);
simulationState = new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel, this);
for (Model m : models) {
m.postLoop(simTimeInSec);
......@@ -283,7 +283,7 @@ public class Simulation {
updateCallbacks(simTimeInSec);
step++;
this.simulationState = new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel);
this.simulationState = new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel, this);
if (attributesSimulation.isWriteSimulationData()) {
processorManager.update(this.simulationState);
......@@ -370,7 +370,7 @@ public class Simulation {
}
private SimulationState initialSimulationState() {
SimulationState state = new SimulationState(name, topography.clone(), scenarioStore, simTimeInSec, step, mainModel);
SimulationState state = new SimulationState(name, topography.clone(), scenarioStore, simTimeInSec, step, mainModel, this);
return state;
}
......@@ -550,4 +550,38 @@ public class Simulation {
return stimulusController;
}
@Override
public Collection<SourceController> getSourceControllers() {
return sourceControllers;
}
@Override
public Collection<TargetController> getTargetControllers() {
return targetControllers;
}
@Override
public Collection<TargetChangerController> getTargetChangerControllers() {
return targetChangerControllers;
}
@Override
public Collection<AbsorbingAreaController> getAbsorbingAreaControllers() {
return absorbingAreaControllers;
}
@Override
public TeleporterController getTeleporterController() {
return teleporterController;
}
@Override
public TopographyController getTopographyController() {
return topographyController;
}
@Override
public ProcessorManager getProcessorManager() {
return processorManager;
}
}
\ No newline at end of file
......@@ -4,9 +4,7 @@ import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.Map;
import java.util.Optional;
public class SimulationState {
......@@ -16,6 +14,7 @@ public class SimulationState {
private final int step;
private final String name;
private final MainModel mainModel;
private final ControllerProvider controllerProvider;
private boolean simStop = false;
protected SimulationState(final String name,
......@@ -23,24 +22,15 @@ public class SimulationState {
final ScenarioStore scenarioStore,
final double simTimeInSec,
final int step,
@Nullable final MainModel mainModel) {
@Nullable final MainModel mainModel,
final ControllerProvider controllerProvider) {
this.name = name;
this.topography = topography;
this.simTimeInSec = simTimeInSec;
this.step = step;
this.scenarioStore = scenarioStore;
this.mainModel = mainModel;
}
@Deprecated
public SimulationState(final Map<Integer, VPoint> pedestrianPositionMap, final Topography topography,
final double simTimeInSec, final int step) {
this.name = "";
this.topography = topography;
this.simTimeInSec = simTimeInSec;
this.step = step;
this.scenarioStore = null;
this.mainModel = null;
this.controllerProvider = controllerProvider;
}
// public access to getters
......@@ -57,6 +47,9 @@ public class SimulationState {
return step;
}
public ControllerProvider getControllerProvider() {
return controllerProvider;
}
public ScenarioStore getScenarioStore() {
return scenarioStore;
......
......@@ -8,6 +8,10 @@ import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.state.traci.CompoundObject;
import org.vadere.state.traci.CompoundObjectBuilder;
import org.vadere.state.traci.CompoundObjectProvider;
import org.vadere.state.traci.TraCIDataType;
/**
* @author Daniel Lehmberg
......@@ -20,7 +24,7 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
*/
@DataProcessorClass(label = "AreaDensityCountingProcessor")
public class AreaDensityCountingProcessor extends AreaDataProcessor<Integer> {
public class AreaDensityCountingProcessor extends AreaDataProcessor<Integer> implements CompoundObjectProvider {
public AreaDensityCountingProcessor() {
super("areaDensityCounting");
......@@ -55,4 +59,17 @@ public class AreaDensityCountingProcessor extends AreaDataProcessor<Integer> {
}
return super.getAttributes();
}
@Override
public CompoundObject provide(CompoundObjectBuilder builder) {
int lastValue = getValue(getLastKey());
int measurementAreaId = this.getMeasurementArea().getId();
return builder.rest()
.add(TraCIDataType.INTEGER) // measurementAreaId
.add(TraCIDataType.INTEGER) // timestep of count
.add(TraCIDataType.INTEGER) // countInId
.build(measurementAreaId,
getLastKey().getTimestep(),
lastValue);
}
}
......@@ -44,6 +44,7 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
private Map<K, V> data;
private int lastStep;
private K lastKey;
private boolean stopSimBeforeSimFinish;
......@@ -109,7 +110,12 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
return this.lastStep;
}
public K getLastKey() {
return lastKey;
}
protected void putValue(final K key, final V value) {
this.lastKey = key;
this.data.put(key, value);
}
......
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