IncentiveBusStop.java

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

  2. import org.djunits.value.vdouble.scalar.Speed;
  3. import org.djunits.value.vdouble.scalar.Time;
  4. import org.opentrafficsim.base.parameters.ParameterException;
  5. import org.opentrafficsim.base.parameters.Parameters;
  6. import org.opentrafficsim.core.gtu.GTUException;
  7. import org.opentrafficsim.core.gtu.perception.EgoPerception;
  8. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  9. import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
  10. import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
  11. import org.opentrafficsim.road.gtu.lane.perception.categories.BusStopPerception;
  12. import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayBusStop;
  13. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  14. import org.opentrafficsim.road.gtu.lane.tactical.pt.BusSchedule;
  15. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
  16. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
  17. import org.opentrafficsim.road.network.lane.object.BusStop;

  18. /**
  19.  * <p>
  20.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  21.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  22.  * <p>
  23.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 27 jan. 2017 <br>
  24.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  25.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  26.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  27.  */
  28. public class IncentiveBusStop implements MandatoryIncentive
  29. {

  30.     /** {@inheritDoc} */
  31.     @Override
  32.     public Desire determineDesire(final Parameters parameters, final LanePerception perception,
  33.             final CarFollowingModel carFollowingModel, final Desire mandatoryDesire)
  34.             throws ParameterException, OperationalPlanException
  35.     {

  36.         HeadwayBusStop firstStop = null;
  37.         PerceptionCollectable<HeadwayBusStop, BusStop> stops =
  38.                 perception.getPerceptionCategory(BusStopPerception.class).getBusStops();
  39.         Time now;
  40.         try
  41.         {
  42.             now = perception.getGtu().getSimulator().getSimulatorTime();
  43.         }
  44.         catch (GTUException exception)
  45.         {
  46.             throw new RuntimeException("GTU not initialized.", exception);
  47.         }
  48.         for (HeadwayBusStop stop : stops)
  49.         {
  50.             try
  51.             {
  52.                 if (((BusSchedule) perception.getGtu().getStrategicalPlanner().getRoute()).isLineStop(stop.getId(), now))
  53.                 {
  54.                     firstStop = stop;
  55.                     break;
  56.                 }
  57.             }
  58.             catch (GTUException exception)
  59.             {
  60.                 throw new OperationalPlanException("Could not obtain bus schedule.", exception);
  61.             }
  62.         }

  63.         if (firstStop == null)
  64.         {
  65.             return new Desire(0, 0);
  66.         }
  67.         Speed speed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
  68.         if (firstStop.getRelativeLane().isCurrent())
  69.         {
  70.             double d = -IncentiveRoute.getDesireToLeave(parameters, firstStop.getDistance(), 1, speed);
  71.             return new Desire(d, d);
  72.         }

  73.         int n = firstStop.getRelativeLane().getNumLanes();

  74.         double dNotGood = -IncentiveRoute.getDesireToLeave(parameters, firstStop.getDistance(), n + 1, speed);
  75.         double dGood = IncentiveRoute.getDesireToLeave(parameters, firstStop.getDistance(), n, speed);
  76.         return firstStop.getRelativeLane().getLateralDirectionality().isRight() ? new Desire(dNotGood, dGood)
  77.                 : new Desire(dGood, dNotGood);

  78.     }

  79.     @Override
  80.     public final String toString()
  81.     {
  82.         return "IncentiveBusStop";
  83.     }

  84. }