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 c91a7b0a authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Added first dummy implementation of class "simulator/control/cognition/CognitionLayer".

This new class interacts with class "Pedestrian". Therefore, added variable "mostImportantEvent" to "Pedestrian" and reformatted this class.
parent 5c2ee366
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.scenario.Pedestrian;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.util.List;
import java.util.stream.Collectors;
/**
* The CognitionLayer class should provide logic to prioritize {@link org.vadere.state.events.types.Event}
* The CognitionLayer class should provide logic to prioritize {@link Event}
* objects based on attributes of a pedestrian.
*/
public class CognitionLayer {
public void prioritizeEvents(List<Event> events, List<Pedestrian> pedestrians){
// TODO: Add "Event" field to class pedestrian and set it here.
throw new NotImplementedException();
public void prioritizeEventsForPedestrians(List<Event> events, List<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.
Event mostImportantEvent = rankWaitHigherThanElapsedTime(events);
pedestrian.setMostImportantEvent(mostImportantEvent);
}
}
private Event rankWaitHigherThanElapsedTime(List<Event> events) {
// TODO: replace dummy implementation here.
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;
}
}
......@@ -26,13 +26,13 @@ public class PedestrianSpeedSetupCheck extends AbstractScenarioCheck implements
") current SpeedDistributionMean is: " + String.format("%.2f", speedMean))
.build());
}
if (p.getAttributes().getMinimumSpeed() > Pedestrian.HUMAN_MAX_SPEED || p.getAttributes().getMaximumSpeed() > Pedestrian.HUMAN_MAX_SPEED) {
if (p.getAttributes().getMinimumSpeed() > Pedestrian.PEDESTRIAN_MAX_SPEED_METER_PER_SECOND || p.getAttributes().getMaximumSpeed() > Pedestrian.PEDESTRIAN_MAX_SPEED_METER_PER_SECOND) {
ret.add(msgBuilder
.topographyWarning()
.target(p)
.reason(ScenarioCheckerReason.PEDESTRIAN_SPEED_NOT_LOGICAL,
String.format("[max: %.2f min: %.2f threshold: %.2f]", p.getAttributes().getMinimumSpeed(),
p.getAttributes().getMaximumSpeed(), Pedestrian.HUMAN_MAX_SPEED))
p.getAttributes().getMaximumSpeed(), Pedestrian.PEDESTRIAN_MAX_SPEED_METER_PER_SECOND))
.build());
}
if (p.getAttributes().getMinimumSpeed() < 0 || p.getAttributes().getMaximumSpeed() < 0) {
......
package org.vadere.state.scenario;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.types.Event;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
import java.util.HashMap;
import java.util.LinkedList;
......@@ -11,22 +11,20 @@ import java.util.Random;
public class Pedestrian extends Agent {
public static double HUMAN_MAX_SPEED = 12.0; // ms^-1
/** Target ID if the pedestrian represents a target, -1 otherwise. */
private int idAsTarget; // TODO should actually be an attribute or a member of a subclass
private Map<Class<? extends ModelPedestrian>, ModelPedestrian> modelPedestrianMap;
// Constants
public static double PEDESTRIAN_MAX_SPEED_METER_PER_SECOND = 12.0;
// Variables
private int idAsTarget; // TODO should actually be an attribute or a member of a subclass
private boolean isChild; // TODO should actually be an attribute or a member of a subclass
private boolean isLikelyInjured; // TODO should actually be an attribute or a member of a subclass
private Event mostImportantEvent; /** Evaluated in each time step in "CognitionLayer". */
private LinkedList<Integer> groupIds; // TODO should actually be an attribute or a member of a subclass
/** Used only for JSON serialization? */
// TODO used at all? Car does NOT have this field. remove if unused!
private ScenarioElementType type = ScenarioElementType.PEDESTRIAN;
private LinkedList<Integer> groupSizes;
private Map<Class<? extends ModelPedestrian>, ModelPedestrian> modelPedestrianMap;
private ScenarioElementType type = ScenarioElementType.PEDESTRIAN; // TODO used at all? For JSON de-/serialization? Car does NOT have this field. remove if unused!
// Constructors
@SuppressWarnings("unused")
private Pedestrian() {
// TODO constructor may be required for Jackson?
......@@ -40,25 +38,22 @@ public class Pedestrian extends Agent {
public Pedestrian(AttributesAgent attributesAgent, Random random) {
super(attributesAgent, random);
modelPedestrianMap = new HashMap<>();
idAsTarget = -1;
isChild = false;
isLikelyInjured = false;
mostImportantEvent = null;
groupIds = new LinkedList<>();
groupSizes = new LinkedList<>();
modelPedestrianMap = new HashMap<>();
}
/**
* Copy constructor, references the same attributes.
*/
private Pedestrian(Pedestrian other) {
super(other);
modelPedestrianMap = new HashMap<>(other.modelPedestrianMap);
isChild = other.isChild;
isLikelyInjured = other.isLikelyInjured;
idAsTarget = other.idAsTarget;
isChild = other.isChild;
isLikelyInjured = other.isLikelyInjured;
mostImportantEvent = other.mostImportantEvent;
if (other.groupIds != null) {
groupIds = new LinkedList<>(other.groupIds);
......@@ -67,77 +62,61 @@ public class Pedestrian extends Agent {
groupIds = new LinkedList<>();
groupSizes = new LinkedList<>();
}
}
public void addGroupId(int groupId, int size){
groupIds.add(groupId);
groupSizes.add(size);
}
public <T extends ModelPedestrian> T getModelPedestrian(Class<? extends T> modelType) {
return (T) modelPedestrianMap.get(modelType);
}
public <T extends ModelPedestrian> ModelPedestrian setModelPedestrian(T modelPedestrian) {
return modelPedestrianMap.put(modelPedestrian.getClass(), modelPedestrian);
}
public void setGroupIds(LinkedList<Integer> groupIds) {
this.groupIds = groupIds;
modelPedestrianMap = new HashMap<>(other.modelPedestrianMap);
}
public void setGroupSizes(LinkedList<Integer> groupSizes) {
this.groupSizes = groupSizes;
// Getter
public int getIdAsTarget() {
return this.idAsTarget;
}
public VShape getInformationShape() {
return null;
public boolean isChild() {
return isChild;
}
public LinkedList<Integer> getGroupIds() {
return groupIds;
public boolean isLikelyInjured() {
return isLikelyInjured;
}
public Event getMostImportantEvent() { return mostImportantEvent; }
public LinkedList<Integer> getGroupIds() { return groupIds; }
public LinkedList<Integer> getGroupSizes() {
return groupSizes;
}
public boolean isTarget() {
return this.idAsTarget != -1;
}
public int getIdAsTarget() {
return this.idAsTarget;
}
public void setIdAsTarget(int id) {
this.idAsTarget = id;
}
public <T extends ModelPedestrian> T getModelPedestrian(Class<? extends T> modelType) { return (T) modelPedestrianMap.get(modelType); }
@Override
public ScenarioElementType getType() {
return ScenarioElementType.PEDESTRIAN;
}
public boolean isChild() {
return isChild;
}
// Setter
public void setIdAsTarget(int id) { this.idAsTarget = id; }
public void setChild(boolean child) {
this.isChild = child;
}
public void setLikelyInjured(boolean likelyInjured) {
this.isLikelyInjured = likelyInjured;
}
public void setMostImportantEvent(Event mostImportantEvent) { this.mostImportantEvent = mostImportantEvent; }
public void setGroupIds(LinkedList<Integer> groupIds) {
this.groupIds = groupIds;
}
public void setGroupSizes(LinkedList<Integer> groupSizes) {
this.groupSizes = groupSizes;
}
public <T extends ModelPedestrian> ModelPedestrian setModelPedestrian(T modelPedestrian) {
return modelPedestrianMap.put(modelPedestrian.getClass(), modelPedestrian);
}
public boolean isLikelyInjured() {
return isLikelyInjured;
// Methods
public boolean isTarget() {
return this.idAsTarget != -1;
}
public void setLikelyInjured(boolean likelyInjured) {
this.isLikelyInjured = likelyInjured;
public void addGroupId(int groupId, int size){
groupIds.add(groupId);
groupSizes.add(size);
}
@Override
public Pedestrian clone() {
return new Pedestrian(this);
}
}
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