View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.mental.channel;
2   
3   import java.util.Set;
4   import java.util.function.Function;
5   
6   import org.opentrafficsim.base.parameters.ParameterException;
7   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
8   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
9   import org.opentrafficsim.road.gtu.lane.perception.mental.AbstractTask;
10  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
11  
12  /**
13   * Task demand for lane changing left and right. This is defined as the level of lane change desire if the lane change desire in
14   * the relevant direction is equal or larger to the other direction. Otherwise it is 0.
15   * <p>
16   * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * </p>
19   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
20   */
21  public final class ChannelTaskLaneChange extends AbstractTask implements ChannelTask
22  {
23  
24      /** Current left lane change desire. */
25      private static final ParameterTypeDouble DLEFT = LmrsParameters.DLEFT;
26  
27      /** Current right lane change desire. */
28      private static final ParameterTypeDouble DRIGHT = LmrsParameters.DRIGHT;
29  
30      /** Standard set of left and right lane-change task. */
31      private static final Set<ChannelTask> SET = Set.of(new ChannelTaskLaneChange(true), new ChannelTaskLaneChange(false));
32  
33      /** Standard supplier that supplies instances for left and right lane-change task. */
34      public static final Function<LanePerception, Set<ChannelTask>> SUPPLIER = (p) -> SET;
35  
36      /** Whether this task instance regards the left side. */
37      private final boolean left;
38  
39      /**
40       * Constructor.
41       * @param left whether this task instance regards the left side.
42       */
43      private ChannelTaskLaneChange(final boolean left)
44      {
45          super("lane-changing");
46          this.left = left;
47      }
48  
49      @Override
50      public String getId()
51      {
52          return String.format("lane-changing (%s)", this.left ? "left" : "right");
53      }
54  
55      @Override
56      public Object getChannel()
57      {
58          return this.left ? LEFT : RIGHT;
59      }
60  
61      @Override
62      public double calculateTaskDemand(final LanePerception perception) throws ParameterException
63      {
64          double dLeft = perception.getGtu().getParameters().getParameter(DLEFT);
65          double dRight = perception.getGtu().getParameters().getParameter(DRIGHT);
66          return Math.min(0.999,
67                  this.left ? (dLeft >= dRight && dLeft > 0.0 ? dLeft : 0.0) : (dRight >= dLeft && dRight > 0.0 ? dRight : 0.0));
68      }
69  
70  }