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

Commit 6b8a40a2 authored by Marion Goedel's avatar Marion Goedel

Added a new outputprocessor, namely "NumberOverlapsProcessor" that is...

Added a new outputprocessor, namely "NumberOverlapsProcessor" that is dependent of the PedestrianOverlapProcessor. It saves the number of overlaps that occurred during the simulation run.
parent af25b04e
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.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor;
import org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor;
import org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import javax.swing.JOptionPane;
import javax.print.attribute.IntegerSyntax;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* This processor counts the number of overlaps during a simulation run.
* The is commented code that can be used to show a info box if overlaps occured.
*
* @author Marion Gödel
*/
@DataProcessorClass()
public class NumberOverlapsProcessor extends DataProcessor<NoDataKey, Long> {
private PedestrianOverlapProcessor pedOverlapProc;
public NumberOverlapsProcessor() {
super("overlaps");
setAttributes(new AttributesNumberOverlapsProcessor());
}
@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);
long numberOverlaps = 0;
if (this.pedOverlapProc.getValues().size() > 0) {
numberOverlaps = this.pedOverlapProc.getValues().stream().filter(i -> i == 1).count();
}
/* // Uncomment this code if you want to get the info box with the number of overlaps
if (numberOverlaps > 0 ) {
NumberOverlapsProcessor.infoBox(numberOverlaps + " Overlaps have occured during the simulation!", "Number Overlaps");
System.out.println("* CAREFUL *: " + numberOverlaps + " Overlaps have occured during the simulation!");
}
*/
this.putValue(NoDataKey.key(), numberOverlaps);
}
/*
// Uncomment this code if you want to get the info box with the number of overlaps (if > 0)
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);
AttributesNumberOverlapsProcessor att = (AttributesNumberOverlapsProcessor) this.getAttributes();
this.pedOverlapProc = (PedestrianOverlapProcessor) manager.getProcessor(att.getPedestrianOverlapProcessorId());
}
@Override
public AttributesProcessor getAttributes() {
if (super.getAttributes() == null) {
setAttributes(new AttributesNumberOverlapsProcessor());
}
return super.getAttributes();
}
}
......@@ -18,6 +18,7 @@ import java.util.Collection;
public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrianIdKey, Integer> {
private double pedRadius;
public PedestrianOverlapProcessor() {
super("overlaps");
setAttributes(new AttributesPedestrianOverlapProcessor());
......
package org.vadere.state.attributes.processor;
/**
* @author Marion Gödel
*
*/
public class AttributesNumberOverlapsProcessor extends AttributesProcessor {
private int pedestrianOverlapProcessorId;
public int getPedestrianOverlapProcessorId() {
return this.pedestrianOverlapProcessorId;
}
public void setPedestrianOverlapProcessorId(int pedestrianOverlapProcessorId) {
checkSealed();
this.pedestrianOverlapProcessorId = pedestrianOverlapProcessorId;
}
}
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