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