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; they stay on the same lane (e.g., bicycles). 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 SameLaneLeft implements OvertakingConditions 185 { 186 187 /** {@inheritDoc} */ 188 @Override 189 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 190 final LaneBasedGTU predecessorGTU) 191 { 192 return OvertakingDirection.LEFT; 193 } 194 195 /** {@inheritDoc} */ 196 @Override 197 public final String toString() 198 { 199 return "SameLaneLeft []"; 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-2016 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 public static class SameLaneRight implements OvertakingConditions 214 { 215 216 /** {@inheritDoc} */ 217 @Override 218 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 219 final LaneBasedGTU predecessorGTU) 220 { 221 return OvertakingDirection.RIGHT; 222 } 223 224 /** {@inheritDoc} */ 225 @Override 226 public final String toString() 227 { 228 return "SameLaneRight []"; 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-2016 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 public static class SameLaneBoth implements OvertakingConditions 243 { 244 245 /** {@inheritDoc} */ 246 @Override 247 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 248 final LaneBasedGTU predecessorGTU) 249 { 250 return OvertakingDirection.BOTH; 251 } 252 253 /** {@inheritDoc} */ 254 @Override 255 public final String toString() 256 { 257 return "SameLaneBoth []"; 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-2016 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 public static 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 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, 290 final LaneBasedGTU predecessorGTU) 291 { 292 return gtu.getSpeed().lt(this.rightOvertakingSpeedMax) ? OvertakingDirection.BOTH : OvertakingDirection.LEFT; 293 } 294 295 /** {@inheritDoc} */ 296 @Override 297 public final String toString() 298 { 299 return "LeftAlwaysRightSpeed [rightOvertakingSpeedMax=" + this.rightOvertakingSpeedMax + "]"; 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-2016 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 public static 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 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, 332 final LaneBasedGTU predecessorGTU) 333 { 334 return gtu.getSpeed().lt(this.leftOvertakingSpeedMax) ? OvertakingDirection.BOTH : OvertakingDirection.RIGHT; 335 } 336 337 /** {@inheritDoc} */ 338 @Override 339 public final String toString() 340 { 341 return "RightAlwaysLeftSpeed [leftOvertakingSpeedMax=" + this.leftOvertakingSpeedMax + "]"; 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. 352 * <p> 353 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 354 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 355 * </p> 356 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, 357 * initial version Sep 13, 2015 358 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 359 */ 360 public static class LeftSet implements OvertakingConditions, Serializable 361 { 362 /** */ 363 private static final long serialVersionUID = 20150913L; 364 365 /** A collection of GTUs that can overtake another collection of GTUs. */ 366 private final Collection<GTUType> overtakingGTUs; 367 368 /** A collection of GTUs that can be overtaken by another collection of GTUs. */ 369 private final Collection<GTUType> overtakenGTUs; 370 371 /** 372 * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example: 373 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, 374 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. 375 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains 376 * GTUType.ALL, all GTUs can overtake. 377 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL, 378 * all GTUs can be overtaken. 379 */ 380 public LeftSet(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs) 381 { 382 this.overtakingGTUs = overtakingGTUs; 383 this.overtakenGTUs = overtakenGTUs; 384 } 385 386 /** {@inheritDoc} */ 387 @Override 388 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 389 final LaneBasedGTU predecessorGTU) 390 { 391 if ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType()) 392 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU.getGTUType())))) 393 { 394 return OvertakingDirection.LEFT; 395 } 396 return OvertakingDirection.NONE; 397 } 398 399 /** {@inheritDoc} */ 400 @Override 401 public final String toString() 402 { 403 return "LeftSet [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs + "]"; 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-2016 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 public static 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> overtakingGTUs; 429 430 /** A collection of GTUs that can be overtaken by another collection of GTUs. */ 431 private final Collection<GTUType> overtakenGTUs; 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 the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains 438 * GTUType.ALL, all GTUs can overtake. 439 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL, 440 * all GTUs can be overtaken. 441 */ 442 public RightSet(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs) 443 { 444 this.overtakingGTUs = overtakingGTUs; 445 this.overtakenGTUs = overtakenGTUs; 446 } 447 448 /** {@inheritDoc} */ 449 @Override 450 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 451 final LaneBasedGTU predecessorGTU) 452 { 453 if ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType()) 454 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU.getGTUType())))) 455 { 456 return OvertakingDirection.RIGHT; 457 } 458 return OvertakingDirection.NONE; 459 } 460 461 /** {@inheritDoc} */ 462 @Override 463 public final String toString() 464 { 465 return "RightSet [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs + "]"; 466 } 467 } 468 469 /** 470 * Provide a collection of GTUs that can overtake another collection of GTUs on the left side, but not vice versa. Example: 471 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}. 472 * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars, 473 * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not 474 * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR, 475 * TRUCK} in that lane. In addition, overtaking on the other side is allowed under a given driving speed. 476 * <p> 477 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 478 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 479 * </p> 480 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, 481 * initial version Sep 13, 2015 482 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 483 */ 484 public static class LeftSetRightSpeed implements OvertakingConditions, Serializable 485 { 486 /** */ 487 private static final long serialVersionUID = 20150913L; 488 489 /** A collection of GTUs that can overtake another collection of GTUs. */ 490 private final Collection<GTUType> overtakingGTUs; 491 492 /** A collection of GTUs that can be overtaken by another collection of GTUs. */ 493 private final Collection<GTUType> overtakenGTUs; 494 495 /** The speed under which overtaking on the "wrong" side is allowed. */ 496 private final Speed rightOvertakingSpeedMax; 497 498 /** 499 * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example: 500 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, 501 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. In addition, overtaking on the other side is allowed under a 502 * given driving speed. 503 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains 504 * GTUType.ALL, all GTUs can overtake. 505 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL, 506 * all GTUs can be overtaken. 507 * @param rightOvertakingSpeedMax the speed under which overtaking on the "wrong" side is allowed 508 */ 509 public LeftSetRightSpeed(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs, 510 final Speed rightOvertakingSpeedMax) 511 { 512 this.overtakingGTUs = overtakingGTUs; 513 this.overtakenGTUs = overtakenGTUs; 514 this.rightOvertakingSpeedMax = rightOvertakingSpeedMax; 515 } 516 517 /** {@inheritDoc} */ 518 @Override 519 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 520 final LaneBasedGTU predecessorGTU) 521 { 522 boolean left = ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType()) 523 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU.getGTUType())))); 524 boolean right = gtu.getSpeed().lt(this.rightOvertakingSpeedMax); 525 if (left) 526 { 527 return right ? OvertakingDirection.BOTH : OvertakingDirection.LEFT; 528 } 529 return right ? OvertakingDirection.RIGHT : OvertakingDirection.NONE; 530 } 531 532 /** {@inheritDoc} */ 533 @Override 534 public final String toString() 535 { 536 return "LeftSetRightSpeed [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs 537 + ", rightOvertakingSpeedMax=" + this.rightOvertakingSpeedMax + "]"; 538 } 539 } 540 541 /** 542 * Provide a collection of GTUs that can overtake another collection of GTUs on the right side, but not vice versa. Example: 543 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, SCOOTER}. 544 * In the latter case, cars, trucks and busses can overtake all other GTUs, but bicycles and scooters cannot overtake cars, 545 * trucks or busses. Another example is a lane where cars and motors can overtake all other road users, but trucks are not 546 * allowed to overtake. In that case, we would allow {CAR, MOTOR} to overtake {ALL} or {CAR, MOTOR} to overtake {CAR, MOTOR, 547 * TRUCK} in that lane. In addition, overtaking on the other side is allowed under a given driving speed. 548 * <p> 549 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 550 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 551 * </p> 552 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, 553 * initial version Sep 13, 2015 554 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 555 */ 556 public static class RightSetLeftSpeed implements OvertakingConditions, Serializable 557 { 558 /** */ 559 private static final long serialVersionUID = 20150913L; 560 561 /** A collection of GTUs that can overtake another collection of GTUs. */ 562 private final Collection<GTUType> overtakingGTUs; 563 564 /** A collection of GTUs that can be overtaken by another collection of GTUs. */ 565 private final Collection<GTUType> overtakenGTUs; 566 567 /** The speed under which overtaking on the "wrong" side is allowed. */ 568 private final Speed leftOvertakingSpeedMax; 569 570 /** 571 * Provide a collection of GTUs that can overtake another collection of GTUs on the left, but not vice versa. Example: 572 * {CAR, TRUCK, BUS} can overtake {BICYCLE, SCOOTER}, or {CAR, TRUCK, BUS} can overtake {CAR, TRUCK, BUS, BICYCLE, 573 * SCOOTER}, or {CAR, TRUCK, BUS} can overtake {TRACTOR}. In addition, overtaking on the other side is allowed under a 574 * given driving speed. 575 * @param overtakingGTUs the GTUs that can overtake a set of other GTUs, e.g., CAR, TRUCK. If overtakingGTUs contains 576 * GTUType.ALL, all GTUs can overtake. 577 * @param overtakenGTUs the GTUs that can be overtaken, e.g., BICYCLE, SCOOTER. If overtakenGTUs contains GTUType.ALL, 578 * all GTUs can be overtaken. 579 * @param leftOvertakingSpeedMax the speed under which overtaking on the "wrong" side is allowed 580 */ 581 public RightSetLeftSpeed(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs, 582 final Speed leftOvertakingSpeedMax) 583 { 584 this.overtakingGTUs = overtakingGTUs; 585 this.overtakenGTUs = overtakenGTUs; 586 this.leftOvertakingSpeedMax = leftOvertakingSpeedMax; 587 } 588 589 /** {@inheritDoc} */ 590 @Override 591 public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu, 592 final LaneBasedGTU predecessorGTU) 593 { 594 boolean right = ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType()) 595 && (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU.getGTUType())))); 596 boolean left = gtu.getSpeed().lt(this.leftOvertakingSpeedMax); 597 if (right) 598 { 599 return left ? OvertakingDirection.BOTH : OvertakingDirection.RIGHT; 600 } 601 return left ? OvertakingDirection.LEFT : OvertakingDirection.NONE; 602 } 603 604 /** {@inheritDoc} */ 605 @Override 606 public final String toString() 607 { 608 return "RightSetLeftSpeed [overtakingGTUs=" + this.overtakingGTUs + ", overtakenGTUs=" + this.overtakenGTUs 609 + ", leftOvertakingSpeedMax=" + this.leftOvertakingSpeedMax + "]"; 610 } 611 } 612 613 }