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