1 package org.opentrafficsim.road.network.lane.changing;
2
3 import java.io.Serializable;
4 import java.util.Collection;
5
6 import org.djunits.value.vdouble.scalar.Speed;
7 import org.opentrafficsim.core.gtu.GTUType;
8 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9 import org.opentrafficsim.road.network.lane.Lane;
10
11 /**
12 * This class implements the overtaking conditions. Examples are:
13 * <ul>
14 * <li>Overtaking on the left is allowed for all GTU types (not likely when there are e.g., both cars and bicycles in the
15 * model).</li>
16 * <li>A GTU type CAR can overtake a GTU type TRACTOR on the left on this road, but no other types of GTUs.</li>
17 * <li>When the speed of the GTU you try to overtake is lower than 50 km/h, you can overtake on the left.</li>
18 * <li>When the speed of the GTU you try to overtake is 25 km/h less than the maximum speed of the lane on which you and the
19 * other GTU are driving, you can overtake on the left or right.</li>
20 * <li>only overtake vehicles that have a maximum speed of under 25 km/h.</li>
21 * <li>Overtaking on the left is allowed for all GTU types, but overtaking on the right is also allowed when traffic density is
22 * below a certain number</li>
23 * <li>Overtaking on the left is allowed for all GTU types, but overtaking on the right is also allowed when the distance to a
24 * traffic light is less than 200 m</li>
25 * <li>Overtaking on the left and the right is allowed for all GTUs. This can e.g. be used on an American highway where all GTUs
26 * that are allowed on the highway can indeed overtake on the right or the left.</li>
27 * </ul>
28 * <b>Note:</b> The class only checks whether it is <b>allowed</b> to overtake another GTU on this road, not whether it is
29 * possible or safe to do so. That has to be checked by the GTU itself based on e.g., gap acceptance.
30 * <p>
31 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
32 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
33 * <p>
34 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
35 * initial version Sep 13, 2015 <br>
36 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
37 */
38 public interface OvertakingConditions
39 {
40 /**
41 * Implementation of the overtaking conditions. E.g., is a car allowed on this road to overtake a tractor? If so, on which
42 * side(s)?
43 * @param lane the lane for which to evaluate the overtaking conditions
44 * @param gtu the GTU that might overtake another GTU
45 * @param predecessorGTU the GTU in front of the GTU that might want to overtake
46 * @return an overtaking direction: LEFT, RIGHT, BOTH or NONE
47 */
48 OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU predecessorGTU);
49
50 /********************************************************************************************************************/
51 /********************** IMPLEMENTATION CLASSES OF MOST COMMON OVERTAKING CONDITIONS *****************************/
52 /********************************************************************************************************************/
53
54 /**
55 * Overtaking on the left allowed for all GTUs. Note: overtaking on the right not allowed, so vehicles will stall on a
56 * multilane road near a traffic light. Also, bicycles will overtake cars on the "wrong" side of the road in this simple
57 * condition!
58 * <p>
59 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
60 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
61 * </p>
62 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
63 * initial version Sep 13, 2015
64 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
65 */
66 public static class LeftOnly implements OvertakingConditions
67 {
68
69 /** {@inheritDoc} */
70 @Override
71 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
72 final LaneBasedGTU predecessorGTU)
73 {
74 return OvertakingDirection.LEFT;
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 public final String toString()
80 {
81 return "LeftOnly []";
82 }
83 }
84
85 /**
86 * Overtaking on the right allowed for all GTUs. Note: overtaking on the left not allowed, so vehicles will stall on a
87 * multilane road near a traffic light. Also, bicycles will overtake cars on the "wrong" side of the road in this simple
88 * condition!
89 * <p>
90 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
91 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
92 * </p>
93 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
94 * initial version Sep 13, 2015
95 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
96 */
97 public static class RightOnly implements OvertakingConditions
98 {
99
100 /** {@inheritDoc} */
101 @Override
102 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
103 final LaneBasedGTU predecessorGTU)
104 {
105 return OvertakingDirection.RIGHT;
106 }
107
108 /** {@inheritDoc} */
109 @Override
110 public final String toString()
111 {
112 return "RightOnly []";
113 }
114 }
115
116 /**
117 * No overtaking allowed. Note if there are multiple lanes, vehicles will stall near a traffic light.
118 * <p>
119 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
120 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
121 * </p>
122 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
123 * initial version Sep 13, 2015
124 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
125 */
126 public static class None implements OvertakingConditions
127 {
128
129 /** {@inheritDoc} */
130 @Override
131 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
132 final LaneBasedGTU predecessorGTU)
133 {
134 return OvertakingDirection.NONE;
135 }
136
137 /** {@inheritDoc} */
138 @Override
139 public final String toString()
140 {
141 return "None []";
142 }
143 }
144
145 /**
146 * Overtaking on both sides allowed. This is, e.g., the situation for an American highway.
147 * <p>
148 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
149 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
150 * </p>
151 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
152 * initial version Sep 13, 2015
153 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
154 */
155 public static class LeftAndRight implements OvertakingConditions
156 {
157
158 /** {@inheritDoc} */
159 @Override
160 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
161 final LaneBasedGTU predecessorGTU)
162 {
163 return OvertakingDirection.BOTH;
164 }
165
166 /** {@inheritDoc} */
167 @Override
168 public final String toString()
169 {
170 return "LeftAndRight []";
171 }
172 }
173
174 /**
175 * Overtaking on the left allowed for all GTUs, and overtaking on the right allowed under a given speed.
176 * <p>
177 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
178 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
179 * </p>
180 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
181 * initial version Sep 13, 2015
182 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
183 */
184 public static class LeftAlwaysRightSpeed implements OvertakingConditions, Serializable
185 {
186 /** */
187 private static final long serialVersionUID = 20150913L;
188
189 /** The speed under which overtaking on the "wrong" side is allowed. */
190 private final Speed rightOvertakingSpeedMax;
191
192 /**
193 * @param rightOvertakingSpeedMax the speed under which overtaking on the "wrong" side is allowed
194 */
195 public LeftAlwaysRightSpeed(final Speed rightOvertakingSpeedMax)
196 {
197 this.rightOvertakingSpeedMax = rightOvertakingSpeedMax;
198 }
199
200 /** {@inheritDoc} */
201 @Override
202 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
203 final LaneBasedGTU predecessorGTU)
204 {
205 return gtu.getSpeed().lt(this.rightOvertakingSpeedMax) ? OvertakingDirection.BOTH
206 : OvertakingDirection.LEFT;
207 }
208
209 /** {@inheritDoc} */
210 @Override
211 public final String toString()
212 {
213 return "LeftAlwaysRightSpeed [rightOvertakingSpeedMax=" + this.rightOvertakingSpeedMax + "]";
214 }
215 }
216
217 /**
218 * Overtaking on the right allowed for all GTUs, and overtaking on the left allowed under a given speed.
219 * <p>
220 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
221 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
222 * </p>
223 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
224 * initial version Sep 13, 2015
225 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
226 */
227 public static class RightAlwaysLeftSpeed implements OvertakingConditions, Serializable
228 {
229 /** */
230 private static final long serialVersionUID = 20150913L;
231
232 /** The speed under which overtaking on the "wrong" side is allowed. */
233 private final Speed leftOvertakingSpeedMax;
234
235 /**
236 * @param leftOvertakingSpeedMax the speed under which overtaking on the "wrong" side is allowed
237 */
238 public RightAlwaysLeftSpeed(final Speed leftOvertakingSpeedMax)
239 {
240 this.leftOvertakingSpeedMax = leftOvertakingSpeedMax;
241 }
242
243 /** {@inheritDoc} */
244 @Override
245 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
246 final LaneBasedGTU predecessorGTU)
247 {
248 return gtu.getSpeed().lt(this.leftOvertakingSpeedMax) ? OvertakingDirection.BOTH
249 : OvertakingDirection.RIGHT;
250 }
251
252 /** {@inheritDoc} */
253 @Override
254 public final String toString()
255 {
256 return "RightAlwaysLeftSpeed [leftOvertakingSpeedMax=" + this.leftOvertakingSpeedMax + "]";
257 }
258 }
259
260 /**
261 * Provide a collection of GTUs that can overtake another collection of GTUs on the left side, but not vice versa. Example:
262 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
263 * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
264 * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
265 * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
266 * TRUCK} in that lane.
267 * <p>
268 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
269 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
270 * </p>
271 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
272 * initial version Sep 13, 2015
273 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
274 */
275 public static class LeftSet implements OvertakingConditions, Serializable
276 {
277 /** */
278 private static final long serialVersionUID = 20150913L;
279
280 /** A collection of GTUs that can overtake another collection of GTUs. */
281 private final Collection<GTUType> overtakingGTUs;
282
283 /** A collection of GTUs that can be overtaken by another collection of GTUs. */
284 private final Collection<GTUType> overtakenGTUs;
285
286 /**
287 * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example:
288 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
289 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}.
290 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains
291 * GTUType.ALL, all GTUs can overtake.
292 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL,
293 * all GTUs can be overtaken.
294 */
295 public LeftSet(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs)
296 {
297 this.overtakingGTUs = overtakingGTUs;
298 this.overtakenGTUs = overtakenGTUs;
299 }
300
301 /** {@inheritDoc} */
302 @Override
303 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
304 final LaneBasedGTU predecessorGTU)
305 {
306 if ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType())
307 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs
308 .contains(predecessorGTU.getGTUType()))))
309 {
310 return OvertakingDirection.LEFT;
311 }
312 return OvertakingDirection.NONE;
313 }
314
315 /** {@inheritDoc} */
316 @Override
317 public final String toString()
318 {
319 return "LeftSet [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs + "]";
320 }
321 }
322
323 /**
324 * Provide a collection of GTUs that can overtake another collection of GTUs on the right side, but not vice versa. Example:
325 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
326 * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
327 * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
328 * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
329 * TRUCK} in that lane.
330 * <p>
331 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
332 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
333 * </p>
334 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
335 * initial version Sep 13, 2015
336 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
337 */
338 public static class RightSet implements OvertakingConditions, Serializable
339 {
340 /** */
341 private static final long serialVersionUID = 20150913L;
342
343 /** A collection of GTUs that can overtake another collection of GTUs. */
344 private final Collection<GTUType> overtakingGTUs;
345
346 /** A collection of GTUs that can be overtaken by another collection of GTUs. */
347 private final Collection<GTUType> overtakenGTUs;
348
349 /**
350 * Provide a collection of GTUs that can overtake another collection of GTUs on the right, but not vice versa. Example:
351 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
352 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}.
353 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains
354 * GTUType.ALL, all GTUs can overtake.
355 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL,
356 * all GTUs can be overtaken.
357 */
358 public RightSet(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs)
359 {
360 this.overtakingGTUs = overtakingGTUs;
361 this.overtakenGTUs = overtakenGTUs;
362 }
363
364 /** {@inheritDoc} */
365 @Override
366 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
367 final LaneBasedGTU predecessorGTU)
368 {
369 if ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType())
370 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs
371 .contains(predecessorGTU.getGTUType()))))
372 {
373 return OvertakingDirection.RIGHT;
374 }
375 return OvertakingDirection.NONE;
376 }
377
378 /** {@inheritDoc} */
379 @Override
380 public final String toString()
381 {
382 return "RightSet [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs + "]";
383 }
384 }
385
386 /**
387 * Provide a collection of GTUs that can overtake another collection of GTUs on the left side, but not vice versa. Example:
388 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
389 * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
390 * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
391 * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
392 * TRUCK} in that lane. In addition, overtaking on the other side is allowed under a given driving speed.
393 * <p>
394 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
395 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
396 * </p>
397 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
398 * initial version Sep 13, 2015
399 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
400 */
401 public static class LeftSetRightSpeed implements OvertakingConditions, Serializable
402 {
403 /** */
404 private static final long serialVersionUID = 20150913L;
405
406 /** A collection of GTUs that can overtake another collection of GTUs. */
407 private final Collection<GTUType> overtakingGTUs;
408
409 /** A collection of GTUs that can be overtaken by another collection of GTUs. */
410 private final Collection<GTUType> overtakenGTUs;
411
412 /** The speed under which overtaking on the "wrong" side is allowed. */
413 private final Speed rightOvertakingSpeedMax;
414
415 /**
416 * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example:
417 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
418 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. In addition, overtaking on the other side is allowed under a
419 * given driving speed.
420 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains
421 * GTUType.ALL, all GTUs can overtake.
422 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL,
423 * all GTUs can be overtaken.
424 * @param rightOvertakingSpeedMax the speed under which overtaking on the "wrong" side is allowed
425 */
426 public LeftSetRightSpeed(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs,
427 final Speed rightOvertakingSpeedMax)
428 {
429 this.overtakingGTUs = overtakingGTUs;
430 this.overtakenGTUs = overtakenGTUs;
431 this.rightOvertakingSpeedMax = rightOvertakingSpeedMax;
432 }
433
434 /** {@inheritDoc} */
435 @Override
436 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
437 final LaneBasedGTU predecessorGTU)
438 {
439 boolean left =
440 ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType())
441 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU
442 .getGTUType()))));
443 boolean right = gtu.getSpeed().lt(this.rightOvertakingSpeedMax);
444 if (left)
445 {
446 return right ? OvertakingDirection.BOTH : OvertakingDirection.LEFT;
447 }
448 return right ? OvertakingDirection.RIGHT : OvertakingDirection.NONE;
449 }
450
451 /** {@inheritDoc} */
452 @Override
453 public final String toString()
454 {
455 return "LeftSetRightSpeed [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs
456 + ", rightOvertakingSpeedMax=" + this.rightOvertakingSpeedMax + "]";
457 }
458 }
459
460 /**
461 * Provide a collection of GTUs that can overtake another collection of GTUs on the right side, but not vice versa. Example:
462 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
463 * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
464 * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
465 * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
466 * TRUCK} in that lane. In addition, overtaking on the other side is allowed under a given driving speed.
467 * <p>
468 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
469 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
470 * </p>
471 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
472 * initial version Sep 13, 2015
473 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
474 */
475 public static class RightSetLeftSpeed implements OvertakingConditions, Serializable
476 {
477 /** */
478 private static final long serialVersionUID = 20150913L;
479
480 /** A collection of GTUs that can overtake another collection of GTUs. */
481 private final Collection<GTUType> overtakingGTUs;
482
483 /** A collection of GTUs that can be overtaken by another collection of GTUs. */
484 private final Collection<GTUType> overtakenGTUs;
485
486 /** The speed under which overtaking on the "wrong" side is allowed. */
487 private final Speed leftOvertakingSpeedMax;
488
489 /**
490 * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example:
491 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
492 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. In addition, overtaking on the other side is allowed under a
493 * given driving speed.
494 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains
495 * GTUType.ALL, all GTUs can overtake.
496 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL,
497 * all GTUs can be overtaken.
498 * @param leftOvertakingSpeedMax the speed under which overtaking on the "wrong" side is allowed
499 */
500 public RightSetLeftSpeed(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs,
501 final Speed leftOvertakingSpeedMax)
502 {
503 this.overtakingGTUs = overtakingGTUs;
504 this.overtakenGTUs = overtakenGTUs;
505 this.leftOvertakingSpeedMax = leftOvertakingSpeedMax;
506 }
507
508 /** {@inheritDoc} */
509 @Override
510 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
511 final LaneBasedGTU predecessorGTU)
512 {
513 boolean right =
514 ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType())
515 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU
516 .getGTUType()))));
517 boolean left = gtu.getSpeed().lt(this.leftOvertakingSpeedMax);
518 if (right)
519 {
520 return left ? OvertakingDirection.BOTH : OvertakingDirection.RIGHT;
521 }
522 return left ? OvertakingDirection.LEFT : OvertakingDirection.NONE;
523 }
524
525 /** {@inheritDoc} */
526 @Override
527 public final String toString()
528 {
529 return "RightSetLeftSpeed [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs
530 + ", leftOvertakingSpeedMax=" + this.leftOvertakingSpeedMax + "]";
531 }
532 }
533
534 }