View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.opentrafficsim.base.parameters.ParameterException;
4   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
5   import org.opentrafficsim.base.parameters.Parameters;
6   import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
7   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
8   import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
9   import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
10  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
11  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
12  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
13  
14  /**
15   * Determines lane change desire in order to adhere to keeping right or left. Such desire only exists if the route and speed
16   * (considered within an anticipation distance) are not affected on the adjacent lane. The level of lane change desire is only
17   * sufficient to overcome the lowest threshold for free lane changes.
18   * <p>
19   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21   * </p>
22   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
23   */
24  public class IncentiveKeep implements VoluntaryIncentive
25  {
26  
27      /** Free lane change threshold parameter type. */
28      protected static final ParameterTypeDouble DFREE = LmrsParameters.DFREE;
29  
30      /** {@inheritDoc} */
31      @Override
32      public final Desire determineDesire(final Parameters parameters, final LanePerception perception,
33              final CarFollowingModel carFollowingModel, final Desire mandatoryDesire, final Desire voluntaryDesire)
34              throws ParameterException, OperationalPlanException
35      {
36          if (mandatoryDesire.right() < 0 || voluntaryDesire.right() < 0
37                  || !perception.getLaneStructure().exists(RelativeLane.RIGHT))
38          {
39              // no desire to go right if more dominant incentives provide a negative desire to go right
40              return new Desire(0, 0);
41          }
42          // keep right with dFree
43          return new Desire(0, parameters.getParameter(DFREE));
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public final String toString()
49      {
50          return "IncentiveKeep";
51      }
52  
53  }