Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 94c9fd07 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "Simulation", use new class "CognitionLayer" to prioritize events for each pedestrian.

VadereSimulator/src/org/vadere/simulator/models/Model.java:
- Removed method "update(final List<Event> events)".

VadereSimulator/src/org/vadere/simulator/models/osm/OptimalStepsModel.java:
- Removed unnecessary methods (used for original proof of concept).
parent c91a7b0a
......@@ -2,6 +2,7 @@ package org.vadere.simulator.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.control.cognition.CognitionLayer;
import org.vadere.simulator.control.events.EventController;
import org.vadere.simulator.control.factory.SourceControllerFactory;
import org.vadere.simulator.models.DynamicElementFactory;
......@@ -70,6 +71,7 @@ public class Simulation {
private final SourceControllerFactory sourceControllerFactory;
private SimulationResult simulationResult;
private final EventController eventController;
private final CognitionLayer cognitionLayer;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager, SimulationResult simulationResult) {
......@@ -97,6 +99,8 @@ public class Simulation {
this.topographyController = new TopographyController(topography, dynamicElementFactory);
this.eventController = new EventController(scenarioStore);
this.cognitionLayer = new CognitionLayer();
// ::start:: this code is to visualize the potential fields. It may be refactored later.
if(attributesSimulation.isVisualizationEnabled()) {
IPotentialFieldTarget pft = null;
......@@ -280,8 +284,8 @@ public class Simulation {
private void updateCallbacks(double simTimeInSec) {
List<Event> events = eventController.getEventsForTime(simTimeInSec);
// TODO: Implement "CognitionLayer" class and use it here, e.g. cognitionLayer(events, pedestrians)
// which calls pedestrian.setBehavior(...) or this methods returns List<Behavior, Pedestrian).
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
cognitionLayer.prioritizeEventsForPedestrians(events, pedestrians);
// TODO Why are target controllers readded in each simulation loop?
this.targetControllers.clear();
......@@ -301,7 +305,7 @@ public class Simulation {
step++;
for (Model m : models) {
m.update(events);
m.update(simTimeInSec);
}
if (topographyController.getTopography().hasTeleporter()) {
......
......@@ -5,6 +5,7 @@ import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.WaitEvent;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
......@@ -14,7 +15,7 @@ import java.util.stream.Collectors;
*/
public class CognitionLayer {
public void prioritizeEventsForPedestrians(List<Event> events, List<Pedestrian> pedestrians){
public void prioritizeEventsForPedestrians(List<Event> events, Collection<Pedestrian> pedestrians){
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.
......
......@@ -33,15 +33,6 @@ public interface Model {
void update(final double simTimeInSec);
default void update(final List<Event> events) {
// In the first run, ignore everything else "ElapsedTimeEvent".
for (Event event : events) {
if (event instanceof ElapsedTimeEvent) {
this.update(event.getTime());
}
}
}
static <T extends Attributes> T findAttributes(List<Attributes> attributesList, final Class<T> type) {
try {
final T a = FindByClass.findSingleObjectOfClass(attributesList, type);
......
......@@ -234,40 +234,12 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami
@Override
public void update(final double simTimeInSec) {
// TODO: handle each pedestrian individually based on its "mostImportantEvent".
double timeStepInSec = simTimeInSec - this.lastSimTimeInSec;
updateSchemeOSM.update(timeStepInSec, simTimeInSec);
lastSimTimeInSec = simTimeInSec;
}
@Override
public void update(final List<Event> events) {
// TODO: improve proof of concept (prioritize events etc.)
Event mostImportantEvent = prioritizeEvents(events);
if (mostImportantEvent instanceof ElapsedTimeEvent) {
handleElapsedTimeEvent(mostImportantEvent);
} else if (mostImportantEvent instanceof WaitEvent) {
handleWaitEvent(mostImportantEvent);
} else {
throw new IllegalArgumentException("Cannot handle event: " + mostImportantEvent);
}
}
private Event prioritizeEvents(List<Event> events) {
Event mostImportantEvent = null;
List<Event> waitEvents = events.stream().filter(event -> event instanceof WaitEvent).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);
}
return mostImportantEvent;
}
private void handleElapsedTimeEvent(final Event event) {
if (!(event instanceof ElapsedTimeEvent)) {
throw new IllegalArgumentException("Wrong event type passed, expected: " + ElapsedTimeEvent.class.getName());
......
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