1 package org.opentrafficsim.road.gtu.lane.perception.categories;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.Map;
6 import java.util.Set;
7 import java.util.SortedSet;
8
9 import org.opentrafficsim.base.TimeStampedObject;
10 import org.opentrafficsim.base.parameters.ParameterException;
11 import org.opentrafficsim.core.gtu.GTUException;
12 import org.opentrafficsim.core.gtu.Try;
13 import org.opentrafficsim.core.gtu.perception.AbstractPerceptionCategory;
14 import org.opentrafficsim.core.network.LateralDirectionality;
15 import org.opentrafficsim.core.network.NetworkException;
16 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
17 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
18 import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
19 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
20 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
21
22
23
24
25
26
27
28
29
30
31
32 public class HistoricalNeighborsPerception extends AbstractPerceptionCategory<LaneBasedGTU, LanePerception>
33 implements NeighborsPerception, Serializable
34 {
35
36
37 private static final long serialVersionUID = 20180131L;
38
39
40 private final int nFollowers;
41
42
43 private final int nLeaders;
44
45
46 private final Map<RelativeLane, TimeStampedObject<SortedSet<HeadwayGTU>>> followers = new HashMap<>();
47
48
49 private final Map<RelativeLane, TimeStampedObject<SortedSet<HeadwayGTU>>> leaders = new HashMap<>();
50
51
52 private final Map<LateralDirectionality, TimeStampedObject<SortedSet<HeadwayGTU>>> firstFollowers = new HashMap<>();
53
54
55 private final Map<LateralDirectionality, TimeStampedObject<SortedSet<HeadwayGTU>>> firstLeaders = new HashMap<>();
56
57
58 private final Map<LateralDirectionality, TimeStampedObject<Boolean>> gtuAlongside = new HashMap<>();
59
60
61 private final HeadwayGtuType headwayGtuType;
62
63 public HistoricalNeighborsPerception(final LanePerception perception, final HeadwayGtuType headwayGtuType)
64 {
65 this(perception, Integer.MAX_VALUE, Integer.MAX_VALUE, headwayGtuType);
66 }
67
68 public HistoricalNeighborsPerception(final LanePerception perception, final int nFollowers, final int nLeaders,
69 final HeadwayGtuType headwayGtuType)
70 {
71 super(perception);
72 this.nFollowers = nFollowers;
73 this.nLeaders = nLeaders;
74 this.headwayGtuType = headwayGtuType;
75 }
76
77
78 @Override
79 public void updateAll() throws GTUException, NetworkException, ParameterException
80 {
81 this.followers.clear();
82 this.leaders.clear();
83 this.firstFollowers.clear();
84 this.firstLeaders.clear();
85 this.gtuAlongside.clear();
86
87 Set<RelativeLane> crossSection =
88 Try.assign(() -> getPerception().getPerceptionCategory(InfrastructurePerception.class).getCrossSection(),
89 GTUException.class, "HistoricalNeighborsPerception requires InfrastructurePerception");
90 for (RelativeLane lane : crossSection)
91 {
92
93 }
94 }
95
96
97 @Override
98 public void updateFirstLeaders(final LateralDirectionality lat) throws ParameterException, GTUException, NetworkException
99 {
100 updateAll();
101 }
102
103
104 @Override
105 public void updateFirstFollowers(final LateralDirectionality lat) throws GTUException, ParameterException, NetworkException
106 {
107 updateAll();
108 }
109
110
111 @Override
112 public void updateGtuAlongside(final LateralDirectionality lat) throws GTUException, ParameterException, NetworkException
113 {
114 updateAll();
115 }
116
117
118 @Override
119 public void updateLeaders(final RelativeLane lane) throws ParameterException, GTUException, NetworkException
120 {
121 updateAll();
122 }
123
124
125 @Override
126 public void updateFollowers(final RelativeLane lane) throws GTUException, NetworkException, ParameterException
127 {
128 updateAll();
129 }
130
131
132 @Override
133 public SortedSet<HeadwayGTU> getFirstLeaders(LateralDirectionality lat)
134 throws ParameterException, NullPointerException, IllegalArgumentException
135 {
136 return null;
137 }
138
139
140 @Override
141 public SortedSet<HeadwayGTU> getFirstFollowers(LateralDirectionality lat)
142 throws ParameterException, NullPointerException, IllegalArgumentException
143 {
144 return null;
145 }
146
147
148 @Override
149 public boolean isGtuAlongside(LateralDirectionality lat)
150 throws ParameterException, NullPointerException, IllegalArgumentException
151 {
152 return false;
153 }
154
155
156 @Override
157 public PerceptionCollectable<HeadwayGTU, LaneBasedGTU> getLeaders(RelativeLane lane)
158 {
159 return null;
160 }
161
162
163 @Override
164 public PerceptionCollectable<HeadwayGTU, LaneBasedGTU> getFollowers(RelativeLane lane)
165 {
166 return null;
167 }
168
169 }