24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 8028c523 authored by Marion Goedel's avatar Marion Goedel

Added two new processor:

- PedestrianOverlapDistProcessor
  Saves for each pedestrian in each timestep the size of the overlap. That is the difference between the radii of the pedestrians and the distance between their centers. The processors works only if all pedestrians in the simulation have the same radius!
- MaxOverlapProcessor
  Saves the maximum overlap for one simulation. As explained above, the overlap is 2*pedRadius - norm(ped_pos_i - ped_pos_j). Again, this processor only works if all pedestrians in the simulation have the same radius.

Both processors are especially useful for analyzing the number and sizes of overlaps occuring in the simulation. Both processors were tested with a Matlab script but there are no JUnit tests yet.
parent 63ea3395
Pipeline #65687 failed with stages
in 43 minutes and 57 seconds
package org.vadere.simulator.projects.dataprocessing.processor;
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.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.
* The processor depends on the PedestrianOverlapDistProcessor. It only works if all pedestrians in the simulation have
* the same radius.
*
* @author Marion Gödel
*/
@DataProcessorClass()
public class MaxOverlapProcessor extends DataProcessor<NoDataKey, Double> {
private PedestrianOverlapDistProcessor pedOverlapProc;
public MaxOverlapProcessor() {
super("max_size_overlap");
setAttributes(new AttributesMaxOverlapProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
//ensure that all required DataProcessors are updated.
this.pedOverlapProc.doUpdate(state);
}
@Override
public void postLoop(final SimulationState state) {
this.pedOverlapProc.postLoop(state);
OptionalDouble maximumOverlap = this.pedOverlapProc.getValues().stream().filter(val -> val > 0).mapToDouble(val -> val.doubleValue()).max();
if(maximumOverlap.isPresent()){
this.putValue(NoDataKey.key(),maximumOverlap.getAsDouble());
/* // Uncomment if you want a info box to inform you about the maximum overlap
MaxOverlapProcessor.infoBox("Minimum distance between centers: " + maximumOverlap + " meters" , "Maximum Overlap");
*/
}else{
this.putValue(NoDataKey.key(), null);
}
}
/* // Uncomment if you want a info box to inform you about the maximum overlap
public static void infoBox(String infoMessage, String titleBar)
{
JOptionPane.showMessageDialog(null, infoMessage, titleBar, JOptionPane.INFORMATION_MESSAGE);
}
*/
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesMaxOverlapProcessor att = (AttributesMaxOverlapProcessor) this.getAttributes();
this.pedOverlapProc = (PedestrianOverlapDistProcessor) manager.getProcessor(att.getPedestrianMaxOverlapProcessorId());
}
@Override
public AttributesProcessor getAttributes() {
if (super.getAttributes() == null) {
setAttributes(new AttributesMaxOverlapProcessor());
}
return super.getAttributes();
}
}
......@@ -33,7 +33,7 @@ public class NumberOverlapsProcessor extends DataProcessor<NoDataKey, Long> {
public NumberOverlapsProcessor() {
super("overlaps");
super("nr_overlaps");
setAttributes(new AttributesNumberOverlapsProcessor());
}
......
package org.vadere.simulator.projects.dataprocessing.processor;
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.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesMaxOverlapProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.*;
import java.util.stream.Stream;
/**
* This processor gives for each pedestrian - if at least one overlap occurs in this time step - the overlap with
* the closest other pedestrian. That is 2*radius - distance (between the centers of the pedestrians). That means, if
* several overlaps occur at the same timestep, only the largest one is shown.
* At the moment, the radius needs to be equal for all pedestrians in the simulation.
*
* @author Marion Gödel
*/
@DataProcessorClass()
public class PedestrianOverlapDistProcessor extends DataProcessor<TimestepPedestrianIdKey, Double> {
public PedestrianOverlapDistProcessor() {
super("overlap_dist");
}
@Override
protected void doUpdate(final SimulationState state) {
double pedRadius = state.getTopography().getAttributesPedestrian().getRadius(); // in init there is no access to the state
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
peds.forEach(p -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), p.getId()),
this.calculateOverlaps(peds, p, pedRadius)));
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
}
private double calculateOverlaps(final Collection<Pedestrian> peds, Pedestrian ped, double pedRadius) {
VPoint pos = ped.getPosition();
Stream<Pedestrian> pedList = peds.stream().filter(p -> (!p.equals(ped)) ? p.getPosition().distance(pos) <= 2 * pedRadius: false);
List<Double> overlaps = new ArrayList<Double>();
pedList.forEach(p -> overlaps.add(2*pedRadius - p.getPosition().distance(pos)));
double overlapDist = (overlaps.isEmpty()) ? 0 : Collections.max(overlaps);
return overlapDist;
}
}
package org.vadere.state.attributes.processor;
/**
* @author Marion Gödel
*
*/
public class AttributesMaxOverlapProcessor extends AttributesProcessor {
private int pedestrianMaxOverlapProcessorId;
public int getPedestrianMaxOverlapProcessorId() {
return this.pedestrianMaxOverlapProcessorId;
}
public void getPedestrianMaxOverlapProcessorId(int pedestrianMaxOverlapProcessorId) {
checkSealed();
this.pedestrianMaxOverlapProcessorId = pedestrianMaxOverlapProcessorId;
}
}
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