View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Speed;
4   import org.djunits.value.vdouble.scalar.Time;
5   import org.opentrafficsim.base.parameters.ParameterException;
6   import org.opentrafficsim.base.parameters.Parameters;
7   import org.opentrafficsim.core.gtu.GTUException;
8   import org.opentrafficsim.core.gtu.perception.EgoPerception;
9   import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
10  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
11  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
12  import org.opentrafficsim.road.gtu.lane.perception.categories.BusStopPerception;
13  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayBusStop;
14  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
15  import org.opentrafficsim.road.gtu.lane.tactical.pt.BusSchedule;
16  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
17  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
18  import org.opentrafficsim.road.network.lane.object.BusStop;
19  
20  /**
21   * <p>
22   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
24   * <p>
25   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 27 jan. 2017 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
28   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
29   */
30  public class IncentiveBusStop implements MandatoryIncentive
31  {
32  
33      /** {@inheritDoc} */
34      @Override
35      public Desire determineDesire(final Parameters parameters, final LanePerception perception,
36              final CarFollowingModel carFollowingModel, final Desire mandatoryDesire)
37              throws ParameterException, OperationalPlanException
38      {
39  
40          HeadwayBusStop firstStop = null;
41          PerceptionCollectable<HeadwayBusStop, BusStop> stops =
42                  perception.getPerceptionCategory(BusStopPerception.class).getBusStops();
43          Time now;
44          try
45          {
46              now = perception.getGtu().getSimulator().getSimulatorTime();
47          }
48          catch (GTUException exception)
49          {
50              throw new RuntimeException("GTU not initialized.", exception);
51          }
52          for (HeadwayBusStop stop : stops)
53          {
54              try
55              {
56                  if (((BusSchedule) perception.getGtu().getStrategicalPlanner().getRoute()).isLineStop(stop.getId(), now))
57                  {
58                      firstStop = stop;
59                      break;
60                  }
61              }
62              catch (GTUException exception)
63              {
64                  throw new OperationalPlanException("Could not obtain bus schedule.", exception);
65              }
66          }
67  
68          if (firstStop == null)
69          {
70              return new Desire(0, 0);
71          }
72          Speed speed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
73          if (firstStop.getRelativeLane().isCurrent())
74          {
75              double d = -IncentiveRoute.getDesireToLeave(parameters, firstStop.getDistance(), 1, speed);
76              return new Desire(d, d);
77          }
78  
79          int n = firstStop.getRelativeLane().getNumLanes();
80  
81          double dNotGood = -IncentiveRoute.getDesireToLeave(parameters, firstStop.getDistance(), n + 1, speed);
82          double dGood = IncentiveRoute.getDesireToLeave(parameters, firstStop.getDistance(), n, speed);
83          return firstStop.getRelativeLane().getLateralDirectionality().isRight() ? new Desire(dNotGood, dGood)
84                  : new Desire(dGood, dNotGood);
85  
86      }
87  
88      @Override
89      public final String toString()
90      {
91          return "IncentiveBusStop";
92      }
93  
94  }