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