Commit c708976e authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Merge branch 'develop' of gitlab.lrz.de:vadere/vadere into develop

parents 522ff377 46915268
Pipeline #67801 passed with stages
in 58 minutes and 41 seconds
package org.vadere.simulator.projects.dataprocessing;
import org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore;
import org.vadere.simulator.projects.dataprocessing.store.OutputDefinitionStore;
import org.vadere.simulator.projects.dataprocessing.store.OutputFileStore;
import org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore;
import org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor;
import java.util.Arrays;
......@@ -12,40 +13,73 @@ import java.util.Arrays;
*/
public final class OutputPresets {
private static OutputPresets instance;
private final OutputDefinitionStore outputDefinition;
private OutputPresets() {
this.outputDefinition = new OutputDefinitionStore();
// private final DataProcessorFactory dataProcessorFactory;
// private final OutputFileFactory outputFileFactory;
public OutputPresets(){
// dataProcessorFactory = DataProcessorFactory.instance();
// outputFileFactory = OutputFileFactory.instance();
}
public OutputDefinitionStore buildDefault() {
OutputDefinitionStore defaultPreset = new OutputDefinitionStore();
DataProcessorStore processor1 = new DataProcessorStore();
processor1.setType("org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor");
processor1.setId(1);
this.outputDefinition.addProcessor(processor1);
defaultPreset.addProcessor(processor1);
DataProcessorStore processor2 = new DataProcessorStore();
processor2.setType("org.vadere.simulator.projects.dataprocessing.processor.PedestrianTargetIdProcessor");
processor2.setId(2);
this.outputDefinition.addProcessor(processor2);
defaultPreset.addProcessor(processor2);
OutputFileStore outputFile = new OutputFileStore();
outputFile.setType("org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile");
outputFile.setFilename(DataProcessingJsonManager.TRAJECTORIES_FILENAME);
outputFile.setProcessors(Arrays.asList(1, 2));
this.outputDefinition.addOutputFile(outputFile);
defaultPreset.addOutputFile(outputFile);
this.outputDefinition.setTimestamped(true);
}
defaultPreset.setTimestamped(true);
public static OutputDefinitionStore getOutputDefinition() {
return getInstance().outputDefinition;
return defaultPreset;
}
public static OutputPresets getInstance() {
if (instance == null) {
instance = new OutputPresets();
}
public OutputDefinitionStore withOverlapProcessor(){
OutputDefinitionStore store = buildDefault();
DataProcessorStore processor3 = new DataProcessorStore();
processor3.setType("org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor");
processor3.setId(3);
store.addProcessor(processor3);
return instance;
DataProcessorStore processor4 = new DataProcessorStore();
AttributesNumberOverlapsProcessor attr4 = new AttributesNumberOverlapsProcessor();
attr4.setPedestrianOverlapProcessorId(3);
processor4.setType("org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor");
processor4.setId(4);
processor4.setAttributesType("org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor");
processor4.setAttributes(attr4);
store.addProcessor(processor4);
OutputFileStore outputFilePedOverlap = new OutputFileStore();
outputFilePedOverlap.setType("org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile");
outputFilePedOverlap.setFilename("overlaps.csv");
outputFilePedOverlap.setProcessors(Arrays.asList(3));
store.addOutputFile(outputFilePedOverlap);
OutputFileStore outputFileOverlapCount = new OutputFileStore();
outputFileOverlapCount.setType("org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile");
outputFileOverlapCount.setFilename("overlapCount.txt");
outputFileOverlapCount.setProcessors(Arrays.asList(4));
store.addOutputFile(outputFileOverlapCount);
return store;
}
// create default Scenario File with overlap processors added automatically.
public static OutputDefinitionStore getOutputDefinition() {
return new OutputPresets().withOverlapProcessor();
}
}
......@@ -6,20 +6,20 @@ import org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestria
import java.util.Objects;
@OutputFileMap(outputFileClass = TimestepPedestrianIdOverlapOutputFile.class)
public class TimestepPedestrianIdOverlap implements DataKey<TimestepPedestrianIdOverlap> {
public class TimestepPedestrianIdOverlapKey implements DataKey<TimestepPedestrianIdOverlapKey> {
private final int timeStep;
private final int pedId1;
private final int pedId2;
public TimestepPedestrianIdOverlap(int timeStep, int pedId1, int pedId2) {
public TimestepPedestrianIdOverlapKey(int timeStep, int pedId1, int pedId2) {
this.timeStep = timeStep;
this.pedId1 = pedId1;
this.pedId2 = pedId2;
}
public static String[] getHeaders(){
return new String[]{TimestepKey.getHeader(), PedestrianIdKey.getHeader(), "overlapedWithPedestrianId"};
return new String[]{TimestepKey.getHeader(), PedestrianIdKey.getHeader(), "overlapPedestrianId"};
}
public int getTimeStep() {
......@@ -39,7 +39,7 @@ public class TimestepPedestrianIdOverlap implements DataKey<TimestepPedestrianId
}
@Override
public int compareTo(@NotNull TimestepPedestrianIdOverlap o) {
public int compareTo(@NotNull TimestepPedestrianIdOverlapKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
result = Integer.compare(this.pedId1, o.pedId1);
......@@ -54,7 +54,7 @@ public class TimestepPedestrianIdOverlap implements DataKey<TimestepPedestrianId
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TimestepPedestrianIdOverlap that = (TimestepPedestrianIdOverlap) o;
TimestepPedestrianIdOverlapKey that = (TimestepPedestrianIdOverlapKey) o;
return timeStep == that.timeStep &&
pedId1 == that.pedId1 &&
pedId2 == that.pedId2;
......@@ -68,7 +68,7 @@ public class TimestepPedestrianIdOverlap implements DataKey<TimestepPedestrianId
@Override
public String toString() {
return "TimestepPedestrianIdOverlap{" +
return "TimestepPedestrianIdOverlapKey{" +
"timeStep=" + timeStep +
", pedId1=" + pedId1 +
", pedId2=" + pedId2 +
......
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.annotation.factories.outputfiles.OutputFileClass;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlap;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlapKey;
@OutputFileClass(dataKeyMapping = TimestepPedestrianIdOverlap.class)
public class TimestepPedestrianIdOverlapOutputFile extends OutputFile<TimestepPedestrianIdOverlap>{
@OutputFileClass(dataKeyMapping = TimestepPedestrianIdOverlapKey.class)
public class TimestepPedestrianIdOverlapOutputFile extends OutputFile<TimestepPedestrianIdOverlapKey>{
public TimestepPedestrianIdOverlapOutputFile() {
super(TimestepPedestrianIdOverlap.getHeaders());
super(TimestepPedestrianIdOverlapKey.getHeaders());
}
@Override
public String[] toStrings(final TimestepPedestrianIdOverlap key){
public String[] toStrings(final TimestepPedestrianIdOverlapKey key){
return key.toStrings();
}
}
......@@ -5,12 +5,9 @@ import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.NoDataKey;
import org.vadere.state.attributes.processor.AttributesMaxOverlapProcessor;
import org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import javax.swing.*;
import java.util.OptionalDouble;
import java.util.OptionalInt;
/**
* This processor saves the largest overlap (2*pedRadius - distance between the pedestrian's centers) for one simulation.
......@@ -68,7 +65,7 @@ public class MaxOverlapProcessor extends DataProcessor<NoDataKey, Double> {
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesMaxOverlapProcessor att = (AttributesMaxOverlapProcessor) this.getAttributes();
this.pedOverlapProc = (PedestrianOverlapDistProcessor) manager.getProcessor(att.getPedestrianMaxOverlapProcessorId());
this.pedOverlapProc = (PedestrianOverlapDistProcessor) manager.getProcessor(att.getPedestrianOverlapDistProcessorId());
}
......
......@@ -4,7 +4,7 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.OverlapData;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlap;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlapKey;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -18,8 +18,9 @@ import java.util.stream.Collectors;
/**
* @author Mario Teixeira Parente
*/
@DataProcessorClass()
public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrianIdOverlap, OverlapData> {
public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrianIdOverlapKey, OverlapData> {
private double minDist;
......@@ -34,8 +35,8 @@ public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrian
minDist = pedRadius * 2;
int timeStep = state.getStep();
for (Pedestrian ped : peds) {
// get all Pedestrians with at moust pedRadius*2.5 distance away
// this reduces the amount auf overlap test.
// get all Pedestrians with at most pedRadius*2.5 distance away
// this reduces the amount of overlap tests
VPoint pedPos = ped.getPosition();
List<DynamicElement> neighbours = getDynElementsAtPosition(state.getTopography(), ped.getPosition(), pedRadius *2.5);
// collect pedIds and distance of all overlaps for the current ped in the current timestep
......@@ -45,11 +46,11 @@ public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrian
.filter(OverlapData::isNotSelfOverlap)
.filter(OverlapData::isOverlap)
.collect(Collectors.toList());
overlaps.forEach(o -> this.putValue(new TimestepPedestrianIdOverlap(timeStep, o.getPed1Id(), o.getPed2Id()), o));
overlaps.forEach(o -> this.putValue(new TimestepPedestrianIdOverlapKey(timeStep, o.getPed1Id(), o.getPed2Id()), o));
}
}
public String[] toStrings(final TimestepPedestrianIdOverlap key) {
public String[] toStrings(final TimestepPedestrianIdOverlapKey key) {
return this.hasValue(key) ? this.getValue(key).toStrings() : new String[]{"N/A", "N/A"};
}
......
......@@ -34,7 +34,6 @@ public class PedestrianOverlapProcessorTest extends ProcessorTest {
}
@Test
@Ignore
public void doUpdateWithTouching() throws Exception {
((PedestrianOverlapProcessorTestEnv)processorTestEnv).touching();
super.doUpdate();
......
......@@ -2,7 +2,7 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.OverlapData;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlap;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlapKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.DynamicElement;
......@@ -10,16 +10,17 @@ import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.LinkedCellsGrid;
import org.vadere.util.geometry.shapes.VPoint;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import static org.mockito.ArgumentMatchers.doubleThat;
import static org.mockito.Mockito.mock;
public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdOverlap, OverlapData> {
public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdOverlapKey, OverlapData> {
private PedestrianListBuilder b = new PedestrianListBuilder();
......@@ -33,7 +34,7 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
try {
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
TimestepPedestrianIdOverlap.class,
TimestepPedestrianIdOverlapKey.class,
testedProcessor.getId());
} catch (ClassNotFoundException e) {
e.printStackTrace();
......@@ -80,10 +81,10 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
Mockito.when(state.getTopography().getAttributesPedestrian().getRadius()).thenReturn(0.195);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 5), b.overlapData(1,5,minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 5, 1), b.overlapData(5,1,minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 3), b.overlapData(1,3,minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 1), b.overlapData(3,1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 1, 5), b.overlapData(1,5,minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 5, 1), b.overlapData(5,1,minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 1, 3), b.overlapData(1,3,minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 3, 1), b.overlapData(3,1, minDist));
}
});
......@@ -99,21 +100,21 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
Mockito.when(state.getTopography().getAttributesPedestrian().getRadius()).thenReturn(0.195);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 2), b.overlapData(1, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 3), b.overlapData(1, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 4), b.overlapData(1, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 1, 2), b.overlapData(1, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 1, 3), b.overlapData(1, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 1, 4), b.overlapData(1, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 1), b.overlapData(2, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 3), b.overlapData(2, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 4), b.overlapData(2, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 2, 1), b.overlapData(2, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 2, 3), b.overlapData(2, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 2, 4), b.overlapData(2, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 1), b.overlapData(3, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 2), b.overlapData(3, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 4), b.overlapData(3, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 3, 1), b.overlapData(3, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 3, 2), b.overlapData(3, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 3, 4), b.overlapData(3, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 1), b.overlapData(4, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 2), b.overlapData(4, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 3), b.overlapData(4, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 4, 1), b.overlapData(4, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 4, 2), b.overlapData(4, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 4, 3), b.overlapData(4, 3, minDist));
}
});
}
......@@ -125,29 +126,39 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
addMockStates(a.getRadius(), distAtAxis, new VPoint(vertDistAt45deg, vertDistAt45deg));
double minDist = 0.195*2;
int step = 1;
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 2), b.overlapData(1, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 1), b.overlapData(2, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 4), b.overlapData(3, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 3), b.overlapData(4, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 5, 6), b.overlapData(5, 6, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 6, 5), b.overlapData(6, 5, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 1, 2), b.overlapData(1, 2, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 2, 1), b.overlapData(2, 1, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 3, 4), b.overlapData(3, 4, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 4, 3), b.overlapData(4, 3, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 5, 6), b.overlapData(5, 6, minDist));
addToExpectedOutput(new TimestepPedestrianIdOverlapKey(step, 6, 5), b.overlapData(6, 5, minDist));
}
void verySmallNotOverlapping() {
AttributesAgent a = new AttributesAgent();
double distAtAxis = a.getRadius()*2 + 0.001; // this should count as overlap
double vertDistAt45deg = 2*Math.sqrt(0.5)*a.getRadius() + 0.001;
double vertDistAt45deg = Math.sqrt(2)*a.getRadius() + 0.001;
addMockStates(a.getRadius(), distAtAxis, new VPoint(vertDistAt45deg, vertDistAt45deg));
}
void touching() {
AttributesAgent a = new AttributesAgent();
double distAtAxis = a.getRadius()*2; // this should count as overlap
double vertDistAt45deg = 2*Math.sqrt(0.5)*a.getRadius();
double vertDistAt45deg = round(Math.sqrt(2)*a.getRadius(), 16);
addMockStates(a.getRadius(), distAtAxis, new VPoint(vertDistAt45deg, vertDistAt45deg));
}
public static double round(double val, int places){
if(places < 0)
throw new IllegalArgumentException();
BigDecimal bigDecimal = new BigDecimal(val);
bigDecimal = bigDecimal.setScale(places, RoundingMode.HALF_UP);
return bigDecimal.doubleValue();
}
private void addMockStates(double radius, double distAtAxis, VPoint vertDistAt45deg) {
clearStates();
addSimState(new SimulationStateMock(1) {
......
......@@ -6,14 +6,14 @@ package org.vadere.state.attributes.processor;
*/
public class AttributesMaxOverlapProcessor extends AttributesProcessor {
private int pedestrianMaxOverlapProcessorId;
private int pedestrianOverlapDistProcessorId;
public int getPedestrianMaxOverlapProcessorId() {
return this.pedestrianMaxOverlapProcessorId;
public int getPedestrianOverlapDistProcessorId() {
return this.pedestrianOverlapDistProcessorId;
}
public void getPedestrianMaxOverlapProcessorId(int pedestrianMaxOverlapProcessorId) {
public void getPedestrianOverlapDistProcessorId(int pedestrianOverlapDistProcessorId) {
checkSealed();
this.pedestrianMaxOverlapProcessorId = pedestrianMaxOverlapProcessorId;
this.pedestrianOverlapDistProcessorId = pedestrianOverlapDistProcessorId;
}
}
Supports Markdown
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