IncentiveKeep.java

  1. package org.opentrafficsim.road.gtu.lane.tactical.lmrs;

  2. import org.opentrafficsim.base.parameters.ParameterException;
  3. import org.opentrafficsim.base.parameters.ParameterTypeDouble;
  4. import org.opentrafficsim.base.parameters.Parameters;
  5. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  6. import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
  7. import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
  8. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  9. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
  10. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
  11. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;

  12. /**
  13.  * Determines lane change desire in order to adhere to keeping right or left. Such desire only exists if the route and speed
  14.  * (considered within an anticipation distance) are not affected on the adjacent lane. The level of lane change desire is only
  15.  * sufficient to overcome the lowest threshold for free lane changes.
  16.  * <p>
  17.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  18.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  19.  * <p>
  20.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
  21.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  22.  */
  23. public class IncentiveKeep implements VoluntaryIncentive
  24. {

  25.     /** Free lane change threshold parameter type. */
  26.     protected static final ParameterTypeDouble DFREE = LmrsParameters.DFREE;

  27.     /** {@inheritDoc} */
  28.     @Override
  29.     public final Desire determineDesire(final Parameters parameters, final LanePerception perception,
  30.             final CarFollowingModel carFollowingModel, final Desire mandatoryDesire, final Desire voluntaryDesire)
  31.             throws ParameterException, OperationalPlanException
  32.     {
  33.         if (mandatoryDesire.getRight() < 0 || voluntaryDesire.getRight() < 0
  34.                 || !perception.getLaneStructure().getExtendedCrossSection().contains(RelativeLane.RIGHT))
  35.         {
  36.             // no desire to go right if more dominant incentives provide a negative desire to go right
  37.             return new Desire(0, 0);
  38.         }
  39.         // keep right with dFree
  40.         return new Desire(0, parameters.getParameter(DFREE));
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public final String toString()
  45.     {
  46.         return "IncentiveKeep";
  47.     }

  48. }