From 5fa69f1f367105339333cb3d693be8c7d52296ad Mon Sep 17 00:00:00 2001 From: Benedikt Kleinmeier Date: Mon, 18 Feb 2019 10:15:39 +0100 Subject: [PATCH] In "EventController", include start AND end time boundary when checking if timeframe is active. Added two additional test scenarios: - wait_event_2_sources_2_targets_osm_event_driven.scenario - wait_event_recurring_2_sources_2_targets_osm_sequential.scenario VadereSimulator/tests/org/vadere/simulator/control/events/EventControllerTest.java: - Adapted unit tests for this logical change. --- ...ources_2_targets_osm_event_driven.scenario | 234 ++++++++++++++++++ ..._sources_2_targets_osm_sequential.scenario | 234 ++++++++++++++++++ .../control/events/EventController.java | 21 +- .../control/events/EventControllerTest.java | 4 +- 4 files changed, 480 insertions(+), 13 deletions(-) create mode 100644 VadereModelTests/TestEvents/scenarios/wait_event_2_sources_2_targets_osm_event_driven.scenario create mode 100644 VadereModelTests/TestEvents/scenarios/wait_event_recurring_2_sources_2_targets_osm_sequential.scenario diff --git a/VadereModelTests/TestEvents/scenarios/wait_event_2_sources_2_targets_osm_event_driven.scenario b/VadereModelTests/TestEvents/scenarios/wait_event_2_sources_2_targets_osm_event_driven.scenario new file mode 100644 index 000000000..ef6d475d1 --- /dev/null +++ b/VadereModelTests/TestEvents/scenarios/wait_event_2_sources_2_targets_osm_event_driven.scenario @@ -0,0 +1,234 @@ +{ + "name" : "wait_event_2_sources_2_targets_osm_event_driven", + "description" : "", + "release" : "0.7", + "processWriters" : { + "files" : [ { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile", + "filename" : "density.txt", + "processors" : [ 1 ] + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile", + "filename" : "out.txt", + "processors" : [ 3 ] + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile", + "filename" : "out1.txt", + "processors" : [ 4 ] + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile", + "filename" : "postvis.trajectories", + "processors" : [ 1, 2 ] + } ], + "processors" : [ { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianDensityCountingProcessor", + "id" : 1, + "attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianDensityCountingProcessor", + "attributes" : { + "pedestrianPositionProcessorId" : 2, + "radius" : 1.5 + } + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor", + "id" : 2 + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor", + "id" : 3 + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor", + "id" : 4, + "attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor", + "attributes" : { + "pedestrianOverlapProcessorId" : 3 + } + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.MaxOverlapProcessor", + "id" : 5, + "attributesType" : "org.vadere.state.attributes.processor.AttributesMaxOverlapProcessor", + "attributes" : { + "pedestrianOverlapProcessorId" : 3 + } + } ], + "isTimestamped" : true, + "isWriteMetaData" : false + }, + "scenario" : { + "mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel", + "attributesModel" : { + "org.vadere.state.attributes.models.AttributesFloorField" : { + "createMethod" : "HIGH_ACCURACY_FAST_MARCHING", + "potentialFieldResolution" : 0.1, + "obstacleGridPenalty" : 0.1, + "targetAttractionStrength" : 1.0, + "timeCostAttributes" : { + "standardDeviation" : 0.7, + "type" : "UNIT", + "obstacleDensityWeight" : 3.5, + "pedestrianSameTargetDensityWeight" : 3.5, + "pedestrianOtherTargetDensityWeight" : 3.5, + "pedestrianWeight" : 3.5, + "queueWidthLoading" : 1.0, + "pedestrianDynamicWeight" : 6.0, + "loadingType" : "CONSTANT" + } + }, + "org.vadere.state.attributes.models.AttributesOSM" : { + "stepCircleResolution" : 18, + "numberOfCircles" : 1, + "optimizationType" : "DISCRETE", + "varyStepDirection" : false, + "movementType" : "ARBITRARY", + "stepLengthIntercept" : 0.4625, + "stepLengthSlopeSpeed" : 0.2345, + "stepLengthSD" : 0.036, + "movementThreshold" : 0.0, + "minStepLength" : 0.4625, + "minimumStepLength" : false, + "maxStepDuration" : 1.7976931348623157E308, + "dynamicStepLength" : false, + "updateType" : "EVENT_DRIVEN", + "seeSmallWalls" : false, + "targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid", + "pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell", + "obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell", + "submodels" : [ ] + }, + "org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : { + "pedPotentialIntimateSpaceWidth" : 0.45, + "pedPotentialPersonalSpaceWidth" : 1.2, + "pedPotentialHeight" : 50.0, + "obstPotentialWidth" : 0.8, + "obstPotentialHeight" : 6.0, + "intimateSpaceFactor" : 1.2, + "personalSpacePower" : 1, + "intimateSpacePower" : 1 + } + }, + "attributesSimulation" : { + "finishTime" : 150.0, + "simTimeStepLength" : 0.4, + "realTimeSimTimeRatio" : 0.0, + "writeSimulationData" : true, + "visualizationEnabled" : true, + "printFPS" : false, + "digitsPerCoordinate" : 2, + "useFixedSeed" : true, + "fixedSeed" : 1, + "simulationSeed" : 1 + }, + "topography" : { + "attributes" : { + "bounds" : { + "x" : 0.0, + "y" : 0.0, + "width" : 40.0, + "height" : 16.0 + }, + "boundingBoxWidth" : 0.5, + "bounded" : true + }, + "obstacles" : [ ], + "stairs" : [ ], + "targets" : [ { + "id" : 1, + "absorbing" : true, + "shape" : { + "x" : 36.0, + "y" : 10.5, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "waitingTime" : 0.0, + "waitingTimeYellowPhase" : 0.0, + "parallelWaiters" : 0, + "individualWaiting" : true, + "deletionDistance" : 0.1, + "startingWithRedLight" : false, + "nextSpeed" : -1.0 + }, { + "id" : 2, + "absorbing" : true, + "shape" : { + "x" : 36.0, + "y" : 1.0, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "waitingTime" : 0.0, + "waitingTimeYellowPhase" : 0.0, + "parallelWaiters" : 0, + "individualWaiting" : true, + "deletionDistance" : 0.1, + "startingWithRedLight" : false, + "nextSpeed" : -1.0 + } ], + "sources" : [ { + "id" : 1, + "shape" : { + "x" : 1.0, + "y" : 10.5, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution", + "distributionParameters" : [ 1.0 ], + "spawnNumber" : 10, + "maxSpawnNumberTotal" : -1, + "startTime" : 0.0, + "endTime" : 0.0, + "spawnAtRandomPositions" : false, + "useFreeSpaceOnly" : true, + "targetIds" : [ 1 ], + "groupSizeDistribution" : [ 1.0 ], + "dynamicElementType" : "PEDESTRIAN" + }, { + "id" : 2, + "shape" : { + "x" : 1.0, + "y" : 1.0, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution", + "distributionParameters" : [ 1.0 ], + "spawnNumber" : 10, + "maxSpawnNumberTotal" : -1, + "startTime" : 0.0, + "endTime" : 0.0, + "spawnAtRandomPositions" : false, + "useFreeSpaceOnly" : true, + "targetIds" : [ 2 ], + "groupSizeDistribution" : [ 1.0 ], + "dynamicElementType" : "PEDESTRIAN" + } ], + "dynamicElements" : [ ], + "attributesPedestrian" : { + "radius" : 0.195, + "densityDependentSpeed" : false, + "speedDistributionMean" : 1.34, + "speedDistributionStandardDeviation" : 0.26, + "minimumSpeed" : 0.5, + "maximumSpeed" : 2.2, + "acceleration" : 2.0 + }, + "teleporter" : null, + "attributesCar" : null + }, + "eventInfos" : [ { + "eventTimeframe" : { + "startTime" : 10.0, + "endTime" : 60.0, + "repeat" : false, + "waitTimeBetweenRepetition" : 0.0 + }, + "events" : [ { + "type" : "WaitEvent", + "targets" : [ ] + } ] + } ] + } +} \ No newline at end of file diff --git a/VadereModelTests/TestEvents/scenarios/wait_event_recurring_2_sources_2_targets_osm_sequential.scenario b/VadereModelTests/TestEvents/scenarios/wait_event_recurring_2_sources_2_targets_osm_sequential.scenario new file mode 100644 index 000000000..baa6b3b5d --- /dev/null +++ b/VadereModelTests/TestEvents/scenarios/wait_event_recurring_2_sources_2_targets_osm_sequential.scenario @@ -0,0 +1,234 @@ +{ + "name" : "wait_event_recurring_2_sources_2_targets_osm_sequential", + "description" : "", + "release" : "0.7", + "processWriters" : { + "files" : [ { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile", + "filename" : "density.txt", + "processors" : [ 1 ] + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile", + "filename" : "out.txt", + "processors" : [ 3 ] + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile", + "filename" : "out1.txt", + "processors" : [ 4 ] + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile", + "filename" : "postvis.trajectories", + "processors" : [ 1, 2 ] + } ], + "processors" : [ { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianDensityCountingProcessor", + "id" : 1, + "attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianDensityCountingProcessor", + "attributes" : { + "pedestrianPositionProcessorId" : 2, + "radius" : 1.5 + } + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor", + "id" : 2 + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor", + "id" : 3 + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor", + "id" : 4, + "attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor", + "attributes" : { + "pedestrianOverlapProcessorId" : 3 + } + }, { + "type" : "org.vadere.simulator.projects.dataprocessing.processor.MaxOverlapProcessor", + "id" : 5, + "attributesType" : "org.vadere.state.attributes.processor.AttributesMaxOverlapProcessor", + "attributes" : { + "pedestrianOverlapProcessorId" : 3 + } + } ], + "isTimestamped" : true, + "isWriteMetaData" : false + }, + "scenario" : { + "mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel", + "attributesModel" : { + "org.vadere.state.attributes.models.AttributesFloorField" : { + "createMethod" : "HIGH_ACCURACY_FAST_MARCHING", + "potentialFieldResolution" : 0.1, + "obstacleGridPenalty" : 0.1, + "targetAttractionStrength" : 1.0, + "timeCostAttributes" : { + "standardDeviation" : 0.7, + "type" : "UNIT", + "obstacleDensityWeight" : 3.5, + "pedestrianSameTargetDensityWeight" : 3.5, + "pedestrianOtherTargetDensityWeight" : 3.5, + "pedestrianWeight" : 3.5, + "queueWidthLoading" : 1.0, + "pedestrianDynamicWeight" : 6.0, + "loadingType" : "CONSTANT" + } + }, + "org.vadere.state.attributes.models.AttributesOSM" : { + "stepCircleResolution" : 18, + "numberOfCircles" : 1, + "optimizationType" : "DISCRETE", + "varyStepDirection" : false, + "movementType" : "ARBITRARY", + "stepLengthIntercept" : 0.4625, + "stepLengthSlopeSpeed" : 0.2345, + "stepLengthSD" : 0.036, + "movementThreshold" : 0.0, + "minStepLength" : 0.4625, + "minimumStepLength" : false, + "maxStepDuration" : 1.7976931348623157E308, + "dynamicStepLength" : false, + "updateType" : "SEQUENTIAL", + "seeSmallWalls" : false, + "targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid", + "pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell", + "obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell", + "submodels" : [ ] + }, + "org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : { + "pedPotentialIntimateSpaceWidth" : 0.45, + "pedPotentialPersonalSpaceWidth" : 1.2, + "pedPotentialHeight" : 50.0, + "obstPotentialWidth" : 0.8, + "obstPotentialHeight" : 6.0, + "intimateSpaceFactor" : 1.2, + "personalSpacePower" : 1, + "intimateSpacePower" : 1 + } + }, + "attributesSimulation" : { + "finishTime" : 150.0, + "simTimeStepLength" : 0.4, + "realTimeSimTimeRatio" : 0.0, + "writeSimulationData" : true, + "visualizationEnabled" : true, + "printFPS" : false, + "digitsPerCoordinate" : 2, + "useFixedSeed" : true, + "fixedSeed" : 1, + "simulationSeed" : 1 + }, + "topography" : { + "attributes" : { + "bounds" : { + "x" : 0.0, + "y" : 0.0, + "width" : 40.0, + "height" : 16.0 + }, + "boundingBoxWidth" : 0.5, + "bounded" : true + }, + "obstacles" : [ ], + "stairs" : [ ], + "targets" : [ { + "id" : 1, + "absorbing" : true, + "shape" : { + "x" : 36.0, + "y" : 10.5, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "waitingTime" : 0.0, + "waitingTimeYellowPhase" : 0.0, + "parallelWaiters" : 0, + "individualWaiting" : true, + "deletionDistance" : 0.1, + "startingWithRedLight" : false, + "nextSpeed" : -1.0 + }, { + "id" : 2, + "absorbing" : true, + "shape" : { + "x" : 36.0, + "y" : 1.0, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "waitingTime" : 0.0, + "waitingTimeYellowPhase" : 0.0, + "parallelWaiters" : 0, + "individualWaiting" : true, + "deletionDistance" : 0.1, + "startingWithRedLight" : false, + "nextSpeed" : -1.0 + } ], + "sources" : [ { + "id" : 1, + "shape" : { + "x" : 1.0, + "y" : 10.5, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution", + "distributionParameters" : [ 1.0 ], + "spawnNumber" : 10, + "maxSpawnNumberTotal" : -1, + "startTime" : 0.0, + "endTime" : 0.0, + "spawnAtRandomPositions" : false, + "useFreeSpaceOnly" : true, + "targetIds" : [ 1 ], + "groupSizeDistribution" : [ 1.0 ], + "dynamicElementType" : "PEDESTRIAN" + }, { + "id" : 2, + "shape" : { + "x" : 1.0, + "y" : 1.0, + "width" : 2.5, + "height" : 4.5, + "type" : "RECTANGLE" + }, + "interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution", + "distributionParameters" : [ 1.0 ], + "spawnNumber" : 10, + "maxSpawnNumberTotal" : -1, + "startTime" : 0.0, + "endTime" : 0.0, + "spawnAtRandomPositions" : false, + "useFreeSpaceOnly" : true, + "targetIds" : [ 2 ], + "groupSizeDistribution" : [ 1.0 ], + "dynamicElementType" : "PEDESTRIAN" + } ], + "dynamicElements" : [ ], + "attributesPedestrian" : { + "radius" : 0.195, + "densityDependentSpeed" : false, + "speedDistributionMean" : 1.34, + "speedDistributionStandardDeviation" : 0.26, + "minimumSpeed" : 0.5, + "maximumSpeed" : 2.2, + "acceleration" : 2.0 + }, + "teleporter" : null, + "attributesCar" : null + }, + "eventInfos" : [ { + "eventTimeframe" : { + "startTime" : 0.0, + "endTime" : 10.0, + "repeat" : true, + "waitTimeBetweenRepetition" : 10.0 + }, + "events" : [ { + "type" : "WaitEvent", + "targets" : [ ] + } ] + } ] + } +} \ No newline at end of file diff --git a/VadereSimulator/src/org/vadere/simulator/control/events/EventController.java b/VadereSimulator/src/org/vadere/simulator/control/events/EventController.java index cb3df444b..265e4f69a 100644 --- a/VadereSimulator/src/org/vadere/simulator/control/events/EventController.java +++ b/VadereSimulator/src/org/vadere/simulator/control/events/EventController.java @@ -16,7 +16,8 @@ import java.util.stream.Collectors; * The EventController uses the passed {@link ScenarioStore} * to extract the possible events from the scenario description. * - * TODO Clarify what happens if "simTimeSteps" are too big. + * TODO: Clarify what should happen if "simTimeSteps" is too coarse + * and defined events cannot be triggered correctly here. */ public class EventController { @@ -96,16 +97,14 @@ public class EventController { } /** - * Return if "simulationTime" is in interval [startTime, endTime) of given "timeframe". + * Return if "simulationTime" is in interval [startTime, endTime] of given "timeframe". * - * TODO: Maybe, including boundaries, i.e. [startTime, endTime], is more intuitive. Check if this causes problems. - * * @throws IllegalArgumentException If given timeframe is a recurring one. */ public static boolean oneTimeTimeframeIsActiveAtSimulationTime(EventTimeframe timeframe, double simulationTime) { throwExceptionIfTimeframeIsInvalid(timeframe, false); - boolean eventIsActive = (simulationTime >= timeframe.getStartTime() && simulationTime < timeframe.getEndTime()); + boolean eventIsActive = (simulationTime >= timeframe.getStartTime() && simulationTime <= timeframe.getEndTime()); return eventIsActive; } @@ -127,12 +126,12 @@ public class EventController { * waitTimeBetweenRepetition = 1.0 * simulationTime = 0.8 * - * That means, the timeframe is active in following intervals (end time is excluded!): + * That means, the timeframe is active in following intervals (end time is included!): * - * [0.75 -- 1.25) - * [2.25 -- 2.75) - * [3.75 -- 4.25) - * [5.25 -- 5.75) + * [0.75 -- 1.25] + * [2.25 -- 2.75] + * [3.75 -- 4.25] + * [5.25 -- 5.75] * ... * * Now, if this method gets "simulationTime = 0.8", the method should detect that the timeframe @@ -153,7 +152,7 @@ public class EventController { double eventStartTimeCurrentPeriod = timeframe.getStartTime() + (currentPeriod * eventPeriodLength); double eventEndTimeCurrentPeriod = eventStartTimeCurrentPeriod + eventLength; - boolean eventIsActive = (simulationTime >= eventStartTimeCurrentPeriod && simulationTime < eventEndTimeCurrentPeriod); + boolean eventIsActive = (simulationTime >= eventStartTimeCurrentPeriod && simulationTime <= eventEndTimeCurrentPeriod); return eventIsActive; } diff --git a/VadereSimulator/tests/org/vadere/simulator/control/events/EventControllerTest.java b/VadereSimulator/tests/org/vadere/simulator/control/events/EventControllerTest.java index be4c8f5a0..fd0ab1ec0 100644 --- a/VadereSimulator/tests/org/vadere/simulator/control/events/EventControllerTest.java +++ b/VadereSimulator/tests/org/vadere/simulator/control/events/EventControllerTest.java @@ -156,7 +156,7 @@ public class EventControllerTest { } @Test - public void timeframeIsActiveAtSimulationTimeReturnsFalseIfSimulationTimeFallsOntoEndTimePeriodically() { + public void timeframeIsActiveAtSimulationTimeReturnsTrueIfSimulationTimeFallsOntoEndTimePeriodically() { boolean recurringEvent = true; double startTime = 0.75; double endTime = 1.25; @@ -170,7 +170,7 @@ public class EventControllerTest { double currentSimulationTime = simulationTime + (i * periodicity); boolean timeframeIsActive = EventController.timeframeIsActiveAtSimulationTime(timeframe, currentSimulationTime); - assertFalse(timeframeIsActive); + assertTrue(timeframeIsActive); } } -- GitLab