Commit db12ac1c authored by Mario Teixeira Parente's avatar Mario Teixeira Parente
Browse files

Merge branch 'dev/processors' into develop

parents 1709d0cd 8de07160
......@@ -112,7 +112,7 @@ protected abstract void doUpdate(final SimulationState state) {
int timeStep = state.getStep();
int amountPeds = state.getTopography().getElements(Pedestrian.class).size();
this.addValue(new TimestepDataKey(timeStep), amountPeds);
this.setValue(new TimestepDataKey(timeStep), amountPeds);
}
```
......
......@@ -20,6 +20,14 @@
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename": "postvis.trajectories",
"processors": [ 1, 18 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepRowOutputFile",
"filename": "output_ts_row.txt",
"processors": [ 20 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPositionOutputFile",
"filename": "output_ts_pos.txt",
"processors": [ 21 ]
} ],
"processors": [ {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -165,5 +173,19 @@
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor",
"id": 19
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldGridProcessor",
"id": 20,
"attributesType": "org.vadere.state.attributes.processor.AttributesFloorFieldProcessor",
"attributes": {
"targetId": 1
}
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldProcessor",
"id": 21,
"attributesType": "org.vadere.state.attributes.processor.AttributesFloorFieldProcessor",
"attributes": {
"targetId": 1
}
} ]
}
......@@ -5,10 +5,10 @@ package org.vadere.simulator.projects.dataprocessing.datakey;
*
*/
public class PedestrianIdDataKey implements DataKey<PedestrianIdDataKey> {
public class PedestrianIdKey implements DataKey<PedestrianIdKey> {
private final int pedestrianId;
public PedestrianIdDataKey(int pedestrianId) {
public PedestrianIdKey(int pedestrianId) {
this.pedestrianId = pedestrianId;
}
......@@ -36,14 +36,14 @@ public class PedestrianIdDataKey implements DataKey<PedestrianIdDataKey> {
return false;
if (getClass() != obj.getClass())
return false;
PedestrianIdDataKey other = (PedestrianIdDataKey) obj;
PedestrianIdKey other = (PedestrianIdKey) obj;
if (pedestrianId != other.pedestrianId)
return false;
return true;
}
@Override
public int compareTo(PedestrianIdDataKey o) {
public int compareTo(PedestrianIdKey o) {
return Integer.compare(pedestrianId, o.pedestrianId);
}
......
......@@ -5,14 +5,14 @@ package org.vadere.simulator.projects.dataprocessing.datakey;
*
*/
public class TimestepDataKey implements DataKey<TimestepDataKey> {
public class TimestepKey implements DataKey<TimestepKey> {
private final int timestep;
public TimestepDataKey(int timestep) {
public TimestepKey(int timestep) {
this.timestep = timestep;
}
@Override
public int compareTo(final TimestepDataKey o) {
public int compareTo(final TimestepKey o) {
return Integer.compare(timestep, o.timestep);
}
......@@ -36,7 +36,7 @@ public class TimestepDataKey implements DataKey<TimestepDataKey> {
return false;
if (getClass() != obj.getClass())
return false;
TimestepDataKey other = (TimestepDataKey) obj;
TimestepKey other = (TimestepKey) obj;
if (timestep != other.timestep)
return false;
return true;
......
......@@ -5,11 +5,11 @@ package org.vadere.simulator.projects.dataprocessing.datakey;
*
*/
public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianIdDataKey> {
public class TimestepPedestrianIdKey implements DataKey<TimestepPedestrianIdKey> {
private final int timestep;
private final int pedestrianId;
public TimestepPedestrianIdDataKey(int timestep, int pedestrianId) {
public TimestepPedestrianIdKey(int timestep, int pedestrianId) {
this.timestep = timestep;
this.pedestrianId = pedestrianId;
}
......@@ -23,7 +23,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId
}
@Override
public int compareTo(TimestepPedestrianIdDataKey o) {
public int compareTo(TimestepPedestrianIdKey o) {
int result = Integer.compare(timestep, o.timestep);
if (result == 0) {
return Integer.compare(pedestrianId, o.pedestrianId);
......@@ -32,7 +32,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId
}
public static String[] getHeaders() {
return new String[] { TimestepDataKey.getHeader(), PedestrianIdDataKey.getHeader() };
return new String[] { TimestepKey.getHeader(), PedestrianIdKey.getHeader() };
}
@Override
......@@ -52,7 +52,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId
return false;
if (getClass() != obj.getClass())
return false;
TimestepPedestrianIdDataKey other = (TimestepPedestrianIdDataKey) obj;
TimestepPedestrianIdKey other = (TimestepPedestrianIdKey) obj;
if (pedestrianId != other.pedestrianId)
return false;
if (timestep != other.timestep)
......
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.jetbrains.annotations.NotNull;
import org.vadere.util.geometry.shapes.VPoint;
/**
* @author Mario Teixeira Parente
*/
public class TimestepPositionKey implements DataKey<TimestepPositionKey> {
private int timeStep;
private VPoint position;
public TimestepPositionKey(int timeStep, VPoint position) {
this.timeStep = timeStep;
this.position = position;
}
public int getTimeStep() {
return this.timeStep;
}
public VPoint getPosition() {
return this.position;
}
@Override
public int compareTo(@NotNull TimestepPositionKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
result = Double.compare(this.position.x, o.position.x);
if (result == 0) {
result = Double.compare(this.position.y, o.position.y);
}
}
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TimestepPositionKey that = (TimestepPositionKey) o;
if (timeStep != that.timeStep) return false;
return position.equals(that.position);
}
@Override
public int hashCode() {
int result = timeStep;
result = 31 * result + position.hashCode();
return result;
}
public static String[] getHeaders() {
return new String[] { "timeStep", "x", "y" };
}
}
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.jetbrains.annotations.NotNull;
/**
* @author Mario Teixeira Parente
*
*/
public class TimestepRowKey implements DataKey<TimestepRowKey> {
private int timeStep;
private int row;
public TimestepRowKey(int timeStep, int row) {
this.timeStep = timeStep;
this.row = row;
}
public int getTimeStep() {
return this.timeStep;
}
public int getRow() {
return this.row;
}
@Override
public int compareTo(@NotNull TimestepRowKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
return Integer.compare(this.row, o.row);
}
return result;
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
/**
* @author Mario Teixeira Parente
*
*/
public class PedestrianIdOutputFile extends OutputFile<PedestrianIdDataKey> {
public class PedestrianIdOutputFile extends OutputFile<PedestrianIdKey> {
public PedestrianIdOutputFile() {
super(PedestrianIdDataKey.getHeader());
super(PedestrianIdKey.getHeader());
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
/**
* @author Mario Teixeira Parente
*
*/
public class TimestepOutputFile extends OutputFile<TimestepDataKey> {
public class TimestepOutputFile extends OutputFile<TimestepKey> {
public TimestepOutputFile() {
super("hdfkh");
......
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
/**
* @author Mario Teixeira Parente
*
*/
public class TimestepPedestrianIdOutputFile extends OutputFile<TimestepPedestrianIdDataKey> {
public class TimestepPedestrianIdOutputFile extends OutputFile<TimestepPedestrianIdKey> {
public TimestepPedestrianIdOutputFile() {
super(TimestepPedestrianIdDataKey.getHeaders());
super(TimestepPedestrianIdKey.getHeaders());
}
@Override
public String[] toStrings(final TimestepPedestrianIdDataKey key) {
public String[] toStrings(final TimestepPedestrianIdKey key) {
return new String[] { Integer.toString(key.getTimestep()), Integer.toString(key.getPedestrianId()) };
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPositionKey;
public class TimestepPositionOutputFile extends OutputFile<TimestepPositionKey> {
public TimestepPositionOutputFile() {
super(TimestepPositionKey.getHeaders());
}
@Override
public String[] toStrings(TimestepPositionKey key) {
return new String[] { Integer.toString(key.getTimeStep()), Double.toString(key.getPosition().x), Double.toString(key.getPosition().y) };
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepRowKey;
public class TimestepRowOutputFile extends OutputFile<TimestepRowKey> {
public TimestepRowOutputFile() {
super("timeStep", "row");
}
@Override
public String[] toStrings(TimestepRowKey key) {
return new String[] { Integer.toString(key.getTimeStep()), Integer.toString(key.getRow()) };
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesAreaProcessor;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -10,7 +10,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
*
*/
public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepDataKey, V> {
public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> {
private VRectangle measurementArea;
protected AreaDataProcessor(final String... headers) {
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
/**
* @author Mario Teixeira Parente
......@@ -18,6 +18,6 @@ public abstract class AreaDensityProcessor extends AreaDataProcessor<Double> {
@Override
protected void doUpdate(final SimulationState state) {
this.addValue(new TimestepDataKey(state.getStep()), this.densAlg.getDensity(state));
this.setValue(new TimestepKey(state.getStep()), this.densAlg.getDensity(state));
}
}
......@@ -2,9 +2,9 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesAreaSpeedProcessor;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -30,22 +30,22 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> {
this.pedPosProc.update(state);
this.pedVelProc.update(state);
Map<PedestrianIdDataKey, VPoint> positionMap = this.pedPosProc.getPositions(new TimestepDataKey(step));
Map<PedestrianIdKey, VPoint> positionMap = this.pedPosProc.getPositions(new TimestepKey(step));
int pedCount = 0;
double sumVelocities = 0.0;
for (Map.Entry<PedestrianIdDataKey, VPoint> entry : positionMap.entrySet()) {
for (Map.Entry<PedestrianIdKey, VPoint> entry : positionMap.entrySet()) {
final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue();
if (getMeasurementArea().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdDataKey(step, pedId));
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId));
pedCount++;
}
}
this.addValue(new TimestepDataKey(step), sumVelocities / pedCount);
this.setValue(new TimestepKey(step), sumVelocities / pedCount);
}
@Override
......
......@@ -20,7 +20,7 @@ import java.util.TreeMap;
*
* The method <tt>doUpdate</tt> gets called after every simulation step with the current <tt>SimulationState</tt>.
* Here, one gets the opportunity to compute a new value or to update the state for a computation in <tt>postLoop</tt>.
* The computed value can be stored afterwards in the data by using the <tt>addValue</tt> method.
* The computed value can be stored afterwards in the data by using the <tt>setValue</tt> method.
*
* To get specific attributes defined in JSON or access to the <tt>MainModel</tt>, one has to use the <tt>init</tt> method which
* gives access to all significant things via the argument <tt>manager</tt> of type <tt>ProcessorManager</tt>.
......@@ -96,7 +96,7 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
return data.get(key);
}
protected void addValue(final K key, final V value) {
protected void setValue(final K key, final V value) {
this.data.put(key, value);
}
......
......@@ -36,7 +36,7 @@ public class EvacuationTimeProcessor extends DataProcessor<NoDataKey, Double> {
: Collections.max(this.pedEvacTimeProc.getValues());
}
this.addValue(NoDataKey.key(), result);
this.setValue(NoDataKey.key(), result);
}
@Override
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepRowKey;
import org.vadere.state.attributes.processor.AttributesFloorFieldProcessor;
import org.vadere.util.data.FloorFieldGridRow;
public class FloorFieldGridProcessor extends DataProcessor<TimestepRowKey, FloorFieldGridRow> {
private int targetId;
@Override
protected void doUpdate(SimulationState state) {
// First try, TODO: Implementation
for (int i = 0; i < 50; ++i) {
this.setValue(new TimestepRowKey(state.getStep(), i), new FloorFieldGridRow(50));
}
}
@Override
public void init(ProcessorManager manager) {
AttributesFloorFieldProcessor att = (AttributesFloorFieldProcessor) this.getAttributes();
this.targetId = att.getTargetId();
}
@Override
public String[] toStrings(TimestepRowKey key) {
return this.getValue(key).toStrings();
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPositionKey;
import org.vadere.state.attributes.processor.AttributesFloorFieldProcessor;
import org.vadere.util.geometry.shapes.VPoint;
/**
* @author Mario Teixeira Parente
*/
public class FloorFieldProcessor extends DataProcessor<TimestepPositionKey, Double> {
private int targetId;
public FloorFieldProcessor() {
super("potential");
}
@Override
protected void doUpdate(SimulationState state) {
// First try, TODO: Implementation
for (int x = 0; x < 50; ++x) {
for (int y = 0; y < 50; ++y) {
this.setValue(new TimestepPositionKey(state.getStep(), new VPoint(x, y)), 0.0);
}
}
}
@Override
public void init(ProcessorManager manager) {
AttributesFloorFieldProcessor att = (AttributesFloorFieldProcessor) this.getAttributes();
this.targetId = att.getTargetId();
}
}
......@@ -40,7 +40,7 @@ public class MeanPedestrianEvacuationTimeProcessor extends DataProcessor<NoDataK
.collect(Collectors.toList());
int count = nonNans.size();
this.addValue(NoDataKey.key(), count > 0
this.setValue(NoDataKey.key(), count > 0
? nonNans.stream().reduce(0.0, (val1, val2) -> val1 + val2) / count
: Double.NaN);
}
......
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