Commit 20318bca authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "EventController", implemented added timeframe checks in constructor and...

In "EventController", implemented added timeframe checks in constructor and implemented "getEventsForTime()".
parent 7544295a
Pipeline #65250 failed with stages
in 46 seconds
{
"name" : "events_recurring_wait_events",
"description" : "",
"release" : "0.3",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
"processors" : [ 1, 2 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 1
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianTargetIdProcessor",
"id" : 2
} ],
"isTimestamped" : true
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 18,
"numberOfCircles" : 1,
"varyStepDirection" : false,
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"optimizationType" : "DISCRETE",
"movementType" : "ARBITRARY",
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"minimumStepLength" : 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
},
"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"
}
}
},
"attributesSimulation" : {
"finishTime" : 200.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"needsBoundary" : false,
"digitsPerCoordinate" : 2,
"useRandomSeed" : true,
"randomSeed" : 1
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 200.0,
"height" : 10.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true
},
"obstacles" : [ ],
"stairs" : [ ],
"targets" : [ {
"id" : 2,
"absorbing" : true,
"shape" : {
"x" : 190.9,
"y" : 3.3,
"width" : 1.1,
"height" : 2.3,
"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" : 0.6,
"y" : 3.1,
"width" : 1.0,
"height" : 2.8,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 0.5 ],
"spawnNumber" : 20,
"maxSpawnNumberTotal" : 5,
"startTime" : 0.0,
"endTime" : 100.0,
"spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false,
"targetIds" : [ 2, 1 ],
"groupSizeDistribution" : [ 1.0, 0.0, 0.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
},
"attributesCar" : {
"id" : -1,
"radius" : 0.195,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"length" : 4.5,
"width" : 1.7,
"direction" : {
"x" : 1.0,
"y" : 0.0
}
}
},
"eventInfos" : [ {
"eventTimeframe" : {
"startTime" : 5.0,
"endTime" : 10.0,
"repeat" : true,
"waitTimeBetweenRepetition" : 5.0
},
"events" : [ {
"type" : "WaitEvent",
"targets" : [ ]
} ]
} ]
}
}
\ No newline at end of file
......@@ -15,6 +15,8 @@ import java.util.stream.Collectors;
*
* The EventController uses the passed @see ScenarioStore
* to extract the possible events from the scenario description.
*
* TODO Clarify what happens if "simTimeSteps" are too big.
*/
public class EventController {
......@@ -34,6 +36,9 @@ public class EventController {
recurringEvents = scenarioStore.getEventInfoStore().getEventInfos().stream()
.filter(eventInfo -> eventInfo.getEventTimeframe().isRepeat() == true)
.collect(Collectors.toList());
oneTimeEvents.stream().forEach(eventInfo -> throwExceptionIfTimeframeIsInvalid(eventInfo.getEventTimeframe(), false));
recurringEvents.stream().forEach(eventInfo -> throwExceptionIfTimeframeIsInvalid(eventInfo.getEventTimeframe(), true));
}
// Getters
......@@ -52,47 +57,53 @@ public class EventController {
// Methods
public List<Event> getEventsForTime(double simulationTime) {
// TODO Handle one-time and recurring events properly.
List<Event> events = new ArrayList<>();
// Always, create an "ElapsedTimeEvent".
events.add(new ElapsedTimeEvent(simulationTime));
for (EventInfo eventInfo : scenarioStore.getEventInfoStore().getEventInfos()) {
EventTimeframe eventTimeframe = eventInfo.getEventTimeframe();
List<Event> activeOneTimeEvents = getOneTimeEventsForSimulationTime(simulationTime);
List<Event> activeRecurringEvents = getRecurringEventsForSimulationTime(simulationTime);
if (simulationTime >= eventTimeframe.getStartTime() && simulationTime <= eventTimeframe.getEndTime()) {
events.addAll(eventInfo.getEvents());
}
}
events.addAll(activeOneTimeEvents);
events.addAll(activeRecurringEvents);
return events;
}
public List<Event> getRecurringEventsForSimulationTime(double simulationTime) {
private List<Event> getOneTimeEventsForSimulationTime(double simulationTime) {
List<Event> activeEvents = new ArrayList<>();
for (EventInfo eventInfo : recurringEvents) {
EventTimeframe timeframe = eventInfo.getEventTimeframe();
oneTimeEvents.stream()
.filter(eventInfo -> oneTimeTimeframeIsActiveAtSimulationTime(eventInfo.getEventTimeframe(), simulationTime))
.forEach(eventInfo -> activeEvents.addAll(eventInfo.getEvents()));
double eventLength = timeframe.getEndTime() - timeframe.getStartTime();
double eventFrequency = eventLength + timeframe.getWaitTimeBetweenRepetition();
return activeEvents;
}
// TODO Check if implementation is correct or "if (simulationTime < startTime)" must be introduced.
double normalizedSimulationTime = Math.max(0, Math.floor(simulationTime) - 1);
double startTimeForNextEvent = timeframe.getStartTime() + (normalizedSimulationTime * eventFrequency);
double endTimeForNextEvent = startTimeForNextEvent + eventLength;
private List<Event> getRecurringEventsForSimulationTime(double simulationTime) {
List<Event> activeEvents = new ArrayList<>();
boolean eventIsActive = (simulationTime >= startTimeForNextEvent && simulationTime < endTimeForNextEvent);
if (eventIsActive) {
activeEvents.addAll(eventInfo.getEvents());
}
}
recurringEvents.stream()
.filter(eventInfo -> timeframeIsActiveAtSimulationTime(eventInfo.getEventTimeframe(), simulationTime))
.forEach(eventInfo -> activeEvents.addAll(eventInfo.getEvents()));
return activeEvents;
}
/**
* Return if "simulationTime" is in interval [startTime, endTime) of given "timeframe".
*
* @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());
return eventIsActive;
}
/**
* Given a (recurring) "timeframe" and a "simulationTime" return if the
* timeframe is "active" at that specific "simulationTime" or not.
......@@ -120,11 +131,11 @@ public class EventController {
*
* Now, if this method gets "simulationTime = 0.8", the method should detect that the timeframe
* is active in that given time.
*
* @throws IllegalArgumentException If given timeframe is a one-time timeframe.
*/
public static boolean timeframeIsActiveAtSimulationTime(EventTimeframe timeframe, double simulationTime) {
if (timeframe.isRepeat() == false) {
throw new IllegalArgumentException("EventTimeframe: \"repeat=true\" is required!");
}
throwExceptionIfTimeframeIsInvalid(timeframe, true);
double eventLength = timeframe.getEndTime() - timeframe.getStartTime();
double eventPeriodLength = eventLength + timeframe.getWaitTimeBetweenRepetition();
......@@ -141,4 +152,18 @@ public class EventController {
return eventIsActive;
}
/**
* Throw @see IllegalArgumentException if startTime > endTime OR timeframe does not meet recurring expectation.
*/
private static void throwExceptionIfTimeframeIsInvalid(EventTimeframe timeframe, boolean expectRecurring) {
if (timeframe.getStartTime() > timeframe.getEndTime()) {
throw new IllegalArgumentException("EventTimeframe: startTime > endTime!");
}
if (timeframe.isRepeat() != expectRecurring) {
throw new IllegalArgumentException(String.format("EventTimeframe: \"repeat=%b\" expected!", expectRecurring));
}
}
}
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