delete Processors that are not tied to basic infrastructure

parent df38613e
package org.vadere.simulator.projects.dataprocessing.processors;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.vadere.simulator.control.SimulationState;
import org.vadere.state.attributes.processors.AttributesDensityVoronoiProcessor;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.util.data.Row;
import org.vadere.util.data.Table;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.voronoi.VoronoiDiagram;
import com.google.gson.annotations.Expose;
/**
*
* Computes the density over defined area for each time step.
*
*
*/
public class AreaVoronoiProcessor extends AbstractProcessor {
@Expose
private Table table;
@Expose
private int lastStep;
@Expose
private Map<Integer, Double> areaMap;
@Expose
private Map<Integer, VPoint> faceMap;
private AttributesDensityVoronoiProcessor attributes;
private PedestrianVelocityProcessor pedestrianVelocityProcessor;
public AreaVoronoiProcessor() {
this(new AttributesDensityVoronoiProcessor(), new PedestrianVelocityProcessor());
}
public AreaVoronoiProcessor(final AttributesDensityVoronoiProcessor attributes,
final PedestrianVelocityProcessor pedestrianVelocityProcessor) {
this.areaMap = new HashMap<>();
this.faceMap = new HashMap<>();
this.attributes = attributes;
this.pedestrianVelocityProcessor = pedestrianVelocityProcessor;
this.pedestrianVelocityProcessor.addColumnName("speed");
table = getTable();
table.clear("step", "time", getDensityType(), "speed", "flow");
}
@Override
public Table preLoop(SimulationState state) {
return super.preLoop(state);
}
@Override
public Table postUpdate(final SimulationState state) {
Table table = getTable();
table.clear();
table.addRow();
Row row = new Row();
row.setEntry("step", state.getStep());
row.setEntry("time", state.getSimTimeInSec());
double density = getDensity(state);
row.setEntry(getDensityType(), density);
double speed = getSpeed(state);
row.setEntry("speed", speed);
row.setEntry("flow", density * speed);
table.addColumnEntries(row);
return table;
}
@Override
public String[] getAllColumnNames() {
return table.getColumnNames();
}
private double getDensity(final SimulationState state) {
if (state.getStep() != lastStep) {
cumputeAreas(state);
lastStep = state.getStep();
}
VRectangle measurementArea = attributes.getMeasurementArea();
double area = 0.0;
double pedCount = 0.0;
for (Integer site : faceMap.keySet()) {
if (measurementArea.contains(faceMap.get(site))) {
area += areaMap.get(site);
pedCount++;
}
}
if (pedCount == 0) {
return 0;
} else {
return pedCount / area;
}
}
private double getSpeed(final SimulationState state) {
Table pedVelocityTable = pedestrianVelocityProcessor.postUpdate(state);
VRectangle measurementArea = attributes.getMeasurementArea();
ListIterator<Row> rowIteratorVelocity = pedVelocityTable.listMapIterator();
double pedCount = 0;
double sumSpeeds = 0;
while (rowIteratorVelocity.hasNext()) {
Row velocityRow = rowIteratorVelocity.next();
VPoint position = new VPoint((Double) velocityRow.getEntry("x"), (Double) velocityRow.getEntry("y"));
if (measurementArea.contains(position)) {
double speed = (Double) velocityRow.getEntry("speed");
sumSpeeds += speed;
pedCount++;
}
}
return sumSpeeds / pedCount;
}
private void cumputeAreas(final SimulationState state) {
VoronoiDiagram voronoiDiagram = new VoronoiDiagram(attributes.getVoronoiArea());
// convert pedestrians to positions
List<VPoint> pedestrianPositions = Agent.getPositions(state.getTopography().getElements(Agent.class));
voronoiDiagram.computeVoronoiDiagram(pedestrianPositions);
// compute everything
List<org.vadere.util.voronoi.Face> faces = voronoiDiagram.getFaces();
areaMap.clear();
faceMap.clear();
// TODO [priority=medium] [task=optimization] use TreeMap and a good comparator to speed this up!
if (faces != null) {
for (org.vadere.util.voronoi.Face face : faces) {
areaMap.put(face.getId(), face.computeArea());
faceMap.put(face.getId(), face.getSite());
}
}
}
@Override
public AreaVoronoiProcessor clone() {
return new AreaVoronoiProcessor(attributes, pedestrianVelocityProcessor.clone());
}
public String getDensityType() {
return "voronoiAreaDensity";
}
@Override
public boolean equals(final Object obj) {
if (super.equals(obj)) {
AreaVoronoiProcessor tmp = (AreaVoronoiProcessor) obj;
return tmp.attributes.equals(attributes);
}
return false;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + attributes.hashCode();
return result;
}
}
package org.vadere.simulator.projects.dataprocessing.processors;
import org.vadere.simulator.control.SimulationState;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.processors.AttributesDensityCountingProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.data.Table;
import org.vadere.util.geometry.shapes.VPoint;
import com.google.gson.annotations.Expose;
/**
* Adds the current timeStep (step), the current time, position (x, y-coordinates) of each position
* in the position list of this Processor and additional adds the density on these position.
* The density is calculated by counting pedestrians in a circle around each position.
*
* <p>
* <b>Added column names</b>: step {@link Integer}, time {@link Double}, x {@link Double}, y
* {@link Double}, circleDensity {@link Double}
* </p>
*
*
*/
public class DensityCountingProcessor extends DensityProcessor {
private AttributesDensityCountingProcessor attributes;
@Expose
private Table table;
@Expose
private double circleArea;
public DensityCountingProcessor() {
this(new AttributesDensityCountingProcessor());
}
public DensityCountingProcessor(final AttributesDensityCountingProcessor attributes) {
this.attributes = attributes;
this.circleArea = attributes.getRadius() * attributes.getRadius() * Math.PI;
table = getTable();
}
@Override
public String[] getAllColumnNames() {
return table.getColumnNames();
}
protected double getDensity(final VPoint position, final SimulationState state) {
int numberOfPedsInCircle = 0;
for (Pedestrian ped : state.getTopography().getElements(Pedestrian.class)) {
if (position.distance(ped.getPosition()) < attributes.getRadius()) {
numberOfPedsInCircle++;
}
}
return (numberOfPedsInCircle / circleArea);
}
@Override
public DensityCountingProcessor clone() {
return new DensityCountingProcessor(attributes);
}
@Override
public boolean equals(final Object obj) {
if (super.equals(obj)) {
DensityCountingProcessor tmp = (DensityCountingProcessor) obj;
return tmp.attributes.equals(attributes);
}
return false;
}
@Override
public int hashCode() {
int result = super.hashCode();
long temp;
result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
result = 31 * result + (table != null ? table.hashCode() : 0);
temp = Double.doubleToLongBits(circleArea);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String getDensityType() {
return "circleDensity";
}
@Override
public Attributes getAttributes() {
return attributes;
}
}
package org.vadere.simulator.projects.dataprocessing.processors;
import com.google.gson.annotations.Expose;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.models.density.IGaussianFilter;
import org.vadere.simulator.models.potential.timeCostFunction.loading.IPedestrianLoadingStrategy;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.processors.AttributesDensityGaussianProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.data.Table;
import org.vadere.util.geometry.shapes.VPoint;
/**
* Adds the current timeStep (step), the current time, position (x, y-coordinates) of each position
* in the position list of this Processor and additional adds the density on these position.
* The density is calculated by using the gaussian filter (image processing technique).
*
* <p>
* Note: This processor does only work online, since it needs real pedestrain objects
* </p>
*
* <p>
* <b>Added column names</b>: step {@link Integer}, time {@link Double}, x {@link Double}, y
* {@link Double}, gaussianDensity {@link Double}
* </p>
*
*
*/
public class DensityGaussianProcessor extends DensityProcessor {
@Expose
private static Logger logger = LogManager.getLogger(DensityGaussianProcessor.class);
@Expose
private final Table table;
@Expose
private int lastStep;
@Expose
private boolean filteredObstacles;
@Expose
private IGaussianFilter pedestrianFilter;
@Expose
private IGaussianFilter obstacleFilter;
private AttributesDensityGaussianProcessor attributes;
public DensityGaussianProcessor(final AttributesDensityGaussianProcessor attributes) {
super();
this.attributes = attributes;
table = getTable();
this.lastStep = 0;
this.filteredObstacles = false;
}
public DensityGaussianProcessor() {
this(new AttributesDensityGaussianProcessor());
}
@Override
public Table preLoop(SimulationState state) {
return super.preLoop(state);
}
@Override
protected double getDensity(final VPoint position, final SimulationState state) {
double density = 0.0;
if (lastStep != state.getStep()) {
// obstacle will not change so we do it once.
if (!filteredObstacles && attributes.isObstacleDensity()) {
this.obstacleFilter = IGaussianFilter.create(
state.getTopography(),
attributes.getScale(),
attributes.getStandardDerivation());
this.obstacleFilter.filterImage();
filteredObstacles = true;
}
this.pedestrianFilter = IGaussianFilter.create(
state.getTopography().getBounds(),
state.getTopography().getElements(Pedestrian.class),
attributes.getScale(),
attributes.getStandardDerivation(),
state.getTopography().getAttributesPedestrian(),
IPedestrianLoadingStrategy.create());
this.pedestrianFilter.filterImage();
}
if (attributes.isObstacleDensity()) {
density = this.obstacleFilter.getFilteredValue(position.x, position.y);
}
density += this.pedestrianFilter.getFilteredValue(position.x, position.y);
this.lastStep = state.getStep();
return density;
}
@Override
public DensityProcessor clone() {
return new DensityGaussianProcessor();
}
@Override
public String getDensityType() {
return "gaussianDensity";
}
@Override
public Attributes getAttributes() {
return attributes;
}
}
package org.vadere.simulator.projects.dataprocessing.processors;
import com.google.gson.annotations.Expose;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.vadere.simulator.control.SimulationState;
import org.vadere.util.data.Table;
import org.vadere.util.geometry.shapes.VPoint;
/**
* Adds the current timeStep (step), the current time, position (x, y-coordinates) of each position
* in the position list of this Processor and additional adds the density on these position.
*
* <p>
* <b>Added column names</b>: step {@link Integer}, time {@link Double}, x {@link Double}, y
* {@link Double}
* </p>
*
*
*/
public abstract class DensityProcessor extends AbstractProcessor {
@Expose
private List<VPoint> positions;
@Expose
private int lastStep;
public DensityProcessor() {
getTable().clear("step", "time", "x", "y", getDensityType());
positions = new ArrayList<>();
this.lastStep = 0;
}
@Override
public Table preLoop(SimulationState state) {
return super.preLoop(state);
}
@Override
public Table postUpdate(final SimulationState state) {
Table table = getTable();
if (table.isEmpty() || state.getStep() != lastStep) {
table.clear();
for (int row = 0; row < getPositions().size(); row++) {
VPoint position = getPositions().get(row);
table.addRow();
table.addColumnEntry("step", state.getStep());
table.addColumnEntry("time", state.getSimTimeInSec());
table.addColumnEntry("x", position.x);
table.addColumnEntry("y", position.y);
if (isColumnVisible(getDensityType())) {
table.addColumnEntry(getDensityType(), getDensity(position, state));
}
}
}
return table;
}
/**
* Every DensityProcessor should has a unique density type (the name of the column in the
* table).
* This method returns the unique name to identify the column of this density.
*
* @return the unique name to identify the column of this density
*/
public abstract String getDensityType();
/**
* Returns the density of a specific position for the given simulation state.
*
* @param position the position where the measurement will take place
* @param state the simulation state
* @return the density of a specific position
*/
protected abstract double getDensity(final VPoint position, final SimulationState state);
protected List<VPoint> getPositions() {
return positions;
}
public void addAllPositions(final Collection<? extends VPoint> positions) {
this.positions.addAll(positions);
}
public void addAllPositions(final VPoint... positions) {
addAllPositions(Arrays.asList(positions));
}
public void addPosition(final VPoint position) {
positions.add(position);
}
public void removePosition(final VPoint position) {
positions.remove(position);
}
public void removeAllPositions() {
positions.clear();
}
@Override
public abstract DensityProcessor clone();
@Override
public boolean equals(final Object obj) {
if (super.equals(obj)) {
DensityProcessor tmp = (DensityProcessor) obj;
return tmp.positions.equals(positions);
}
return false;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + positions.hashCode();
result = 47 * result + lastStep;
return result;
}
}
package org.vadere.simulator.projects.dataprocessing.processors;
import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.vadere.simulator.control.SimulationState;
import org.vadere.state.attributes.processors.AttributesDensityVoronoiProcessor;
import org.vadere.state.scenario.Agent;
import org.vadere.util.data.Table;
import org.vadere.util.geometry.jts.VoronoiFactory;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import com.google.gson.annotations.Expose;
/**
* Adds the current timeStep (step), the current time, position (x, y-coordinates) of each position
* in the position list of this Processor and additional adds the density on these position.
* The density is calculated by using the the jts diagram.
*
* <p>
* <b>Added column names</b>: step {@link Integer}, time {@link Double}, x {@link Double}, y
* {@link Double}, voronoiDensity {@link Double}