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

Commit e76fa360 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

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 @@
"eventInfos" : [ {
"eventTimeframe" : {
"startTime" : 10.0,
"endTime" : 30.0,
"endTime" : 60.0,
"repeat" : false,
"waitTimeBetweenRepetition" : 0.0
},
......
......@@ -3,6 +3,7 @@ package org.vadere.simulator.control.cognition;
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 java.util.Collection;
......@@ -19,22 +20,33 @@ public class CognitionLayer {
for (Pedestrian pedestrian : pedestrians) {
// 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.
Event mostImportantEvent = rankWaitHigherThanElapsedTime(events);
Event mostImportantEvent = rankWaitHigherThanElapsedTime(events, pedestrian);
pedestrian.setMostImportantEvent(mostImportantEvent);
}
}
private Event rankWaitHigherThanElapsedTime(List<Event> events) {
private Event rankWaitHigherThanElapsedTime(List<Event> events, Pedestrian pedestrian) {
// 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> waitInAreaEvents = events.stream().filter(event -> event instanceof WaitInAreaEvent).collect(Collectors.toList());
if (waitEvents.size() >= 1) {
mostImportantEvent = waitEvents.get(0);
} else {
List<Event> elapsedTimeEvents = events.stream().filter(event -> event instanceof ElapsedTimeEvent).collect(Collectors.toList());
mostImportantEvent = elapsedTimeEvents.get(0);
} else if (waitInAreaEvents.size() >= 1) {
for (Event event : waitInAreaEvents) {
WaitInAreaEvent waitInAreaEvent = (WaitInAreaEvent) event;
boolean pedInArea = waitInAreaEvent.getArea().contains(pedestrian.getPosition());
if (pedInArea) {
mostImportantEvent = waitInAreaEvent;
}
}
}
return mostImportantEvent;
......
......@@ -3,6 +3,9 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
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.Topography;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -42,7 +45,9 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
}
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();
// for the first step after creation, timeOfNextStep has to be initialized
......@@ -57,7 +62,7 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
topography.moveElement(pedestrian, oldPosition);
} else {
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
}
......
......@@ -3,6 +3,9 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
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.Topography;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -30,7 +33,9 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
}
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();
pedestrian.clearStrides();
pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
......@@ -43,7 +48,7 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
}
topography.moveElement(pedestrian, oldPosition);
} else {
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
}
......
Markdown is supported
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