The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit 160c1b99 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Remove getPedestrianPositionMap Method from SimulationState

parent 3ebc518d
......@@ -3,18 +3,14 @@ package org.vadere.simulator.control;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.state.scenario.Car;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class SimulationState {
private final Topography topography;
private final Map<Integer, VPoint> pedestrianPositionMap;
private final double simTimeInSec;
private final ScenarioStore scenarioStore;
private final int step;
......@@ -26,31 +22,23 @@ public class SimulationState {
final ScenarioStore scenarioStore,
final double simTimeInSec,
final int step,
@Nullable final MainModel mainModel) {
@Nullable final MainModel mainModel) {
this.name = name;
this.topography = topography;
this.simTimeInSec = simTimeInSec;
this.step = step;
this.pedestrianPositionMap = new HashMap<>();
this.scenarioStore = scenarioStore;
this.mainModel = mainModel;
for (Pedestrian pedestrian : topography.getElements(Pedestrian.class)) {
pedestrianPositionMap.put(pedestrian.getId(), pedestrian.getPosition());
}
for (Car car : topography.getElements(Car.class)) {
pedestrianPositionMap.put(car.getId(), car.getPosition());
}
}
@Deprecated
public SimulationState(final Map<Integer, VPoint> pedestrianPositionMap, final Topography topography,
final double simTimeInSec, final int step) {
final double simTimeInSec, final int step) {
this.name = "";
this.topography = topography;
this.simTimeInSec = simTimeInSec;
this.step = step;
this.pedestrianPositionMap = pedestrianPositionMap;
this.scenarioStore = null;
this.mainModel = null;
}
......@@ -69,10 +57,6 @@ public class SimulationState {
return step;
}
@Deprecated
public Map<Integer, VPoint> getPedestrianPositionMap() {
return pedestrianPositionMap;
}
public ScenarioStore getScenarioStore() {
return scenarioStore;
......@@ -83,8 +67,8 @@ public class SimulationState {
}
/**
* Returns the main model of the simulation if it is an online simulation, otherwise the main model
* is unknown and therefore null.
* Returns the main model of the simulation if it is an online simulation, otherwise the main
* model is unknown and therefore null.
*
* @return online simulation => main model, otherwise null.
*/
......
......@@ -5,52 +5,51 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianWaitingEndTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Map;
import java.util.Collection;
/**
* @author Mario Teixeira Parente
*
*/
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
private VRectangle waitingArea;
public PedestrianWaitingEndTimeProcessor() {
super("waitingEndTime");
setAttributes(new AttributesPedestrianWaitingEndTimeProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
Map<Integer, VPoint> pedPosMap = state.getPedestrianPositionMap();
for (Map.Entry<Integer, VPoint> entry : pedPosMap.entrySet()) {
int pedId = entry.getKey();
VPoint pos = entry.getValue();
if (this.waitingArea.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, state.getSimTimeInSec());
}
}
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
this.waitingArea = att.getWaitingArea();
}
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesPedestrianWaitingEndTimeProcessor());
}
return super.getAttributes();
}
private VRectangle waitingArea;
public PedestrianWaitingEndTimeProcessor() {
super("waitingEndTime");
setAttributes(new AttributesPedestrianWaitingEndTimeProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
for (Pedestrian p : peds) {
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, state.getSimTimeInSec());
}
}
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
this.waitingArea = att.getWaitingArea();
}
@Override
public AttributesProcessor getAttributes() {
if (super.getAttributes() == null) {
setAttributes(new AttributesPedestrianWaitingEndTimeProcessor());
}
return super.getAttributes();
}
}
......@@ -5,59 +5,59 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianWaitingTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Map;
import java.util.Collection;
/**
* @author Mario Teixeira Parente
*
*/
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
private double lastSimTime;
private VRectangle waitingArea;
public PedestrianWaitingTimeProcessor() {
super("waitingTime");
setAttributes(new AttributesPedestrianWaitingTimeProcessor());
this.lastSimTime = 0.0;
}
@Override
protected void doUpdate(final SimulationState state) {
Map<Integer, VPoint> pedPosMap = state.getPedestrianPositionMap();
double dt = state.getSimTimeInSec() - this.lastSimTime;
for (Map.Entry<Integer, VPoint> entry : pedPosMap.entrySet()) {
int pedId = entry.getKey();
VPoint pos = entry.getValue();
if (this.waitingArea.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, (this.hasValue(key) ? this.getValue(key) : 0.0) + dt);
}
}
this.lastSimTime = state.getSimTimeInSec();
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
this.waitingArea = att.getWaitingArea();
this.lastSimTime = 0.0;
}
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesPedestrianWaitingTimeProcessor());
}
return super.getAttributes();
}
private double lastSimTime;
private VRectangle waitingArea;
public PedestrianWaitingTimeProcessor() {
super("waitingTime");
setAttributes(new AttributesPedestrianWaitingTimeProcessor());
this.lastSimTime = 0.0;
}
@Override
protected void doUpdate(final SimulationState state) {
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
double dt = state.getSimTimeInSec() - this.lastSimTime;
for (Pedestrian p : peds) {
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, (this.hasValue(key) ? this.getValue(key) : 0.0) + dt);
}
}
this.lastSimTime = state.getSimTimeInSec();
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
this.waitingArea = att.getWaitingArea();
this.lastSimTime = 0.0;
}
@Override
public AttributesProcessor getAttributes() {
if (super.getAttributes() == null) {
setAttributes(new AttributesPedestrianWaitingTimeProcessor());
}
return super.getAttributes();
}
}
......@@ -3,19 +3,19 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.tests.reflection.ReflectionHelper;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<PedestrianIdKey, Double> {
private PedestrianListBuilder b = new PedestrianListBuilder();
PedestrianWaitingTimeProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(PedestrianWaitingTimeProcessor.class);
testedProcessor.setId(nextProcessorId());
......@@ -28,23 +28,17 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
@Override
public void loadDefaultSimulationStateMocks(){
//VRectangle(0, 0, 2, 5)
public void loadDefaultSimulationStateMocks() {
/**
* Ped 1,2,3 start within WaitingArea and 4 never enters Area.
*/
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
pedPosMap.put(1, new VPoint(0.0, 1.0));
pedPosMap.put(2, new VPoint(1.0, 2.0));
pedPosMap.put(3, new VPoint(1.5, 3.0));
pedPosMap.put(4, new VPoint(0.0, 7.0)); //never inside
b.clear().add(1, new VPoint(0.0, 1.0));
b.add(2, new VPoint(1.0, 2.0));
b.add(3, new VPoint(1.5, 3.0));
b.add(4, new VPoint(0.0, 7.0)); //never inside
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getSimTimeInSec()).thenReturn(0.0);
addToExpectedOutput(new PedestrianIdKey(1), 0.0);
......@@ -57,13 +51,12 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
pedPosMap.put(1, new VPoint(0.5, 1.0));
pedPosMap.put(2, new VPoint(1.5, 2.0));
pedPosMap.put(3, new VPoint(2.1, 3.0)); //leave area
pedPosMap.put(4, new VPoint(0.5, 7.0)); //never inside
b.clear().add(1, new VPoint(0.5, 1.0));
b.add(2, new VPoint(1.5, 2.0));
b.add(3, new VPoint(2.1, 3.0)); //leave area
b.add(4, new VPoint(0.5, 7.0)); //never inside
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getSimTimeInSec()).thenReturn(0.8);
addToExpectedOutput(new PedestrianIdKey(1), 0.8);
......@@ -74,13 +67,12 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
pedPosMap.put(1, new VPoint(1.0, 1.0));
pedPosMap.put(2, new VPoint(2.2, 2.0)); //leave area
pedPosMap.put(3, new VPoint(2.8, 3.0));
pedPosMap.put(4, new VPoint(1.5, 7.0)); //never inside
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(2.2, 2.0)); //leave area
b.add(3, new VPoint(2.8, 3.0));
b.add(4, new VPoint(1.5, 7.0)); //never inside
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getSimTimeInSec()).thenReturn(1.7);
addToExpectedOutput(new PedestrianIdKey(1), 1.7);
......@@ -90,13 +82,12 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
addSimState(new SimulationStateMock(4) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
pedPosMap.put(1, new VPoint(2.1, 1.0)); //leave area
pedPosMap.put(2, new VPoint(3.2, 2.0));
pedPosMap.put(3, new VPoint(3.8, 3.0));
pedPosMap.put(4, new VPoint(5.5, 7.0)); //never inside
b.clear().add(1, new VPoint(2.1, 1.0)); //leave area
b.add(2, new VPoint(3.2, 2.0));
b.add(3, new VPoint(3.8, 3.0));
b.add(4, new VPoint(5.5, 7.0)); //never inside
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getSimTimeInSec()).thenReturn(3.6);
}
});
......
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