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      @Override
31      public final Desire determineDesire(final Parameters parameters, final LanePerception perception,
32              final CarFollowingModel carFollowingModel, final Desire mandatoryDesire, final Desire voluntaryDesire)
33              throws ParameterException, OperationalPlanException
34      {
35          if (mandatoryDesire.right() < 0 || voluntaryDesire.right() < 0
36                  || !perception.getLaneStructure().exists(RelativeLane.RIGHT))
37          {
38              // no desire to go right if more dominant incentives provide a negative desire to go right
39              return new Desire(0, 0);
40          }
41          // keep right with dFree
42          return new Desire(0, parameters.getParameter(DFREE));
43      }
44  
45      @Override
46      public final String toString()
47      {
48          return "IncentiveKeep";
49      }
50  
51  }