1 package org.opentrafficsim.road.gtu.lane.perception.categories;
2
3 import java.util.HashSet;
4 import java.util.Map;
5 import java.util.Set;
6 import java.util.SortedSet;
7 import java.util.TreeSet;
8
9 import org.opentrafficsim.base.TimeStampedObject;
10 import org.opentrafficsim.core.gtu.GTUException;
11 import org.opentrafficsim.core.gtu.RelativePosition;
12 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
13 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
14 import org.opentrafficsim.road.gtu.lane.perception.LaneStructure.Entry;
15 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
16 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayBusStop;
17 import org.opentrafficsim.road.network.lane.conflict.Conflict;
18 import org.opentrafficsim.road.network.lane.object.BusStop;
19
20
21
22
23
24
25
26
27
28
29
30
31 public class DirectBusStopPerception extends LaneBasedAbstractPerceptionCategory implements BusStopPerception
32 {
33
34
35 private static final long serialVersionUID = 20170127;
36
37
38 private TimeStampedObject<SortedSet<HeadwayBusStop>> busStops;
39
40
41
42
43 public DirectBusStopPerception(final LanePerception perception)
44 {
45 super(perception);
46 }
47
48
49 @Override
50 public final void updateBusStops() throws GTUException, ParameterException
51 {
52 SortedSet<HeadwayBusStop> stops = new TreeSet<>();
53 Map<RelativeLane, SortedSet<Entry<BusStop>>> map = getPerception().getLaneStructure().getDownstreamObjectsOnRoute(
54 BusStop.class, getGtu(), RelativePosition.FRONT, getGtu().getStrategicalPlanner().getRoute());
55 for (RelativeLane relativeLane : map.keySet())
56 {
57 for (Entry<BusStop> entry : map.get(relativeLane))
58 {
59 Set<String> conflictIds = new HashSet<>();
60 for (Conflict conflict : entry.getLaneBasedObject().getConflicts())
61 {
62 conflictIds.add(conflict.getId());
63 }
64 stops.add(new HeadwayBusStop(entry.getLaneBasedObject(), entry.getDistance(), relativeLane, conflictIds));
65 }
66 }
67 this.busStops = new TimeStampedObject<>(stops, getTimestamp());
68 }
69
70
71 @Override
72 public final SortedSet<HeadwayBusStop> getBusStops()
73 {
74 return this.busStops.getObject();
75 }
76
77
78
79
80
81 public final TimeStampedObject<SortedSet<HeadwayBusStop>> getTimeStampedBusStops()
82 {
83 return this.busStops;
84 }
85
86
87 @Override
88 public String toString()
89 {
90 return "DirectBusStopPerception";
91 }
92
93 }