View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.util.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Dimensionless;
4   import org.opentrafficsim.base.OtsRuntimeException;
5   import org.opentrafficsim.core.network.LateralDirectionality;
6   
7   /**
8    * Reflects the level of lane change desire a driver experiences in both the left and right direction. This may be either total
9    * 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
10   * means full desire. Values above 1 are not valid 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   * <p>
13   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * </p>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   * @param left Left desire.
18   * @param right Right desire.
19   */
20  public record Desire(double left, double right)
21  {
22  
23      /** Easy access and efficient zero desired. */
24      public static final Desire ZERO = new Desire(0.0, 0.0);
25  
26      /**
27       * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
28       * @param left Left desire.
29       * @param right Right desire.
30       */
31      public Desire(final double left, final double right)
32      {
33          this.left = left <= 1 ? left : 1;
34          this.right = right <= 1 ? right : 1;
35      }
36  
37      /**
38       * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
39       * @param left Left desire.
40       * @param right Right desire.
41       */
42      public Desire(final Dimensionless left, final Dimensionless right)
43      {
44          this(left.si, right.si);
45      }
46  
47      /**
48       * Returns desire in the given direction.
49       * @param dir Direction for the desire to return.
50       * @return Desire in the given direction.
51       */
52      public final double get(final LateralDirectionality dir)
53      {
54          if (dir.equals(LateralDirectionality.LEFT))
55          {
56              return this.left;
57          }
58          if (dir.equals(LateralDirectionality.RIGHT))
59          {
60              return this.right;
61          }
62          throw new OtsRuntimeException("Lateral direction may not be NONE.");
63      }
64  
65      /**
66       * Returns whether the left desire is larger than (or equal to) the right.
67       * @return Returns whether the left desire is larger than (or equal to) the right.
68       */
69      public final boolean leftIsLargerOrEqual()
70      {
71          return this.left >= this.right;
72      }
73  
74  }