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

Commit d2b3758a authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Rework MigraionAssistant

MigrationAssistant
  |
  +-- IncidentMigrationAssistant (Deprecated)
  |
  +-- JsonMigrationAssistant
      |
      +--using JsonTransformation Interface

The JsonTransformation interface is implemented by in two
different ways:
AbstractJsonTransformation
  |              implements JsonTransformation, JsonNodeExplorer
  |
  +-- JoltTransformation --> relying on Jolt [1]
  |
  +-- SimpleJsonTransformation --> relying on Jackson JsonNode

The JsonTransformation interface provides a three step process
of to transform a given scenario File were each consumes a JsonNode
and returns the changed JsonNode.
1) preHooks
2) transformation
3) postHooks

The MigrationAssistant selects the correct implementation by
using the JsonTransformationFactory which map a given Version
to the corresponding implementation of some JsonTransformation.

1. Subclass either JoltTransformation or SimpeJsonTransformation.
  (a) If JoltTransformation is used, a specialized transformation syntax
      must be used. See [1] for Doc.
  (b) If SimpleJsonTransformation is used no additional input is needed.
       The transformation is done by manually manipulating the Jackson
       JsonNode-Tree
2. add annotation where X.X resembles the Version label i.e. "0.8"
   @MigrationTransformation(targetVersionLabel = "X.X")
3. add the default constructor with no arguments and the
   call super constructor passing the Version
4. Implement initDefaultHooks() and add the pre- and postHook
   LinkedList with JsonTransformationHooks
   (a) use add[Post|Pre][First|Last] methods.
   (b) add addPostHookLast(AbstractJsonTransformation::sort) to ensure
       the right sorting order within the scenario file.
5. (optional) overwrite any of applyPreHooks, applyTransformation,
   applyPostHooks if needed.
6. (optional) add generic JsonNode manipulations to JsonNodeExplorer

This interface contains useful default implementation to navigate a
JsonNode-Tree such as:

path(jsonNode, "some/path/within/the/json") <-- will return empty nodes
                                            with path das not exist
pathMustExist(jsonNode, "some/path/within/the/json") <-- will throw
                                                     MigrationException
renameField(node, "release", "version")  <-- rename keys

