Commit 2a7c0440 authored by Christina's avatar Christina
Browse files

Merge branch 'target_changer_prob_list_MD' into target_changer_prob_list

parents f974cc46 8191387b
Pipeline #250094 passed with stages
in 145 minutes and 57 seconds
......@@ -15,6 +15,10 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "overlapCount.txt",
"processors" : [ 4 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestriansNearbyIdOutputFile",
"filename" : "pedsNearby.txt",
"processors" : [ 8 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
......@@ -32,6 +36,9 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepTargetIDProcessor",
"id" : 6
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestriansNearbyProcessor",
"id" : 8
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......
......@@ -15,6 +15,10 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "overlapCount.txt",
"processors" : [ 4 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestriansNearbyIdOutputFile",
"filename" : "pedsNearby.txt",
"processors" : [ 5 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepProcessor",
......@@ -32,6 +36,18 @@
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestriansNearbyProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianNearbyProcessor",
"attributes" : {
"maxDistanceForANearbyPedestrian" : 1.5,
"sampleEveryNthStep" : 1,
"allowedAbsenceTimestepsIfContactReturns" : 0,
"minTimespanOfContactTimesteps" : 20,
"printContactTrajectories" : false,
"printForPostVis" : true
}
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......@@ -2085,6 +2101,23 @@
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 9999,
"absorbing" : true,
"shape" : {
"x" : 23.5,
"y" : 25.5,
"width" : 1.5,
"height" : 0.5,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ {
"id" : 6,
......
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class PedestriansNearbyData {
private final int pedId1;
private final int pedId2;
private int durationTimesteps;
private int startTimestep;
private List<VPoint> trajectory;
private boolean printTrajectory;
private boolean printForPostVis; // is an ugly one time thing that shouldn't be merged
/*private PedestriansNearbyData() {
this.pedId1 = -1;
this.pedId2 = -1;
this.durationTimesteps = 1;
this.startTimestep = 1;
this.trajectory = new ArrayList<>();
}*/
public int getStartTimestep() {
return startTimestep;
}
public PedestriansNearbyData(int ped1, int ped2, final int durationTimesteps, int startTimestep, List<VPoint> contactTrajectory, boolean printTrajectory, boolean printForPostVis){
this.pedId1 = Math.min(ped1, ped2);
this.pedId2 = Math.max(ped1, ped2);
this.durationTimesteps = durationTimesteps;
this.startTimestep = startTimestep;
this.trajectory = contactTrajectory;
this.printTrajectory = printTrajectory;
this.printForPostVis = printForPostVis;
}
public int getPedId1() {
return pedId1;
}
public int getPedId2() {
return pedId2;
}
public int getDurationTimesteps() {
return durationTimesteps;
}
public boolean isPrintForPostVis() {
return printForPostVis;
}
public List<VPoint> getTrajectory() {
return trajectory;
}
public void addToContactTrajectory(VPoint point) {
trajectory.add(point);
}
public void addToContactTrajectory(List<VPoint> points) {
trajectory.addAll(points);
}
public PedestriansNearbyData getUpdatedData(PedestriansNearbyData newData, int sampleEveryNthStep) {
List<VPoint> traj = getTrajectory();
traj.addAll(newData.getTrajectory());
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + sampleEveryNthStep, getStartTimestep(),traj, printTrajectory, printForPostVis);
}
public String[] toStrings(){
// printForPostVis is an ugly one time thing that shouldn't be merged
if (printForPostVis) {
StringBuilder ret = new StringBuilder();
List<VPoint> traj = getTrajectory();
for (int i = 0; i < traj.size(); i++) {
VPoint p = traj.get(i);
VPoint pNext;
if (i != traj.size() -1) {
pNext = traj.get(i + 1);
} else {
pNext = traj.get(i);
}
Random rand = new Random();
double r1 = rand.nextDouble();
r1 = r1*0.3 - 0.15;
double r2 = rand.nextDouble();
r2 = r2*0.3 - 0.15;
ret.append(hashCode()).append(" ").append(startTimestep*0.4 + i*0.4).append(" ").append(startTimestep*0.4 + (i+1)*0.4).append(" ").append(p.x + r2).append(" ").append(p.y + r1).append(" ").append(pNext.x + r1).append(" ").append(pNext.y + r2).append(" 9999");
if (i != traj.size() -1) {
ret.append("\n");
}
}
return new String[]{ret.toString()};
}
if (!printTrajectory) {
return new String[]{Integer.toString(durationTimesteps)};
}
StringBuilder ret = new StringBuilder();
List<VPoint> traj = getTrajectory();
for (int i = 0; i < traj.size(); i++) {
VPoint p = traj.get(i);
ret.append(p.x).append(" ").append(p.y).append("\n");
if (i != traj.size() -1) {
ret.append("- - - - ");
}
}
return new String[]{Integer.toString(durationTimesteps), ret.toString()};
}
}
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile;
import org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestriansNearbyIdOutputFile;
import org.vadere.state.attributes.AttributesSimulation;
import java.util.Objects;
@OutputFileMap(outputFileClass = TimestepPedestriansNearbyIdOutputFile.class)
public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestriansNearbyIdKey> {
private final int timeStep;
private final int pedId1; //smaller id
private final int pedId2; //bigger id
private final boolean printForPostVis;
public TimestepPedestriansNearbyIdKey(int timeStep, int pedA, int pedB, boolean printForPostVis) {
this.timeStep = timeStep;
this.pedId1 = Math.min(pedA, pedB);
this.pedId2 = Math.max(pedA, pedB);
this.printForPostVis = printForPostVis; // is an ugly one time thing that shouldn't be merged
}
public static String[] getHeaders(){
return new String[]{TimestepKey.getHeader(), PedestrianIdKey.getHeader(), "pedestrianNearbyId"};
}
public int getTimeStep() {
return timeStep;
}
public int getPedId1() {
return pedId1;
}
public int getPedId2() {
return pedId2;
}
public String[] toStrings(){
// printForPostVis is an ugly one time thing that shouldn't be merged
if (printForPostVis) {
//return new String[]{Integer.toString(999), Double.toString(timeStep*0.4), Double.toString(timeStep*0.4 + 0.4)};
return new String[]{};
}
return new String[]{Integer.toString(timeStep), Integer.toString(pedId1), Integer.toString(pedId2)};
}
public boolean isContinuationOf(PedestriansNearbyData other, int toleranceTimesteps) {
return other.getPedId1() == getPedId1() &&
other.getPedId2() == getPedId2() &&
(other.getStartTimestep() + other.getDurationTimesteps() <= getTimeStep()) &&
(other.getStartTimestep() + other.getDurationTimesteps() + toleranceTimesteps >= getTimeStep());
}
public boolean isAccountedForBy(PedestriansNearbyData other) {
return (other.getPedId1() == getPedId1() &&
other.getPedId2() == getPedId2() &&
getTimeStep() >= other.getStartTimestep() &&
getTimeStep() < other.getStartTimestep() + other.getDurationTimesteps());
}
@Override
public int compareTo(@NotNull TimestepPedestriansNearbyIdKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
result = Integer.compare(this.pedId1, o.pedId1);
if (result == 0){
result = Integer.compare(this.pedId2, o.pedId2);
}
}
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TimestepPedestriansNearbyIdKey that = (TimestepPedestriansNearbyIdKey) o;
return timeStep == that.timeStep &&
((pedId1 == that.pedId1 &&
pedId2 == that.pedId2) || (pedId2 == that.pedId1 &&
pedId1 == that.pedId2));
}
@Override
public int hashCode() {
return Objects.hash(timeStep, pedId1, pedId2);
}
@Override
public String toString() {
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.TimestepPedestrianIdOverlapKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestriansNearbyIdKey;
@OutputFileClass(dataKeyMapping = TimestepPedestriansNearbyIdKey.class)
public class TimestepPedestriansNearbyIdOutputFile extends OutputFile<TimestepPedestriansNearbyIdKey>{
public TimestepPedestriansNearbyIdOutputFile() {
super(TimestepPedestriansNearbyIdKey.getHeaders());
}
@Override
public String[] toStrings(final TimestepPedestriansNearbyIdKey key){
return key.toStrings();
}
}
......@@ -105,6 +105,10 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
this.data.put(key, value);
}
protected void removeKey(final K key) {
this.data.remove(key);
}
public void preLoop(final SimulationState state) { data.clear(); }
protected abstract void doUpdate(final SimulationState state);
......
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.PedestriansNearbyData;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestriansNearbyIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianNearbyProcessor;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.LinkedCellsGrid;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Maxim Dudin
*/
@DataProcessorClass()
public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestriansNearbyIdKey, PedestriansNearbyData> {
private double maxDistance; // todo adjustable with json
private int sampleEveryNthStep;
private int allowedAbsenceTimestepsIfContactReturns;
private int minTimespanOfContactTimesteps;
private boolean printContacTrajectories;
private boolean printForPostVis;
public PedestriansNearbyProcessor() {
super("durationTimesteps", "xCoord-Contact", "yCoord-Contact");
setAttributes(new AttributesPedestrianNearbyProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
int timeStep = state.getStep();
if (timeStep % sampleEveryNthStep != 0) {
return;
}
for (Pedestrian ped : peds) {
// get all Pedestrians with at most maxDistance away
// this reduces the amount of overlap tests
VPoint pedPos = ped.getPosition();
List<DynamicElement> dynElemNneighbours = getDynElementsAtPosition(state.getTopography(), ped.getPosition(), maxDistance);
List<PedestriansNearbyData> pedsNearby = dynElemNneighbours
.parallelStream()
.filter(p -> ped.getId() != p.getId())
.map(p -> {
double xAverage = (ped.getPosition().getX() + p.getPosition().getX())/2.;
double yAverage = (ped.getPosition().getY() + p.getPosition().getY())/2.;
//System.out.println("x1= " + ped.getPosition().getX() + "y1= " + ped.getPosition().getY() + "x2= " + p.getPosition().getX() + "y2= " + p.getPosition().getY() + "xAver= " + xAverage + "yAver= " + yAverage);
//System.out.println("x1= " + ped.getPosition().getX() + "y1= " + ped.getPosition().getY() + "x2= " + p.getPosition().getX() + "y2= " + p.getPosition().getY() + "xAver= " + xAverage + "yAver= " + yAverage);
VPoint pointOfContact = new VPoint(xAverage, yAverage);
List<VPoint> trajectory = new ArrayList<>();
trajectory.add(pointOfContact);
return new PedestriansNearbyData(ped.getId(), p.getId(), sampleEveryNthStep, timeStep, trajectory, printContacTrajectories, printForPostVis);})
.collect(Collectors.toList());
pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPedId1(), o.getPedId2(), printForPostVis), o));
}
}
@Override
public void postLoop(final SimulationState state) {
List<TimestepPedestriansNearbyIdKey> toBeRemoved = new ArrayList<>();
for (TimestepPedestriansNearbyIdKey key : getKeys()) {
if (getValue(key).getDurationTimesteps() < minTimespanOfContactTimesteps) {
toBeRemoved.add(key);
}
}
for (TimestepPedestriansNearbyIdKey toRemove: toBeRemoved) {
removeKey(toRemove);
}
}
public String[] toStrings(final TimestepPedestriansNearbyIdKey key) {
return this.hasValue(key) ? this.getValue(key).toStrings() : new String[]{"N/A", "N/A"};
}
@Override
protected void putValue(final TimestepPedestriansNearbyIdKey key, final PedestriansNearbyData value) {
for (TimestepPedestriansNearbyIdKey alreadyExisting : getKeys()) {
PedestriansNearbyData currentVal = getValue(alreadyExisting);
if (key.isAccountedForBy(currentVal)) {
return;
} else if (key.isContinuationOf(currentVal, allowedAbsenceTimestepsIfContactReturns)) {
super.putValue(alreadyExisting, currentVal.getUpdatedData(value, sampleEveryNthStep));
return;
}
}
super.putValue(key, value);
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianNearbyProcessor att = (AttributesPedestrianNearbyProcessor) this.getAttributes();
maxDistance = att.getMaxDistanceForANearbyPedestrian();
sampleEveryNthStep = att.getSampleEveryNthStep();
allowedAbsenceTimestepsIfContactReturns = att.getAllowedAbsenceTimestepsIfContactReturns();
minTimespanOfContactTimesteps = att.getMinTimespanOfContactTimesteps();
printContacTrajectories = att.getPrintContactTrajectories();
printForPostVis = att.getPrintForPostVis();
}
private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) {
LinkedCellsGrid<DynamicElement> dynElements = topography.getSpatialMap(DynamicElement.class);
return dynElements.getObjects(sourcePosition, radius);
}
}
package org.vadere.state.attributes.processor;
/**
* @author Maxim Dudin
*
*/
public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
private double maxDistanceForANearbyPedestrian = 1.5;
private int sampleEveryNthStep = 1;
private int allowedAbsenceTimestepsIfContactReturns = 0;
private int minTimespanOfContactTimesteps = 1;
private boolean printContactTrajectories = false;
private boolean printForPostVis = false;
public double getMaxDistanceForANearbyPedestrian() {
return maxDistanceForANearbyPedestrian;
}
public int getSampleEveryNthStep() {
return sampleEveryNthStep;
}
public int getAllowedAbsenceTimestepsIfContactReturns() {
return allowedAbsenceTimestepsIfContactReturns;
}
public int getMinTimespanOfContactTimesteps() {
return minTimespanOfContactTimesteps;
}
public boolean getPrintContactTrajectories() {
return printContactTrajectories;
}
public boolean getPrintForPostVis() {
return printForPostVis;
}
}
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