View Javadoc
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-2019 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 Lane; the lane for which to evaluate the overtaking conditions
44       * @param gtu LaneBasedGTU; the GTU that might overtake another GTU
45       * @param leaderGTU LaneBasedGTU; 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 leaderGTU);
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-2019 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      class LeftOnly implements OvertakingConditions
67      {
68  
69          /** {@inheritDoc} */
70          @Override
71          public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
72          {
73              return OvertakingDirection.LEFT;
74          }
75  
76          /** {@inheritDoc} */
77          @Override
78          public final String toString()
79          {
80              return "LeftOnly []";
81          }
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-2019 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      class RightOnly implements OvertakingConditions
98      {
99  
100         /** {@inheritDoc} */
101         @Override
102         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
103         {
104             return OvertakingDirection.RIGHT;
105         }
106 
107         /** {@inheritDoc} */
108         @Override
109         public final String toString()
110         {
111             return "RightOnly []";
112         }
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-2019 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     class None implements OvertakingConditions
127     {
128 
129         /** {@inheritDoc} */
130         @Override
131         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
132         {
133             return OvertakingDirection.NONE;
134         }
135 
136         /** {@inheritDoc} */
137         @Override
138         public final String toString()
139         {
140             return "None []";
141         }
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-2019 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     class LeftAndRight implements OvertakingConditions
156     {
157 
158         /** {@inheritDoc} */
159         @Override
160         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
161         {
162             return OvertakingDirection.BOTH;
163         }
164 
165         /** {@inheritDoc} */
166         @Override
167         public final String toString()
168         {
169             return "LeftAndRight []";
170         }
171 
172     }
173 
174     /**
175      * Overtaking on the left allowed for all GTUs; they stay on the same lane (e.g., bicycles).
176      * <p>
177      * Copyright (c) 2013-2019 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     class SameLaneLeft implements OvertakingConditions
185     {
186 
187         /** {@inheritDoc} */
188         @Override
189         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
190         {
191             return OvertakingDirection.LEFT;
192         }
193 
194         /** {@inheritDoc} */
195         @Override
196         public final String toString()
197         {
198             return "SameLaneLeft []";
199         }
200 
201     }
202 
203     /**
204      * Overtaking on the right allowed for all GTUs; they stay on the same lane (e.g., bicycles).
205      * <p>
206      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
207      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
208      * </p>
209      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
210      * initial version Sep 13, 2015
211      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
212      */
213     class SameLaneRight implements OvertakingConditions
214     {
215 
216         /** {@inheritDoc} */
217         @Override
218         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
219         {
220             return OvertakingDirection.RIGHT;
221         }
222 
223         /** {@inheritDoc} */
224         @Override
225         public final String toString()
226         {
227             return "SameLaneRight []";
228         }
229 
230     }
231 
232     /**
233      * Overtaking on both sides allowed for all GTUs; they stay on the same lane (e.g., pedestrians).
234      * <p>
235      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
236      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
237      * </p>
238      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
239      * initial version Sep 13, 2015
240      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
241      */
242     class SameLaneBoth implements OvertakingConditions
243     {
244 
245         /** {@inheritDoc} */
246         @Override
247         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
248         {
249             return OvertakingDirection.BOTH;
250         }
251 
252         /** {@inheritDoc} */
253         @Override
254         public final String toString()
255         {
256             return "SameLaneBoth []";
257         }
258 
259     }
260 
261     /**
262      * Overtaking on the left allowed for all GTUs, and overtaking on the right allowed under a given speed.
263      * <p>
264      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
265      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
266      * </p>
267      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
268      * initial version Sep 13, 2015
269      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
270      */
271     class LeftAlwaysRightSpeed implements OvertakingConditions, Serializable
272     {
273         /** */
274         private static final long serialVersionUID = 20150913L;
275 
276         /** The speed under which overtaking on the "wrong" side is allowed. */
277         private final Speed rightOvertakingSpeedMax;
278 
279         /**
280          * @param rightOvertakingSpeedMax Speed; the speed under which overtaking on the "wrong" side is allowed
281          */
282         public LeftAlwaysRightSpeed(final Speed rightOvertakingSpeedMax)
283         {
284             this.rightOvertakingSpeedMax = rightOvertakingSpeedMax;
285         }
286 
287         /** {@inheritDoc} */
288         @Override
289         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
290         {
291             return gtu.getSpeed().lt(this.rightOvertakingSpeedMax) ? OvertakingDirection.BOTH : OvertakingDirection.LEFT;
292         }
293 
294         /** {@inheritDoc} */
295         @Override
296         public final String toString()
297         {
298             return "LeftAlwaysRightSpeed [rightOvertakingSpeedMax=" + this.rightOvertakingSpeedMax + "]";
299         }
300 
301     }
302 
303     /**
304      * Overtaking on the right allowed for all GTUs, and overtaking on the left allowed under a given speed.
305      * <p>
306      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
307      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
308      * </p>
309      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
310      * initial version Sep 13, 2015
311      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
312      */
313     class RightAlwaysLeftSpeed implements OvertakingConditions, Serializable
314     {
315         /** */
316         private static final long serialVersionUID = 20150913L;
317 
318         /** The speed under which overtaking on the "wrong" side is allowed. */
319         private final Speed leftOvertakingSpeedMax;
320 
321         /**
322          * @param leftOvertakingSpeedMax Speed; the speed under which overtaking on the "wrong" side is allowed
323          */
324         public RightAlwaysLeftSpeed(final Speed leftOvertakingSpeedMax)
325         {
326             this.leftOvertakingSpeedMax = leftOvertakingSpeedMax;
327         }
328 
329         /** {@inheritDoc} */
330         @Override
331         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
332         {
333             return gtu.getSpeed().lt(this.leftOvertakingSpeedMax) ? OvertakingDirection.BOTH : OvertakingDirection.RIGHT;
334         }
335 
336         /** {@inheritDoc} */
337         @Override
338         public final String toString()
339         {
340             return "RightAlwaysLeftSpeed [leftOvertakingSpeedMax=" + this.leftOvertakingSpeedMax + "]";
341         }
342 
343     }
344 
345     /**
346      * Provide a collection of GTUs that can overtake another collection of GTUs on the left side, but not vice versa. Example:
347      * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
348      * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
349      * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
350      * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
351      * TRUCK} in that lane.<br>
352      * TODO: All these "Right/LeftSet" classes should probably use Compatibility instead of full sets.
353      * <p>
354      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
355      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
356      * </p>
357      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
358      * initial version Sep 13, 2015
359      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
360      */
361     class LeftSet implements OvertakingConditions, Serializable
362     {
363         /** */
364         private static final long serialVersionUID = 20150913L;
365 
366         /** A collection of GTUs that can overtake another collection of GTUs. */
367         private final Collection<GTUType> overtakingGTUTypes;
368 
369         /** A collection of GTUs that can be overtaken by another collection of GTUs. */
370         private final Collection<GTUType> overtakenGTUTypes;
371 
372         /**
373          * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example:
374          * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
375          * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}.
376          * @param overtakingGTUTypes Collection&lt;GTUType&gt;; the GTUs that can overtake a set of other GTUs, e.g., CAR,
377          *            TRUCK.
378          * @param overtakenGTUTYpes Collection&lt;GTUType&gt;; the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER.
379          */
380         public LeftSet(final Collection<GTUType> overtakingGTUTypes, final Collection<GTUType> overtakenGTUTYpes)
381         {
382             this.overtakingGTUTypes = overtakingGTUTypes;
383             this.overtakenGTUTypes = overtakenGTUTYpes;
384         }
385 
386         /** {@inheritDoc} */
387         @Override
388         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leaderGTU)
389         {
390             if (this.overtakingGTUTypes.contains(gtu.getGTUType()) && this.overtakenGTUTypes.contains(leaderGTU.getGTUType()))
391             {
392                 return OvertakingDirection.LEFT;
393             }
394             return OvertakingDirection.NONE;
395         }
396 
397         /** {@inheritDoc} */
398         @Override
399         public final String toString()
400         {
401             return "LeftSet [overtakingGTUTypes=" + this.overtakingGTUTypes + ", overtakenGTUTypes=" + this.overtakenGTUTypes
402                     + "]";
403         }
404 
405     }
406 
407     /**
408      * Provide a collection of GTUs that can overtake another collection of GTUs on the right side, but not vice versa. Example:
409      * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
410      * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
411      * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
412      * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
413      * TRUCK} in that lane.
414      * <p>
415      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
416      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
417      * </p>
418      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
419      * initial version Sep 13, 2015
420      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
421      */
422     class RightSet implements OvertakingConditions, Serializable
423     {
424         /** */
425         private static final long serialVersionUID = 20150913L;
426 
427         /** A collection of GTUs that can overtake another collection of GTUs. */
428         private final Collection<GTUType> overtakingGTUTypes;
429 
430         /** A collection of GTUs that can be overtaken by another collection of GTUs. */
431         private final Collection<GTUType> overtakenGTUTypes;
432 
433         /**
434          * Provide a collection of GTUs that can overtake another collection of GTUs on the right, but not vice versa. Example:
435          * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
436          * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}.
437          * @param overtakingGTUs Collection&lt;GTUType&gt;; the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK.
438          * @param overtakenGTUs Collection&lt;GTUType&gt;; the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER.
439          */
440         public RightSet(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs)
441         {
442             this.overtakingGTUTypes = overtakingGTUs;
443             this.overtakenGTUTypes = overtakenGTUs;
444         }
445 
446         /** {@inheritDoc} */
447         @Override
448         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leaderGTU)
449         {
450             if (this.overtakingGTUTypes.contains(gtu.getGTUType()) && this.overtakenGTUTypes.contains(leaderGTU.getGTUType()))
451             {
452                 return OvertakingDirection.RIGHT;
453             }
454             return OvertakingDirection.NONE;
455         }
456 
457         /** {@inheritDoc} */
458         @Override
459         public final String toString()
460         {
461             return "RightSet [overtakingGTUTypes=" + this.overtakingGTUTypes + ", overtakenGTUTypes=" + this.overtakenGTUTypes
462                     + "]";
463         }
464 
465     }
466 
467     /**
468      * Provide a collection of GTUs that can overtake another collection of GTUs on the left side, but not vice versa. Example:
469      * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
470      * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
471      * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
472      * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
473      * TRUCK} in that lane. In addition, overtaking on the other side is allowed under a given driving speed.
474      * <p>
475      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
476      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
477      * </p>
478      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
479      * initial version Sep 13, 2015
480      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
481      */
482     class LeftSetRightSpeed implements OvertakingConditions, Serializable
483     {
484         /** */
485         private static final long serialVersionUID = 20150913L;
486 
487         /** A collection of GTUs that can overtake another collection of GTUs. */
488         private final Collection<GTUType> overtakingGTUTypes;
489 
490         /** A collection of GTUs that can be overtaken by another collection of GTUs. */
491         private final Collection<GTUType> overtakenGTUTypes;
492 
493         /** The speed under which overtaking on the "wrong" side is allowed. */
494         private final Speed rightOvertakingSpeedMax;
495 
496         /**
497          * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example:
498          * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
499          * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. In addition, overtaking on the other side is allowed under a
500          * given driving speed.
501          * @param overtakingGTUs Collection&lt;GTUType&gt;; the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK.
502          * @param overtakenGTUs Collection&lt;GTUType&gt;; the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER.
503          * @param rightOvertakingSpeedMax Speed; the speed under which overtaking on the "wrong" side is allowed
504          */
505         public LeftSetRightSpeed(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs,
506                 final Speed rightOvertakingSpeedMax)
507         {
508             this.overtakingGTUTypes = overtakingGTUs;
509             this.overtakenGTUTypes = overtakenGTUs;
510             this.rightOvertakingSpeedMax = rightOvertakingSpeedMax;
511         }
512 
513         /** {@inheritDoc} */
514         @Override
515         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
516         {
517             boolean left = (this.overtakingGTUTypes.contains(gtu.getGTUType())
518                     && this.overtakenGTUTypes.contains(leadereGTU.getGTUType()));
519             boolean right = gtu.getSpeed().lt(this.rightOvertakingSpeedMax);
520             if (left)
521             {
522                 return right ? OvertakingDirection.BOTH : OvertakingDirection.LEFT;
523             }
524             return right ? OvertakingDirection.RIGHT : OvertakingDirection.NONE;
525         }
526 
527         /** {@inheritDoc} */
528         @Override
529         public final String toString()
530         {
531             return "LeftSetRightSpeed [overtakingGTUTypes=" + this.overtakingGTUTypes + ", overtakenGTUTypes="
532                     + this.overtakenGTUTypes + ", rightOvertakingSpeedMax=" + this.rightOvertakingSpeedMax + "]";
533         }
534 
535     }
536 
537     /**
538      * Provide a collection of GTUs that can overtake another collection of GTUs on the right side, but not vice versa. Example:
539      * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}.
540      * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars,
541      * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not
542      * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR,
543      * TRUCK} in that lane. In addition, overtaking on the other side is allowed under a given driving speed.
544      * <p>
545      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
546      * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
547      * </p>
548      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
549      * initial version Sep 13, 2015
550      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
551      */
552     class RightSetLeftSpeed implements OvertakingConditions, Serializable
553     {
554         /** */
555         private static final long serialVersionUID = 20150913L;
556 
557         /** A collection of GTUs that can overtake another collection of GTUs. */
558         private final Collection<GTUType> overtakingGTUTypes;
559 
560         /** A collection of GTUs that can be overtaken by another collection of GTUs. */
561         private final Collection<GTUType> overtakenGTUTypes;
562 
563         /** The speed under which overtaking on the "wrong" side is allowed. */
564         private final Speed leftOvertakingSpeedMax;
565 
566         /**
567          * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example:
568          * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE,
569          * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. In addition, overtaking on the other side is allowed under a
570          * given driving speed.
571          * @param overtakingGTUs Collection&lt;GTUType&gt;; the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK.
572          * @param overtakenGTUs Collection&lt;GTUType&gt;; the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER.
573          * @param leftOvertakingSpeedMax Speed; the speed under which overtaking on the "wrong" side is allowed
574          */
575         public RightSetLeftSpeed(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs,
576                 final Speed leftOvertakingSpeedMax)
577         {
578             this.overtakingGTUTypes = overtakingGTUs;
579             this.overtakenGTUTypes = overtakenGTUs;
580             this.leftOvertakingSpeedMax = leftOvertakingSpeedMax;
581         }
582 
583         /** {@inheritDoc} */
584         @Override
585         public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, final LaneBasedGTU leadereGTU)
586         {
587             boolean right = ((this.overtakingGTUTypes.contains(gtu.getGTUType())
588                     && (this.overtakenGTUTypes.contains(leadereGTU.getGTUType()))));
589             boolean left = gtu.getSpeed().lt(this.leftOvertakingSpeedMax);
590             if (right)
591             {
592                 return left ? OvertakingDirection.BOTH : OvertakingDirection.RIGHT;
593             }
594             return left ? OvertakingDirection.LEFT : OvertakingDirection.NONE;
595         }
596 
597         /** {@inheritDoc} */
598         @Override
599         public final String toString()
600         {
601             return "RightSetLeftSpeed [overtakingGTUTypes=" + this.overtakingGTUTypes + ", overtakenGTUTypes="
602                     + this.overtakenGTUTypes + ", leftOvertakingSpeedMax=" + this.leftOvertakingSpeedMax + "]";
603         }
604 
605     }
606 
607 }