1 package org.opentrafficsim.road.gtu.lane.tactical.util.lmrs;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Dimensionless;
6 import org.opentrafficsim.core.network.LateralDirectionality;
7
8 /**
9 * Reflects the level of lane change desire a driver experiences in both the left and right direction. This may be either total
10 * desire, or only for a single lane change incentive. Desire is defined as ranging from 0 to 1, where 0 means no desire and 1
11 * means full desire. Values above 1 are not valid and should be limited to 1. Values below 0 are allowed and reflect that a
12 * lane change is undesired (which is different from not desired).
13 * <p>
14 * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16 * </p>
17 * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
18 */
19 public class Desire implements Serializable
20 {
21
22 /** */
23 private static final long serialVersionUID = 20160413L;
24
25 /** Level of left desire. */
26 private final double left;
27
28 /** Level of right desire. */
29 private final double right;
30
31 /** Easy access and efficient zero desired. */
32 public static final Desire ZERO = new Desire(0.0, 0.0);
33
34 /**
35 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
36 * @param left double; Left desire.
37 * @param right double; Right desire.
38 */
39 public Desire(final double left, final double right)
40 {
41 this.left = left <= 1 ? left : 1;
42 this.right = right <= 1 ? right : 1;
43 }
44
45 /**
46 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
47 * @param left Dimensionless; Left desire.
48 * @param right Dimensionless; Right desire.
49 */
50 public Desire(final Dimensionless left, final Dimensionless right)
51 {
52 this(left.si, right.si);
53 }
54
55 /**
56 * Returns desire in the given direction.
57 * @param dir LateralDirectionality; Direction for the desire to return.
58 * @return Desire in the given direction.
59 */
60 public final double get(final LateralDirectionality dir)
61 {
62 if (dir.equals(LateralDirectionality.LEFT))
63 {
64 return this.left;
65 }
66 if (dir.equals(LateralDirectionality.RIGHT))
67 {
68 return this.right;
69 }
70 throw new RuntimeException("Lateral direction may not be NONE.");
71 }
72
73 /**
74 * Returns lane change desire to left.
75 * @return Lane change desire to left.
76 */
77 public final double getLeft()
78 {
79 return this.left;
80 }
81
82 /**
83 * Returns lane change desire to right.
84 * @return Lane change desire to right.
85 */
86 public final double getRight()
87 {
88 return this.right;
89 }
90
91 /**
92 * Returns whether the left desire is larger than (or equal to) the right.
93 * @return Returns whether the left desire is larger than (or equal to) the right.
94 */
95 public final boolean leftIsLargerOrEqual()
96 {
97 return this.left >= this.right;
98 }
99
100 /** {@inheritDoc} */
101 @Override
102 public final String toString()
103 {
104 return "Desire [left=" + this.left + ", right=" + this.right + "]";
105 }
106
107 }