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-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
21   * <p>
22   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
23   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
24   */
25  public class IncentiveKeep implements VoluntaryIncentive
26  {
27  
28      /** Free lane change threshold parameter type. */
29      protected static final ParameterTypeDouble DFREE = LmrsParameters.DFREE;
30  
31      /** {@inheritDoc} */
32      @Override
33      public final Desire determineDesire(final Parameters parameters, final LanePerception perception,
34              final CarFollowingModel carFollowingModel, final Desire mandatoryDesire, final Desire voluntaryDesire)
35              throws ParameterException, OperationalPlanException
36      {
37          if (mandatoryDesire.getRight() < 0 || voluntaryDesire.getRight() < 0
38                  || !perception.getLaneStructure().getExtendedCrossSection().contains(RelativeLane.RIGHT))
39          {
40              // no desire to go right if more dominant incentives provide a negative desire to go right
41              return new Desire(0, 0);
42          }
43          // keep right with dFree
44          return new Desire(0, parameters.getParameter(DFREE));
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public final String toString()
50      {
51          return "IncentiveKeep";
52      }
53  
54  }