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 3ebc518d authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Remove call to SimulationState::getPedestrianPositionMap

parent fb2f71e7
......@@ -5,48 +5,49 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.Map;
import java.util.Collection;
/**
* @author Mario Teixeira Parente
*
*/
public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrianIdKey, Integer> {
private double pedRadius;
public PedestrianOverlapProcessor() {
super("overlaps");
setAttributes(new AttributesPedestrianOverlapProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
Map<Integer, VPoint> pedPosMap = state.getPedestrianPositionMap();
pedPosMap.entrySet().forEach(entry -> this.putValue(new TimestepPedestrianIdKey(state.getStep(), entry.getKey()), this.calculateOverlaps(pedPosMap, entry.getValue())));
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianOverlapProcessor att = (AttributesPedestrianOverlapProcessor) this.getAttributes();
this.pedRadius = att.getPedRadius();
}
private int calculateOverlaps(final Map<Integer, VPoint> pedPosMap, VPoint pos) {
return (int) pedPosMap.values().stream().filter(pedPos -> pedPos.distance(pos) < 2*this.pedRadius).count() -1;
}
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesPedestrianOverlapProcessor());
}
return super.getAttributes();
}
private double pedRadius;
public PedestrianOverlapProcessor() {
super("overlaps");
setAttributes(new AttributesPedestrianOverlapProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
peds.forEach(p -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), p.getId()),
this.calculateOverlaps(peds, p.getPosition())));
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianOverlapProcessor att = (AttributesPedestrianOverlapProcessor) this.getAttributes();
this.pedRadius = att.getPedRadius();
}
private int calculateOverlaps(final Collection<Pedestrian> peds, VPoint pos) {
return (int) peds.stream().filter(p -> p.getPosition().distance(pos) < 2 * this.pedRadius).count() - 1;
}
@Override
public AttributesProcessor getAttributes() {
if (super.getAttributes() == null) {
setAttributes(new AttributesPedestrianOverlapProcessor());
}
return super.getAttributes();
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.writer.VadereStringWriter;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereStringWriterFactory;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
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 PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdKey, Integer> {
PedestrianOverlapProcessorTestEnv(){
private PedestrianListBuilder b = new PedestrianListBuilder();
PedestrianOverlapProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(PedestrianOverlapProcessor.class);
testedProcessor.setId(nextProcessorId());
......@@ -31,12 +31,11 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
pedPosMap.put(1, new VPoint(1.0, 1.0));
pedPosMap.put(2, new VPoint(1.5, 1.5));
pedPosMap.put(3, new VPoint(1.5, 1.0));
pedPosMap.put(4, new VPoint(1.0, 1.5));
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(1.5, 1.5));
b.add(3, new VPoint(1.5, 1.0));
b.add(4, new VPoint(1.0, 1.5));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 0);
......@@ -49,13 +48,13 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
pedPosMap.put(1, new VPoint(1.0, 1.0));
pedPosMap.put(2, new VPoint(1.5, 1.5));
pedPosMap.put(3, new VPoint(1.2, 1.0));
pedPosMap.put(4, new VPoint(1.0, 1.5));
pedPosMap.put(5, new VPoint(0.8, 0.8));
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(1.5, 1.5));
b.add(3, new VPoint(1.2, 1.0));
b.add(4, new VPoint(1.0, 1.5));
b.add(5, new VPoint(0.8, 0.8));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 2);
......@@ -69,12 +68,11 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
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(1.0, 1.0));
pedPosMap.put(3, new VPoint(1.0, 1.0));
pedPosMap.put(4, new VPoint(1.0, 1.0));
Mockito.when(state.getPedestrianPositionMap()).thenReturn(pedPosMap);
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(1.0, 1.0));
b.add(3, new VPoint(1.0, 1.0));
b.add(4, new VPoint(1.0, 1.0));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 3);
......
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