iteratorProcessorsByType(jsonRoot, "org...PedestrianVelocityProcessor )
  <-- returns an iterator of JsonNodes representing a
  PedestrianVelocityProcessor

[1]: https://github.com/bazaarvoice/joltSigned-off-by: hm-schuhba1's avatarhm-schuhba1 <stefan.schuhbaeck@hm.edu>
parent f3e5f552
...@@ -7,10 +7,10 @@ import java.lang.annotation.Target; ...@@ -7,10 +7,10 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@FactoryType( @FactoryType(
factoryClassName = "JoltTransformationFactory", factoryClassName = "JsonTransformationFactory",
extendedClassName = "JoltTransformationBaseFactory", extendedClassName = "JsonTransformationBaseFactory",
factoryImports = {"org.vadere.simulator.projects.migration.jolttranformation.JoltTransformationBaseFactory"}, factoryImports = {"org.vadere.simulator.projects.migration.jsontranformation.JsonTransformationBaseFactory"},
factoryPackage = "org.vadere.simulator.projects.migration.jolttranformation" factoryPackage = "org.vadere.simulator.projects.migration.jsontranformation"
) )
public @interface MigrationTransformation { public @interface MigrationTransformation {
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.migration.incidents.VersionBumpIncident;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* Versions in strict order from oldest to newest. * Versions in strict order from oldest to newest.
...@@ -20,7 +18,8 @@ public enum Version { ...@@ -20,7 +18,8 @@ public enum Version {
V0_4("0.4"), V0_4("0.4"),
V0_5("0.5"), V0_5("0.5"),
V0_6("0.6"), V0_6("0.6"),
V0_7("0.7") V0_7("0.7"),
V0_8("0.8"),
; ;
private String label; private String label;
......
...@@ -5,11 +5,11 @@ import net.sourceforge.argparse4j.inf.Namespace; ...@@ -5,11 +5,11 @@ import net.sourceforge.argparse4j.inf.Namespace;
import org.vadere.simulator.entrypoints.Version; import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner; import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.migration.JoltMigrationAssistant; import org.vadere.simulator.projects.migration.jsontranformation.JsonMigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationAssistant; import org.vadere.simulator.projects.migration.MigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationException; import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.MigrationOptions; import org.vadere.simulator.projects.migration.MigrationOptions;
import org.vadere.simulator.projects.migration.helper.MigrationUtil; import org.vadere.simulator.projects.migration.incident.helper.MigrationUtil;
import org.vadere.util.logging.Logger; import org.vadere.util.logging.Logger;
import java.io.IOException; import java.io.IOException;
...@@ -94,7 +94,7 @@ public class MigrationSubCommand implements SubCommandRunner { ...@@ -94,7 +94,7 @@ public class MigrationSubCommand implements SubCommandRunner {
for (Path dir : dirs) { for (Path dir : dirs) {
logger.info("migrate directory to version(" + targetVersion.label() + "): " + dir.toAbsolutePath().toString()); logger.info("migrate directory to version(" + targetVersion.label() + "): " + dir.toAbsolutePath().toString());
if (projectOnly){ if (projectOnly){
JoltMigrationAssistant migrationAssistant = new JoltMigrationAssistant(); JsonMigrationAssistant migrationAssistant = new JsonMigrationAssistant();
migrationAssistant.analyzeProject(dir.toString()); migrationAssistant.analyzeProject(dir.toString());
} else { } else {
migrationUtil.migrateDirectoryTree(dir, targetVersion, recursive); migrationUtil.migrateDirectoryTree(dir, targetVersion, recursive);
...@@ -147,7 +147,7 @@ public class MigrationSubCommand implements SubCommandRunner { ...@@ -147,7 +147,7 @@ public class MigrationSubCommand implements SubCommandRunner {
outputFile = Paths.get(outputPathString).resolve(scenarioFile.getFileName()); outputFile = Paths.get(outputPathString).resolve(scenarioFile.getFileName());
} }
ma.migrateFile(scenarioFile, targetVersion, outputFile); ma.migrateScenarioFile(scenarioFile, targetVersion, outputFile);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -97,7 +97,7 @@ public class ScenarioRun implements Runnable { ...@@ -97,7 +97,7 @@ public class ScenarioRun implements Runnable {
// prepare processors and simulation data writer // prepare processors and simulation data writer
if(scenarioStore.getAttributesSimulation().isWriteSimulationData()) { if(scenarioStore.getAttributesSimulation().isWriteSimulationData()) {
processorManager = dataProcessingJsonManager.createProcessorManager(mainModel); processorManager = dataProcessingJsonManager.createProcessorManager(mainModel, scenarioStore.getTopography());
processorManager.setSimulationResult(simulationResult); processorManager.setSimulationResult(simulationResult);
} }
......
...@@ -16,6 +16,7 @@ import org.vadere.simulator.projects.dataprocessing.processor.DataProcessorFacto ...@@ -16,6 +16,7 @@ import org.vadere.simulator.projects.dataprocessing.processor.DataProcessorFacto
import org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore; import org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore;
import org.vadere.simulator.projects.dataprocessing.store.OutputFileStore; import org.vadere.simulator.projects.dataprocessing.store.OutputFileStore;
import org.vadere.state.attributes.processor.AttributesProcessor; import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter; import org.vadere.state.util.StateJsonConverter;
import java.io.IOException; import java.io.IOException;
...@@ -281,14 +282,14 @@ public class DataProcessingJsonManager { ...@@ -281,14 +282,14 @@ public class DataProcessingJsonManager {
return main; return main;
} }
public ProcessorManager createProcessorManager(MainModel mainModel) { public ProcessorManager createProcessorManager(MainModel mainModel, final Topography topography) {
// this function is called when the simulation starts running // this function is called when the simulation starts running
for (OutputFile f : outputFiles) { for (OutputFile f : outputFiles) {
f.setWriteMetaData(isWriteMetaData()); // allow to write meta data f.setWriteMetaData(isWriteMetaData()); // allow to write meta data
} }
return new ProcessorManager(dataProcessors, outputFiles, mainModel); return new ProcessorManager(dataProcessors, outputFiles, mainModel, topography);
} }
......
...@@ -5,6 +5,8 @@ import org.vadere.simulator.models.MainModel; ...@@ -5,6 +5,8 @@ import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.projects.SimulationResult; import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile; import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor; import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Topography;
import java.io.File; import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -19,14 +21,17 @@ import java.util.Map; ...@@ -19,14 +21,17 @@ import java.util.Map;
public class ProcessorManager { public class ProcessorManager {
private MainModel mainModel; private MainModel mainModel;
private final Topography topography;
private Map<Integer, DataProcessor<?, ?>> processorMap; private Map<Integer, DataProcessor<?, ?>> processorMap;
private List<OutputFile<?>> outputFiles; private List<OutputFile<?>> outputFiles;
private SimulationResult simulationResult; private SimulationResult simulationResult;
public ProcessorManager(List<DataProcessor<?, ?>> dataProcessors, public ProcessorManager(List<DataProcessor<?, ?>> dataProcessors,
List<OutputFile<?>> outputFiles, MainModel mainModel) { List<OutputFile<?>> outputFiles, MainModel mainModel,
final Topography topography) {
this.mainModel = mainModel; this.mainModel = mainModel;
this.topography = topography;
this.outputFiles = outputFiles; this.outputFiles = outputFiles;
...@@ -49,6 +54,10 @@ public class ProcessorManager { ...@@ -49,6 +54,10 @@ public class ProcessorManager {
return this.processorMap.getOrDefault(id, null); return this.processorMap.getOrDefault(id, null);
} }
public MeasurementArea getMeasurementArea(int measurementAreaId){
return topography.getMeasurementArea(measurementAreaId);
}
public MainModel getMainModel() { public MainModel getMainModel() {
return mainModel; return mainModel;
} }
......
...@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor; ...@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager; import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesAreaProcessor; import org.vadere.state.attributes.processor.AttributesAreaProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
/** /**
...@@ -11,7 +12,7 @@ import org.vadere.util.geometry.shapes.VRectangle; ...@@ -11,7 +12,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
*/ */
public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> { public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> {
private VRectangle measurementArea; private MeasurementArea measurementArea;
protected AreaDataProcessor(final String... headers) { protected AreaDataProcessor(final String... headers) {
super(headers); super(headers);
...@@ -21,10 +22,15 @@ public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> ...@@ -21,10 +22,15 @@ public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V>
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesAreaProcessor att = (AttributesAreaProcessor) this.getAttributes(); AttributesAreaProcessor att = (AttributesAreaProcessor) this.getAttributes();
this.measurementArea = att.getMeasurementArea(); this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
} }
public VRectangle getMeasurementArea() { public MeasurementArea getMeasurementArea() {
return this.measurementArea; return this.measurementArea;
} }
} }
...@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor; ...@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.control.SimulationState; import org.vadere.simulator.control.SimulationState;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.voronoi.Face; import org.vadere.util.voronoi.Face;
...@@ -21,11 +22,11 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm { ...@@ -21,11 +22,11 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm {
private VRectangle measurementArea; private VRectangle measurementArea;
private VRectangle voronoiArea; private VRectangle voronoiArea;
public AreaDensityVoronoiAlgorithm(final VRectangle measurementArea, final VRectangle voronoiArea) { public AreaDensityVoronoiAlgorithm(final MeasurementArea measurementArea, final MeasurementArea voronoiArea) {
super("areaVoronoi"); super("areaVoronoi");
this.measurementArea = measurementArea; this.measurementArea = measurementArea.asVRectangle();
this.voronoiArea = voronoiArea; this.voronoiArea = voronoiArea.asVRectangle();
} }
@Override @Override
......
...@@ -5,6 +5,7 @@ import org.vadere.state.attributes.processor.AttributesAreaDensityVoronoiProcess ...@@ -5,6 +5,7 @@ import org.vadere.state.attributes.processor.AttributesAreaDensityVoronoiProcess
import org.vadere.state.attributes.processor.AttributesProcessor; import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass; import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.state.scenario.MeasurementArea;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
...@@ -23,7 +24,13 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor { ...@@ -23,7 +24,13 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor {
super.init(manager); super.init(manager);
AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes(); AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes();
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), att.getVoronoiArea())); MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), measurementArea));
} }
@Override @Override
......
...@@ -43,7 +43,7 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> { ...@@ -43,7 +43,7 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> {
final int pedId = entry.getKey().getPedestrianId(); final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue(); final VPoint pos = entry.getValue();
if (getMeasurementArea().contains(pos)) { if (getMeasurementArea().asVRectangle().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId)); sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId));
pedCount++; pedCount++;
} }
......
...@@ -8,8 +8,10 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager; ...@@ -8,8 +8,10 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey; import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramBProcessor; import org.vadere.state.attributes.processor.AttributesFundamentalDiagramBProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor; import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.VTrajectory; import org.vadere.state.simulation.VTrajectory;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.logging.Logger;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -32,7 +34,9 @@ import java.util.Map; ...@@ -32,7 +34,9 @@ import java.util.Map;
@DataProcessorClass() @DataProcessorClass()
public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> { public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> {
private VRectangle measurementArea; private static Logger logger = Logger.getLogger(Topography.class);
private MeasurementArea measurementArea;
private PedestrianTrajectoryProcessor pedestrianTrajectoryProcessor; private PedestrianTrajectoryProcessor pedestrianTrajectoryProcessor;
public FundamentalDiagramBProcessor() { public FundamentalDiagramBProcessor() {
...@@ -44,7 +48,11 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, ...@@ -44,7 +48,11 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
super.init(manager); super.init(manager);
AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes(); AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes();
pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(att.getPedestrianTrajectoryProcessorId()); pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(att.getPedestrianTrajectoryProcessorId());
measurementArea = att.getMeasurementArea(); measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas.");
} }
@Override @Override
...@@ -78,7 +86,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, ...@@ -78,7 +86,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
for(Map.Entry<PedestrianIdKey, VTrajectory> trajectoryEntry : trajectoryMap.entrySet()) { for(Map.Entry<PedestrianIdKey, VTrajectory> trajectoryEntry : trajectoryMap.entrySet()) {
PedestrianIdKey key = trajectoryEntry.getKey(); PedestrianIdKey key = trajectoryEntry.getKey();
VTrajectory trajectory = trajectoryEntry.getValue(); VTrajectory trajectory = trajectoryEntry.getValue();
VTrajectory clone = trajectory.cut(measurementArea); VTrajectory clone = trajectory.cut(measurementArea.asVRectangle());
cutTrajectoryMap.put(key, clone); cutTrajectoryMap.put(key, clone);
} }
...@@ -109,7 +117,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, ...@@ -109,7 +117,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
.sum(); .sum();
densityIntegral /= duration; densityIntegral /= duration;
densityIntegral /= measurementArea.getArea(); densityIntegral /= measurementArea.asVRectangle().getArea();
return densityIntegral; return densityIntegral;
/*List<Triple<Double, Double, Integer>> integralValues = new LinkedList<>(); /*List<Triple<Double, Double, Integer>> integralValues = new LinkedList<>();
......
...@@ -9,6 +9,7 @@ import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey; ...@@ -9,6 +9,7 @@ import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramCProcessor; import org.vadere.state.attributes.processor.AttributesFundamentalDiagramCProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor; import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
/** /**
...@@ -25,7 +26,8 @@ import org.vadere.util.geometry.shapes.VRectangle; ...@@ -25,7 +26,8 @@ import org.vadere.util.geometry.shapes.VRectangle;
@DataProcessorClass() @DataProcessorClass()
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> { public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> {
private VRectangle measurementArea; private MeasurementArea measurementArea;
private APedestrianVelocityProcessor pedestrianVelocityProcessor; private APedestrianVelocityProcessor pedestrianVelocityProcessor;
public FundamentalDiagramCProcessor() { public FundamentalDiagramCProcessor() {
...@@ -36,8 +38,12 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, ...@@ -36,8 +38,12 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes(); AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes();
measurementArea = att.getMeasurementArea(); measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId()); pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas.");
} }
@Override @Override
...@@ -58,11 +64,11 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, ...@@ -58,11 +64,11 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
pedestrianVelocityProcessor.update(state); pedestrianVelocityProcessor.update(state);
long N = state.getTopography().getPedestrianDynamicElements().getElements() long N = state.getTopography().getPedestrianDynamicElements().getElements()
.stream() .stream()
.filter(pedestrian -> measurementArea.contains(pedestrian.getPosition())) .filter(pedestrian -> measurementArea.asVRectangle().contains(pedestrian.getPosition()))
.count(); .count();
double velocity = state.getTopography().getPedestrianDynamicElements().getElements() double velocity = state.getTopography().getPedestrianDynamicElements().getElements()
.stream() .stream()
.filter(pedestrian -> measurementArea.contains(pedestrian.getPosition())) .filter(pedestrian -> measurementArea.asVRectangle().contains(pedestrian.getPosition()))
.mapToDouble(pedestrian -> .mapToDouble(pedestrian ->
//pedestrian.getVelocity().getLength() //pedestrian.getVelocity().getLength()
pedestrianVelocityProcessor.getValue(new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId())) pedestrianVelocityProcessor.getValue(new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()))
...@@ -76,7 +82,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, ...@@ -76,7 +82,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
velocity /= N; velocity /= N;
} }
double density = N / measurementArea.getArea(); double density = N / measurementArea.asVRectangle().getArea();
putValue(new TimestepKey(state.getStep()), Pair.of(velocity, density)); putValue(new TimestepKey(state.getStep()), Pair.of(velocity, density));
} }
......
...@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager; ...@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramDProcessor; import org.vadere.state.attributes.processor.AttributesFundamentalDiagramDProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor; import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
/** /**
...@@ -38,7 +39,17 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double, ...@@ -38,7 +39,17 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager); super.init(manager);
AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes(); AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId()); pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm(key -> pedestrianVelocityProcessor.getValue(key), att.getMeasurementArea(), att.getVoronoiArea()); MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId());
if (measurementArea == null || voronoiMeasurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular() || !voronoiMeasurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key),
measurementArea,
voronoiMeasurementArea);
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager; ...@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramEProcessor; import org.vadere.state.attributes.processor.AttributesFundamentalDiagramEProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor; import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;