Commit ccc498cf authored by Maxim Dudin's avatar Maxim Dudin
Browse files

sampling frequency made changeable over json

parent 7b5a4eb4
......@@ -43,8 +43,8 @@ public class PedestriansNearbyData {
return durationTimesteps;
}
public PedestriansNearbyData getDataWithIncrementedDuration() {
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + 1, getStartTimestep());
public PedestriansNearbyData getDataWithIncrementedDuration(int increment) {
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + increment, getStartTimestep());
}
......
......@@ -23,60 +23,65 @@ import java.util.stream.Collectors;
@DataProcessorClass()
public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestriansNearbyIdKey, PedestriansNearbyData> {
private double maxDistance; // todo adjustable with json
private double maxDistance; // todo adjustable with json
private int sampleEveryNthStep;
public PedestriansNearbyProcessor() {
super("durationTimesteps");
setAttributes(new AttributesPedestrianNearbyProcessor());
}
public PedestriansNearbyProcessor() {
super("durationTimesteps");
setAttributes(new AttributesPedestrianNearbyProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
int timeStep = state.getStep();
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 -> new PedestriansNearbyData(ped.getId(), p.getId(), 1, timeStep))
.collect(Collectors.toList());
pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPedId1(), o.getPedId2()), o));
}
}
@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 -> new PedestriansNearbyData(ped.getId(), p.getId(), sampleEveryNthStep, timeStep))
.collect(Collectors.toList());
pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPedId1(), o.getPedId2()), o));
}
}
public String[] toStrings(final TimestepPedestriansNearbyIdKey key) {
return this.hasValue(key) ? this.getValue(key).toStrings() : new String[]{"N/A", "N/A"};
}
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
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(sampleEveryNthStep));
return;
}
}
super.putValue(key, value);
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianNearbyProcessor att = (AttributesPedestrianNearbyProcessor) this.getAttributes();
maxDistance = att.getMaxDistanceForANearbyPedestrian();
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianNearbyProcessor att = (AttributesPedestrianNearbyProcessor) this.getAttributes();
maxDistance = att.getMaxDistanceForANearbyPedestrian();
sampleEveryNthStep = att.getSampleEveryNthStep();
}
private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) {
LinkedCellsGrid<DynamicElement> dynElements = topography.getSpatialMap(DynamicElement.class);
return dynElements.getObjects(sourcePosition, radius);
}
private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) {
LinkedCellsGrid<DynamicElement> dynElements = topography.getSpatialMap(DynamicElement.class);
return dynElements.getObjects(sourcePosition, radius);
}
}
......@@ -6,9 +6,14 @@ package org.vadere.state.attributes.processor;
*/
public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
private double maxDistanceForANearbyPedestrian = 1.5;
private double maxDistanceForANearbyPedestrian = 1.5;
private int sampleEveryNthStep = 1;
public double getMaxDistanceForANearbyPedestrian() {
return maxDistanceForANearbyPedestrian;
}
public int getSampleEveryNthStep() {
return sampleEveryNthStep;
}
}
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