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