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-2016 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 /**
33 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
34 * @param left Left desire.
35 * @param right Right desire.
36 */
37 public Desire(final double left, final double right)
38 {
39 this.left = left <= 1 ? left : 1;
40 this.right = right <= 1 ? right : 1;
41 }
42
43 /**
44 * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
45 * @param left Left desire.
46 * @param right Right desire.
47 */
48 public Desire(final Dimensionless left, final Dimensionless right)
49 {
50 this(left.si, right.si);
51 }
52
53 /**
54 * Returns desire in the given direction.
55 * @param dir Direction for the desire to return.
56 * @return Desire in the given direction.
57 */
58 public final double get(final LateralDirectionality dir)
59 {
60 if (dir.equals(LateralDirectionality.LEFT))
61 {
62 return this.left;
63 }
64 if (dir.equals(LateralDirectionality.RIGHT))
65 {
66 return this.right;
67 }
68 throw new RuntimeException("Lateral direction may not be NONE.");
69 }
70
71 /**
72 * Returns lane change desire to left.
73 * @return Lane change desire to left.
74 */
75 public final double getLeft()
76 {
77 return this.left;
78 }
79
80 /**
81 * Returns lane change desire to right.
82 * @return Lane change desire to right.
83 */
84 public final double getRight()
85 {
86 return this.right;
87 }
88
89 /**
90 * Returns whether the left desire is larger than (or equal to) the right.
91 * @return Returns whether the left desire is larger than (or equal to) the right.
92 */
93 public final boolean leftIsLargerOrEqual()
94 {
95 return this.left >= this.right;
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public final String toString()
101 {
102 return "Desire [left=" + this.left + ", right=" + this.right + "]";
103 }
104
105 }