1 package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2
3 import org.opentrafficsim.core.network.LateralDirectionality;
4
5 /**
6 * Reflects the level of lane change desire a driver experiences in both the
7 * left and right direction. This may be either total desire, or only for a
8 * single lane change incentive. Desire is defined as ranging from 0 to 1,
9 * where 0 means no desire and 1 means full desire. Values above 1 are not valid
10 * and should be limited to 1. Values below 0 are allowed and reflect that a
11 * lane change is undesired (which is different from not desired).
12 * @author Wouter Schakel
13 */
14 public class Desire {
15
16 /** Level of left desire. */
17 private final double left;
18
19 /** Level of right desire. */
20 private final double right;
21
22 /**
23 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
24 * @param left Left desire.
25 * @param right Right desire.
26 */
27 public Desire(final double left, final double right) {
28 this.left = left<=1 ? left : 1;;
29 this.right = right<=1 ? right : 1;;
30 }
31
32 /**
33 * Returns desire in the given direction.
34 * @param dir Direction for the desire to return.
35 * @return Desire in the given direction.
36 */
37 public double get(LateralDirectionality dir) {
38 if (dir==LateralDirectionality.LEFT) {
39 return this.left;
40 } else if (dir==LateralDirectionality.RIGHT) {
41 return this.right;
42 }
43 throw new NullPointerException("Lateral direction may not be null.");
44 }
45
46 /**
47 * Returns lane change desire to left.
48 * @return Lane change desire to left.
49 */
50 public double getLeft() {
51 return this.left;
52 }
53
54 /**
55 * Returns lane change desire to right.
56 * @return Lane change desire to right.
57 */
58 public double getRight() {
59 return this.right;
60 }
61
62 /**
63 * Returns whether the left desire is larger than (or equal to) the right.
64 * @return Returns whether the left desire is larger than (or equal to) the right.
65 */
66 public boolean leftIsLargerOrEqual() {
67 return this.left>=this.right;
68 }
69
70 }