Commit 7b5a4eb4 authored by Maxim Dudin's avatar Maxim Dudin
Browse files

max distance attribute made changeable over json

parent be5b5dad
Pipeline #237313 passed with stages
in 133 minutes and 15 seconds
......@@ -6,49 +6,50 @@ public class PedestriansNearbyData {
public static final PedestriansNearbyData noOverLap = new PedestriansNearbyData();
private final int ped1Id;
private final int ped2Id;
private final int durationTimesteps;
private final int pedId1;
private final int pedId2;
private int durationTimesteps;
private int startTimestep;
private PedestriansNearbyData() {
this.ped1Id = -1;
this.ped2Id = -1;
this.pedId1 = -1;
this.pedId2 = -1;
this.durationTimesteps = 1;
this.startTimestep = 1;
}
public int getStartTimestep() {
return startTimestep;
}
public PedestriansNearbyData(final DynamicElement ped1, final DynamicElement ped2, final int durationTimesteps){
this.ped1Id = ped1.getId();
this.ped2Id = ped2.getId();
public PedestriansNearbyData(int ped1, int ped2, final int durationTimesteps, int startTimestep){
this.pedId1 = Math.min(ped1, ped2);
this.pedId2 = Math.max(ped1, ped2);
this.durationTimesteps = durationTimesteps;
this.startTimestep = startTimestep;
}
/*public boolean isOverlap(){
return overlap > 0;
}*/
public int getPedId1() {
return pedId1;
}
/*public boolean isNotSelfOverlap(){
return !(ped1Id == ped2Id);
}*/
public int getPedId2() {
return pedId2;
}
public int getPed1Id() {
return ped1Id;
public int getDurationTimesteps() {
return durationTimesteps;
}
public int getPed2Id() {
return ped2Id;
public PedestriansNearbyData getDataWithIncrementedDuration() {
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + 1, getStartTimestep());
}
/*public Double getOverlap() {
return overlap;
}*/
public String[] toStrings(){
return new String[]{Integer.toString(durationTimesteps)};
}
/*public int maxDist(@NotNull PedestiansNearbyData o) {
return Double.compare(overlap, o.getOverlap());
}*/
}
......@@ -13,18 +13,14 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
private final int timeStep;
private final int pedId1; //smaller id
private final int pedId2; //bigger id
private final int durationTimesteps;
public TimestepPedestriansNearbyIdKey(int timeStep, int pedA, int pedB) {
this.timeStep = timeStep;
this.pedId1 = Math.min(pedA, pedB);
this.pedId2 = Math.max(pedA, pedB);
this.durationTimesteps = 1; //todo simulation step length
}
public double getDuration() {
return durationTimesteps;
}
public static String[] getHeaders(){
return new String[]{TimestepKey.getHeader(), PedestrianIdKey.getHeader(), "pedestrianNearbyId"};
......@@ -46,6 +42,19 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
return new String[]{Integer.toString(timeStep), Integer.toString(pedId1), Integer.toString(pedId2)};
}
public boolean isContinuationOf(PedestriansNearbyData other) {
return other.getPedId1() == getPedId1() &&
other.getPedId2() == getPedId2() &&
(other.getStartTimestep() + other.getDurationTimesteps() == getTimeStep());
}
public boolean isAccountedForBy(PedestriansNearbyData other) {
return equals(other) ||
(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);
......@@ -53,9 +62,6 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
result = Integer.compare(this.pedId1, o.pedId1);
if (result == 0){
result = Integer.compare(this.pedId2, o.pedId2);
if (result == 0) {
result = Integer.compare(this.durationTimesteps, o.durationTimesteps);
}
}
}
return result;
......@@ -67,15 +73,15 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
if (o == null || getClass() != o.getClass()) return false;
TimestepPedestriansNearbyIdKey that = (TimestepPedestriansNearbyIdKey) o;
return timeStep == that.timeStep &&
pedId1 == that.pedId1 &&
pedId2 == that.pedId2 &&
durationTimesteps == that.durationTimesteps;
((pedId1 == that.pedId1 &&
pedId2 == that.pedId2) || (pedId2 == that.pedId1 &&
pedId1 == that.pedId2));
}
@Override
public int hashCode() {
return Objects.hash(timeStep, pedId1, pedId2, durationTimesteps);
return Objects.hash(timeStep, pedId1, pedId2);
}
@Override
......@@ -84,7 +90,8 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
"timeStep=" + timeStep +
", pedId1=" + pedId1 +
", pedId2=" + pedId2 +
", durationTimesteps=" + durationTimesteps +
'}';
}
}
......@@ -4,8 +4,9 @@ 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.TimestepPedestrianIdOverlapKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestriansNearbyIdKey;
import org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor;
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;
......@@ -22,12 +23,12 @@ import java.util.stream.Collectors;
@DataProcessorClass()
public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestriansNearbyIdKey, PedestriansNearbyData> {
private double minDist;
private double maxDistance = 1.5;
private double maxDistance; // todo adjustable with json
public PedestriansNearbyProcessor() {
super("durationTimesteps");
setAttributes(new AttributesPedestrianNearbyProcessor());
}
@Override
......@@ -42,43 +43,35 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
List<PedestriansNearbyData> pedsNearby = dynElemNneighbours
.parallelStream()
.filter(p -> ped.getId() != p.getId())
.map(p -> new PedestriansNearbyData(ped, p, 1))
.map(p -> new PedestriansNearbyData(ped.getId(), p.getId(), 1, timeStep))
.collect(Collectors.toList());
pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPed1Id(), o.getPed2Id()), o));
pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPedId1(), o.getPedId2()), o));
}
/*double pedRadius = state.getTopography().getAttributesPedestrian().getRadius();
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
String mainModelstring =state.getScenarioStore().getMainModel();
if(mainModelstring != null && mainModelstring.equals(CellularAutomaton.class.getName())) {
minDist = pedRadius * 2 - SPAWN_BUFFER; // allow touching agents for Cellular Automaton
}else{
minDist = pedRadius * 2;
}
int timeStep = state.getStep();
for (Pedestrian ped : peds) {
// 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
List<OverlapData> overlaps = neighbours
.parallelStream()
.map(p -> new OverlapData(ped, p, minDist))
.filter(OverlapData::isNotSelfOverlap)
.filter(OverlapData::isOverlap)
.collect(Collectors.toList());
overlaps.forEach(o -> this.putValue(new TimestepPedestrianIdOverlapKey(timeStep, o.getPed1Id(), o.getPed2Id()), o));
}*/
}
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)) {
super.putValue(alreadyExisting, currentVal.getDataWithIncrementedDuration());
return;
}
}
super.putValue(key, value);
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianNearbyProcessor att = (AttributesPedestrianNearbyProcessor) this.getAttributes();
maxDistance = att.getMaxDistanceForANearbyPedestrian();
}
private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) {
......
package org.vadere.state.attributes.processor;
/**
* @author Maxim Dudin
*
*/
public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
private double maxDistanceForANearbyPedestrian = 1.5;
public double getMaxDistanceForANearbyPedestrian() {
return maxDistanceForANearbyPedestrian;
}
}
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