Commit 208cd179 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Added class "WaitInAreaEvent" and use it in "Simulation" instead of...

Added class "WaitInAreaEvent" and use it in "Simulation" instead of "WaitEvent" to test scenario files.

Notes:
- Currently, event handling is performed by "OptimalStepsModel".
- In the long run this should be done by agents themselves.
- Then, the model classes can remain unchanged.
parent 2bea7847
Pipeline #62800 passed with stage
in 52 seconds
{
"name" : "events_wait_in_area",
"description" : "",
"release" : "0.2",
"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" : {
"standardDerivation" : 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" : 100.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" : 30.0,
"height" : 15.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true
},
"obstacles" : [ ],
"stairs" : [ ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 26.9,
"y" : 8.9,
"width" : 2.0,
"height" : 5.1,
"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" : 27.2,
"y" : 0.9,
"width" : 1.8,
"height" : 5.1,
"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" : 1.0,
"width" : 2.0,
"height" : 5.0,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 1,
"maxSpawnNumberTotal" : 10,
"startTime" : 0.0,
"endTime" : 100.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : false,
"targetIds" : [ 2 ],
"groupSizeDistribution" : [ 0.0, 0.0, 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
}, {
"id" : -1,
"shape" : {
"x" : 1.1,
"y" : 9.1,
"width" : 1.9,
"height" : 4.9,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 1,
"maxSpawnNumberTotal" : 10,
"startTime" : 0.0,
"endTime" : 100.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : false,
"targetIds" : [ 1 ],
"groupSizeDistribution" : [ 0.0, 0.0, 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
},
"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
}
}
}
}
}
......@@ -16,6 +16,7 @@ import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.ElapsedTimeEvent;
import org.vadere.state.events.Event;
import org.vadere.state.events.WaitEvent;
import org.vadere.state.events.WaitInAreaEvent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Target;
......@@ -258,7 +259,7 @@ public class Simulation {
EventFactory eventFactory = new EventFactory();
if (simTimeInSec >= 5 && simTimeInSec <= 30) {
events.add(eventFactory.getEvent(WaitEvent.class, simTimeInSec));
events.add(eventFactory.getEvent(WaitInAreaEvent.class, simTimeInSec));
} else {
events.add(eventFactory.getEvent(ElapsedTimeEvent.class, simTimeInSec));
}
......
......@@ -4,6 +4,9 @@ package org.vadere.simulator.control.events;
import org.vadere.state.events.ElapsedTimeEvent;
import org.vadere.state.events.Event;
import org.vadere.state.events.WaitEvent;
import org.vadere.state.events.WaitInAreaEvent;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
/**
* This class is used to create events from @see org.vadere.state.events package.
......@@ -22,7 +25,12 @@ public class EventFactory {
currentEvent = new ElapsedTimeEvent(time);
} else if (clazz.equals(WaitEvent.class)) {
currentEvent = new WaitEvent(time);
} else {
} else if (clazz.equals(WaitInAreaEvent.class)) {
// TODO Replace dummy area here.
VShape area = new VRectangle(12.5, 0, 5, 6);
currentEvent = new WaitInAreaEvent(time, area);
}
else {
throw new IllegalArgumentException("Class type not supported: " + clazz.getName());
}
......
......@@ -32,6 +32,7 @@ import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.ElapsedTimeEvent;
import org.vadere.state.events.Event;
import org.vadere.state.events.WaitEvent;
import org.vadere.state.events.WaitInAreaEvent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.DynamicElementRemoveListener;
import org.vadere.state.scenario.Pedestrian;
......@@ -276,12 +277,41 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami
handleElapsedTimeEvent(event);
} else if (event instanceof WaitEvent) {
handleWaitEvent(event);
} else if (event instanceof WaitInAreaEvent) {
handleWaitInAreaEvent(event);
} else {
throw new IllegalArgumentException("Cannot handle event: " + event);
}
}
}
private void handleWaitInAreaEvent(Event event) {
if (!(event instanceof WaitInAreaEvent)) {
throw new IllegalArgumentException("Wrong event type passed, expected: " + WaitInAreaEvent.class.getName());
}
WaitInAreaEvent waitInAreaEvent = (WaitInAreaEvent)event;
List<PedestrianOSM> pedestrians = ListUtils.select(
topography.getElements(Pedestrian.class), PedestrianOSM.class);
// Respect update type even if all pedestrians do not move.
if (attributesOSM.getUpdateType() == UpdateType.SHUFFLE) {
Collections.shuffle(pedestrians, this.random);
}
// TODO If pedestrian in area wait, else step.
for (PedestrianOSM pedestrian : pedestrians) {
if (waitInAreaEvent.getArea().contains(pedestrian.getPosition())) { // Wait
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
this.lastSimTimeInSec = waitInAreaEvent.getTime();
} else { // Step
update(event.getTime());
}
}
}
private void handleElapsedTimeEvent(final Event event) {
if (!(event instanceof ElapsedTimeEvent)) {
throw new IllegalArgumentException("Wrong event type passed, expected: " + ElapsedTimeEvent.class.getName());
......
package org.vadere.state.events;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.util.geometry.shapes.VShape;
import java.util.List;
/**
* This event hold as addtional information:
* - An area in which the event is valid.
*/
public class WaitInAreaEvent extends Event {
private VShape area;
public WaitInAreaEvent(double time) {
super(time);
}
public WaitInAreaEvent(double time, VShape area) {
super(time);
this.area = area;
}
public WaitInAreaEvent(double time, List<ScenarioElement> targets) {
super(time, targets);
}
public VShape getArea() {
return area;
}
public void setArea(VShape area) {
this.area = area;
}
}
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