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-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15 * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
16 * <p>
17 * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
18 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
19 */
20 public class Desire implements Serializable
21 {
22
23 /** */
24 private static final long serialVersionUID = 20160413L;
25
26 /** Level of left desire. */
27 private final double left;
28
29 /** Level of right desire. */
30 private final double right;
31
32 /** Easy access and efficient zero desired. */
33 public static final Desirecsim/road/gtu/lane/tactical/util/lmrs/Desire.html#Desire">Desire ZERO = new Desire(0.0, 0.0);
34
35 /**
36 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
37 * @param left double; Left desire.
38 * @param right double; Right desire.
39 */
40 public Desire(final double left, final double right)
41 {
42 this.left = left <= 1 ? left : 1;
43 this.right = right <= 1 ? right : 1;
44 }
45
46 /**
47 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
48 * @param left Dimensionless; Left desire.
49 * @param right Dimensionless; Right desire.
50 */
51 public Desire(final Dimensionless left, final Dimensionless right)
52 {
53 this(left.si, right.si);
54 }
55
56 /**
57 * Returns desire in the given direction.
58 * @param dir LateralDirectionality; Direction for the desire to return.
59 * @return Desire in the given direction.
60 */
61 public final double get(final LateralDirectionality dir)
62 {
63 if (dir.equals(LateralDirectionality.LEFT))
64 {
65 return this.left;
66 }
67 if (dir.equals(LateralDirectionality.RIGHT))
68 {
69 return this.right;
70 }
71 throw new RuntimeException("Lateral direction may not be NONE.");
72 }
73
74 /**
75 * Returns lane change desire to left.
76 * @return Lane change desire to left.
77 */
78 public final double getLeft()
79 {
80 return this.left;
81 }
82
83 /**
84 * Returns lane change desire to right.
85 * @return Lane change desire to right.
86 */
87 public final double getRight()
88 {
89 return this.right;
90 }
91
92 /**
93 * Returns whether the left desire is larger than (or equal to) the right.
94 * @return Returns whether the left desire is larger than (or equal to) the right.
95 */
96 public final boolean leftIsLargerOrEqual()
97 {
98 return this.left >= this.right;
99 }
100
101 /** {@inheritDoc} */
102 @Override
103 public final String toString()
104 {
105 return "Desire [left=" + this.left + ", right=" + this.right + "]";
106 }
107
108 }