View Javadoc
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-2024 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://github.com/wjschakel">Wouter Schakel</a>
18   * @param left double; Left desire.
19   * @param right double; Right desire.
20   */
21  public record Desire(double left, double right) implements Serializable
22  {
23  
24      /** */
25      private static final long serialVersionUID = 20160413L;
26  
27      /** Easy access and efficient zero desired. */
28      public static final Desire ZERO = new Desire(0.0, 0.0);
29  
30      /**
31       * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
32       * @param left double; Left desire.
33       * @param right double; Right desire.
34       */
35      public Desire(final double left, final double right)
36      {
37          this.left = left <= 1 ? left : 1;
38          this.right = right <= 1 ? right : 1;
39      }
40  
41      /**
42       * Constructor which sets the supplied desire. Desire is limited to a maximum of 1.
43       * @param left Dimensionless; Left desire.
44       * @param right Dimensionless; Right desire.
45       */
46      public Desire(final Dimensionless left, final Dimensionless right)
47      {
48          this(left.si, right.si);
49      }
50  
51      /**
52       * Returns desire in the given direction.
53       * @param dir LateralDirectionality; Direction for the desire to return.
54       * @return Desire in the given direction.
55       */
56      public final double get(final LateralDirectionality dir)
57      {
58          if (dir.equals(LateralDirectionality.LEFT))
59          {
60              return this.left;
61          }
62          if (dir.equals(LateralDirectionality.RIGHT))
63          {
64              return this.right;
65          }
66          throw new RuntimeException("Lateral direction may not be NONE.");
67      }
68  
69      /**
70       * Returns whether the left desire is larger than (or equal to) the right.
71       * @return Returns whether the left desire is larger than (or equal to) the right.
72       */
73      public final boolean leftIsLargerOrEqual()
74      {
75          return this.left >= this.right;
76      }
77  
78  }