Commit e76fa360 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Handle "WaitInAreaEvent" in "CognitionLayer.java" and "UpdateScheme(EventDriven|Sequential).java".

parent cad83b9a
Pipeline #75060 failed with stages
in 170 minutes and 19 seconds
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
"eventInfos" : [ { "eventInfos" : [ {
"eventTimeframe" : { "eventTimeframe" : {
"startTime" : 10.0, "startTime" : 10.0,
"endTime" : 30.0, "endTime" : 60.0,
"repeat" : false, "repeat" : false,
"waitTimeBetweenRepetition" : 0.0 "waitTimeBetweenRepetition" : 0.0
}, },
......
...@@ -3,6 +3,7 @@ package org.vadere.simulator.control.cognition; ...@@ -3,6 +3,7 @@ package org.vadere.simulator.control.cognition;
import org.vadere.state.events.types.ElapsedTimeEvent; import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event; import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.WaitEvent; import org.vadere.state.events.types.WaitEvent;
import org.vadere.state.events.types.WaitInAreaEvent;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import java.util.Collection; import java.util.Collection;
...@@ -19,22 +20,33 @@ public class CognitionLayer { ...@@ -19,22 +20,33 @@ public class CognitionLayer {
for (Pedestrian pedestrian : pedestrians) { for (Pedestrian pedestrian : pedestrians) {
// TODO: prioritize the events for the current time step for each pedestrian individually. // TODO: prioritize the events for the current time step for each pedestrian individually.
// by using a finite state machine, weight pedestrian's attributes or any other good mechanism. // by using a finite state machine, weight pedestrian's attributes or any other good mechanism.
Event mostImportantEvent = rankWaitHigherThanElapsedTime(events); Event mostImportantEvent = rankWaitHigherThanElapsedTime(events, pedestrian);
pedestrian.setMostImportantEvent(mostImportantEvent); pedestrian.setMostImportantEvent(mostImportantEvent);
} }
} }
private Event rankWaitHigherThanElapsedTime(List<Event> events) { private Event rankWaitHigherThanElapsedTime(List<Event> events, Pedestrian pedestrian) {
// TODO: replace dummy implementation here. // TODO: replace dummy implementation here.
Event mostImportantEvent = null; Event mostImportantEvent = events.stream()
.filter(event -> event instanceof ElapsedTimeEvent)
.collect(Collectors.toList())
.get(0);
List<Event> waitEvents = events.stream().filter(event -> event instanceof WaitEvent).collect(Collectors.toList()); List<Event> waitEvents = events.stream().filter(event -> event instanceof WaitEvent).collect(Collectors.toList());
List<Event> waitInAreaEvents = events.stream().filter(event -> event instanceof WaitInAreaEvent).collect(Collectors.toList());
if (waitEvents.size() >= 1) { if (waitEvents.size() >= 1) {
mostImportantEvent = waitEvents.get(0); mostImportantEvent = waitEvents.get(0);
} else { } else if (waitInAreaEvents.size() >= 1) {
List<Event> elapsedTimeEvents = events.stream().filter(event -> event instanceof ElapsedTimeEvent).collect(Collectors.toList()); for (Event event : waitInAreaEvents) {
mostImportantEvent = elapsedTimeEvents.get(0); WaitInAreaEvent waitInAreaEvent = (WaitInAreaEvent) event;
boolean pedInArea = waitInAreaEvent.getArea().contains(pedestrian.getPosition());
if (pedInArea) {
mostImportantEvent = waitInAreaEvent;
}
}
} }
return mostImportantEvent; return mostImportantEvent;
......
...@@ -3,6 +3,9 @@ package org.vadere.simulator.models.osm.updateScheme; ...@@ -3,6 +3,9 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM; import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.events.types.ElapsedTimeEvent; import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.WaitEvent;
import org.vadere.state.events.types.WaitInAreaEvent;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
...@@ -42,7 +45,9 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM { ...@@ -42,7 +45,9 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
} }
protected void update(@NotNull final PedestrianOSM pedestrian, final double currentTimeInSec) { protected void update(@NotNull final PedestrianOSM pedestrian, final double currentTimeInSec) {
if (pedestrian.getMostImportantEvent() instanceof ElapsedTimeEvent) { Event mostImportantEvent = pedestrian.getMostImportantEvent();
if (mostImportantEvent instanceof ElapsedTimeEvent) {
VPoint oldPosition = pedestrian.getPosition(); VPoint oldPosition = pedestrian.getPosition();
// for the first step after creation, timeOfNextStep has to be initialized // for the first step after creation, timeOfNextStep has to be initialized
...@@ -57,7 +62,7 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM { ...@@ -57,7 +62,7 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep()); pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
topography.moveElement(pedestrian, oldPosition); topography.moveElement(pedestrian, oldPosition);
} else { } else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep()); pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
} }
} }
......
...@@ -3,6 +3,9 @@ package org.vadere.simulator.models.osm.updateScheme; ...@@ -3,6 +3,9 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM; import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.events.types.ElapsedTimeEvent; import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.WaitEvent;
import org.vadere.state.events.types.WaitInAreaEvent;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
...@@ -30,7 +33,9 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM { ...@@ -30,7 +33,9 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
} }
protected void update(@NotNull final PedestrianOSM pedestrian, final double timeStepInSec) { protected void update(@NotNull final PedestrianOSM pedestrian, final double timeStepInSec) {
if (pedestrian.getMostImportantEvent() instanceof ElapsedTimeEvent) { Event mostImportantEvent = pedestrian.getMostImportantEvent();
if (mostImportantEvent instanceof ElapsedTimeEvent) {
VPoint oldPosition = pedestrian.getPosition(); VPoint oldPosition = pedestrian.getPosition();
pedestrian.clearStrides(); pedestrian.clearStrides();
pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec); pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
...@@ -43,7 +48,7 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM { ...@@ -43,7 +48,7 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
} }
topography.moveElement(pedestrian, oldPosition); topography.moveElement(pedestrian, oldPosition);
} else { } else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep()); pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
} }
} }
......
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