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,
146 final Length distance, final Length length, final Length conflictingLength,
147 final SortedSet<HeadwayGTU> upstreamConflictingGTUs,
148 final SortedSet<HeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
149 final Speed conflictingSpeedLimit, final CrossSectionLink conflictingLink) throws GTUException
150 {
151 this(conflictType, conflictPriority, conflictRuleType, id, distance, length, conflictingLength, upstreamConflictingGTUs,
152 downstreamConflictingGTUs, conflictingVisibility, conflictingSpeedLimit, conflictingLink, null, null);
153 }
154
155
156
157
158
159 public final ConflictType getConflictType()
160 {
161 return this.conflictType;
162 }
163
164
165
166
167
168 public final boolean isCrossing()
169 {
170 return this.conflictType.equals(ConflictType.CROSSING);
171 }
172
173
174
175
176
177 public final boolean isMerge()
178 {
179 return this.conflictType.equals(ConflictType.MERGE);
180 }
181
182
183
184
185
186 public final boolean isSplit()
187 {
188 return this.conflictType.equals(ConflictType.SPLIT);
189 }
190
191
192
193
194
195 public final ConflictPriority getConflictPriority()
196 {
197 return this.conflictPriority;
198 }
199
200
201
202
203
204 public final Length getConflictingLength()
205 {
206 return this.conflictingLength;
207 }
208
209
210
211
212
213 public final SortedSet<HeadwayGTU> getUpstreamConflictingGTUs()
214 {
215 return new TreeSet<>(this.upstreamConflictingGTUs);
216 }
217
218
219
220
221
222
223
224 public final SortedSet<HeadwayGTU> getDownstreamConflictingGTUs()
225 {
226 return new TreeSet<>(this.downstreamConflictingGTUs);
227 }
228
229
230
231
232
233
234
235 public final Length getConflictingVisibility()
236 {
237 return this.conflictingVisibility;
238 }
239
240
241
242
243
244 public final Speed getConflictingSpeedLimit()
245 {
246 return this.conflictingSpeedLimit;
247 }
248
249
250
251
252
253 public final CrossSectionLink getConflictingLink()
254 {
255 return this.conflictingLink;
256 }
257
258
259
260
261
262 public final HeadwayStopLine getStopLine()
263 {
264 return this.stopLine;
265 }
266
267
268
269
270
271 public final HeadwayStopLine getConflictingStopLine()
272 {
273 return this.conflictingStopLine;
274 }
275
276
277
278
279
280 public Class<? extends ConflictRule> getConflictRuleType()
281 {
282 return this.conflictRuleType;
283 }
284
285
286
287
288
289 public Length getConflictingTrafficLightDistance()
290 {
291 return this.conflictingTrafficLightDistance;
292 }
293
294
295
296
297
298 public boolean isPermitted()
299 {
300 return this.permitted;
301 }
302
303
304
305
306
307
308 public void setConflictingTrafficLight(final Length trafficLightDistance, final boolean permittedConflict)
309 {
310 this.conflictingTrafficLightDistance = trafficLightDistance;
311 this.permitted = permittedConflict;
312 }
313
314
315 public final String toString()
316 {
317 return String.format("Headway %s to object %s of type %s", getDistance(), getId(), getObjectType());
318 }
319
320 }