IncentiveGetInLane.java

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

  2. import java.util.SortedSet;

  3. import org.djunits.value.vdouble.scalar.Speed;
  4. import org.opentrafficsim.base.parameters.ParameterException;
  5. import org.opentrafficsim.base.parameters.ParameterTypeDouble;
  6. import org.opentrafficsim.base.parameters.ParameterTypeSpeed;
  7. import org.opentrafficsim.base.parameters.ParameterTypes;
  8. import org.opentrafficsim.base.parameters.Parameters;
  9. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  10. import org.opentrafficsim.road.gtu.lane.perception.InfrastructureLaneChangeInfo;
  11. import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
  12. import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
  13. import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
  14. import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
  15. import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
  16. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  17. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
  18. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
  19. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;

  20. /**
  21.  * Incentive that lets drivers queue in an adjacent lane as soon as the speed is low in the adjacent lane, and stopping in the
  22.  * current lane might block traffic towards other directions.
  23.  * <p>
  24.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  25.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  26.  * <p>
  27.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 28 mrt. 2017 <br>
  28.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  29.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  30.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  31.  */
  32. public class IncentiveGetInLane implements MandatoryIncentive
  33. {

  34.     /** Congestion speed threshold parameter type. */
  35.     protected static final ParameterTypeSpeed VCONG = ParameterTypes.VCONG;

  36.     /** Hierarchy parameter. */
  37.     protected static final ParameterTypeDouble SOCIO = LmrsParameters.SOCIO;

  38.     /** {@inheritDoc} */
  39.     @Override
  40.     public Desire determineDesire(final Parameters parameters, final LanePerception perception,
  41.             final CarFollowingModel carFollowingModel, final Desire mandatoryDesire)
  42.             throws ParameterException, OperationalPlanException
  43.     {

  44.         Speed vCong = parameters.getParameter(VCONG);
  45.         double socio = parameters.getParameter(SOCIO);
  46.         InfrastructurePerception infra = perception.getPerceptionCategory(InfrastructurePerception.class);
  47.         NeighborsPerception neighbors = perception.getPerceptionCategory(NeighborsPerception.class);
  48.         SortedSet<InfrastructureLaneChangeInfo> info = infra.getInfrastructureLaneChangeInfo(RelativeLane.CURRENT);
  49.         double dCur = info.isEmpty() ? Double.POSITIVE_INFINITY
  50.                 : info.first().getRemainingDistance().si / info.first().getRequiredNumberOfLaneChanges();
  51.         double left = 0;
  52.         double right = 0;
  53.         double vCur = Double.POSITIVE_INFINITY;

  54.         for (RelativeLane lane : new RelativeLane[] {RelativeLane.LEFT, RelativeLane.RIGHT})
  55.         {
  56.             if (infra.getCrossSection().contains(lane))
  57.             {
  58.                 SortedSet<InfrastructureLaneChangeInfo> adjInfo = infra.getInfrastructureLaneChangeInfo(lane);
  59.                 double dAdj = adjInfo.isEmpty() ? Double.POSITIVE_INFINITY
  60.                         : adjInfo.first().getRemainingDistance().si / adjInfo.first().getRequiredNumberOfLaneChanges();
  61.                 if (!info.isEmpty() && !info.first().isDeadEnd() && dCur < dAdj)
  62.                 {
  63.                     double v = Double.POSITIVE_INFINITY;
  64.                     for (HeadwayGTU neighbor : neighbors.getLeaders(lane))
  65.                     {
  66.                         v = Math.min(v, neighbor.getSpeed().si);
  67.                     }
  68.                     if (lane.isLeft())
  69.                     {
  70.                         double d = Math.max(0.0, 1.0 - v / vCong.si);
  71.                         left += d;
  72.                         // right -= d;
  73.                     }
  74.                     else
  75.                     {
  76.                         double d = Math.max(0.0, 1.0 - v / vCong.si);
  77.                         right += d;
  78.                         // left -= d;
  79.                     }
  80.                 }
  81.                 if (!adjInfo.isEmpty() && !adjInfo.first().isDeadEnd()
  82.                         && (info.isEmpty() || (!info.isEmpty() && !info.first().isDeadEnd())) && dCur > dAdj)
  83.                 {
  84.                     if (Double.isInfinite(vCur))
  85.                     {
  86.                         for (HeadwayGTU neighbor : neighbors.getLeaders(RelativeLane.CURRENT))
  87.                         {
  88.                             vCur = Math.min(vCur, neighbor.getSpeed().si);
  89.                         }
  90.                     }
  91.                     if (lane.isLeft())
  92.                     {
  93.                         left -= Math.max(0.0, 1.0 - vCur / vCong.si);
  94.                     }
  95.                     else
  96.                     {
  97.                         right -= Math.max(0.0, 1.0 - vCur / vCong.si);
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.         return new Desire(left * socio, right * socio);
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public final String toString()
  107.     {
  108.         return "IncentiveGetInLane";
  109.     }

  110. }