1 package org.opentrafficsim.road.gtu.lane.perception.headway;
2
3 import java.util.SortedSet;
4 import java.util.TreeSet;
5
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.djunits.value.vdouble.scalar.Speed;
8 import org.opentrafficsim.core.gtu.GTUException;
9 import org.opentrafficsim.road.network.lane.CrossSectionLink;
10 import org.opentrafficsim.road.network.lane.conflict.ConflictRule;
11 import org.opentrafficsim.road.network.lane.conflict.ConflictType;
12
13 import nl.tudelft.simulation.language.Throw;
14
15
16
17
18
19
20
21
22
23
24
25 public class HeadwayConflict extends AbstractHeadway
26 {
27
28
29 private static final long serialVersionUID = 20160602L;
30
31
32 private final ConflictType conflictType;
33
34
35 private final ConflictRule conflictRule;
36
37
38 private final Length conflictingLength;
39
40
41
42
43
44 private final SortedSet<AbstractHeadwayGTU> upstreamConflictingGTUs;
45
46
47
48
49
50 private final SortedSet<AbstractHeadwayGTU> downstreamConflictingGTUs;
51
52
53 private final Length conflictingVisibility;
54
55
56 private final Speed conflictingSpeedLimit;
57
58
59 private final CrossSectionLink conflictingLink;
60
61
62 private final HeadwayStopLine stopLine;
63
64
65 private final HeadwayStopLine conflictingStopLine;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 @SuppressWarnings("checkstyle:parameternumber")
85 public HeadwayConflict(final ConflictType conflictType, final ConflictRule conflictRule, final String id,
86 final Length distance, final Length length, final Length conflictingLength,
87 final SortedSet<AbstractHeadwayGTU> upstreamConflictingGTUs,
88 final SortedSet<AbstractHeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
89 final Speed conflictingSpeedLimit, final CrossSectionLink conflictingLink, final HeadwayStopLine stopLine,
90 final HeadwayStopLine conflictingStopLine) throws GTUException
91 {
92 super(ObjectType.CONFLICT, id, distance, length);
93 Throw.whenNull(conflictType, "Conflict type may not be null.");
94 Throw.whenNull(conflictRule, "Conflict rule may not be null.");
95 Throw.whenNull(id, "Conflict id may not be null.");
96 Throw.whenNull(distance, "Conflict distance may not be null.");
97 Throw.whenNull(conflictingLength, "Conflict length may not be null.");
98 Throw.whenNull(upstreamConflictingGTUs, "Upstreaem conflicting GTU's may not be null.");
99 Throw.whenNull(downstreamConflictingGTUs, "Downstream conflicting GTU's may not be null.");
100 Throw.whenNull(conflictingVisibility, "Conflict visibility may not be null.");
101 Throw.whenNull(conflictingSpeedLimit, "Conflict speed limit may not be null.");
102 this.conflictType = conflictType;
103 this.conflictRule = conflictRule;
104 this.conflictingLength = conflictingLength;
105 this.upstreamConflictingGTUs = upstreamConflictingGTUs;
106 this.downstreamConflictingGTUs = downstreamConflictingGTUs;
107 this.conflictingVisibility = conflictingVisibility;
108 this.conflictingSpeedLimit = conflictingSpeedLimit;
109 this.conflictingLink = conflictingLink;
110 this.stopLine = stopLine;
111 this.conflictingStopLine = conflictingStopLine;
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 @SuppressWarnings("checkstyle:parameternumber")
130 public HeadwayConflict(final ConflictType conflictType, final ConflictRule conflictRule, final String id,
131 final Length distance, final Length length, final Length conflictingLength,
132 final SortedSet<AbstractHeadwayGTU> upstreamConflictingGTUs,
133 final SortedSet<AbstractHeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
134 final Speed conflictingSpeedLimit, final CrossSectionLink conflictingLink) throws GTUException
135 {
136 this(conflictType, conflictRule, id, distance, length, conflictingLength, upstreamConflictingGTUs,
137 downstreamConflictingGTUs, conflictingVisibility, conflictingSpeedLimit, conflictingLink, null, null);
138 }
139
140
141
142
143
144 public final ConflictType getConflictType()
145 {
146 return this.conflictType;
147 }
148
149
150
151
152
153 public final boolean isCrossing()
154 {
155 return this.conflictType.equals(ConflictType.CROSSING);
156 }
157
158
159
160
161
162 public final boolean isMerge()
163 {
164 return this.conflictType.equals(ConflictType.MERGE);
165 }
166
167
168
169
170
171 public final boolean isSplit()
172 {
173 return this.conflictType.equals(ConflictType.SPLIT);
174 }
175
176
177
178
179
180 public final ConflictRule getConflictRule()
181 {
182 return this.conflictRule;
183 }
184
185
186
187
188
189 public final boolean isPriority()
190 {
191 return this.conflictRule.equals(ConflictRule.PRIORITY);
192 }
193
194
195
196
197
198 public final boolean isGiveWay()
199 {
200 return this.conflictRule.equals(ConflictRule.GIVE_WAY);
201 }
202
203
204
205
206
207 public final boolean isStop()
208 {
209 return this.conflictRule.equals(ConflictRule.STOP);
210 }
211
212
213
214
215
216 public final boolean isAllStop()
217 {
218 return this.conflictRule.equals(ConflictRule.ALL_STOP);
219 }
220
221
222
223
224
225 public final Length getConflictingLength()
226 {
227 return this.conflictingLength;
228 }
229
230
231
232
233
234 public final SortedSet<AbstractHeadwayGTU> getUpstreamConflictingGTUs()
235 {
236 return new TreeSet<>(this.upstreamConflictingGTUs);
237 }
238
239
240
241
242
243
244
245 public final SortedSet<AbstractHeadwayGTU> getDownstreamConflictingGTUs()
246 {
247 return new TreeSet<>(this.downstreamConflictingGTUs);
248 }
249
250
251
252
253
254
255
256 public final Length getConflictingVisibility()
257 {
258 return this.conflictingVisibility;
259 }
260
261
262
263
264
265 public final Speed getConflictingSpeedLimit()
266 {
267 return this.conflictingSpeedLimit;
268 }
269
270
271
272
273
274 public final CrossSectionLink getConflictingLink()
275 {
276 return this.conflictingLink;
277 }
278
279
280
281
282
283 public final HeadwayStopLine getStopLine()
284 {
285 return this.stopLine;
286 }
287
288
289
290
291
292 public final HeadwayStopLine getConflictingStopLine()
293 {
294 return this.conflictingStopLine;
295 }
296
297
298 public final String toString()
299 {
300 return String.format("Headway %s to object %s of type %s", getDistance(), getId(), getObjectType());
301 }
302
303 }