View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import java.util.SortedSet;
4   
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.djunits.value.vdouble.scalar.Time;
7   import org.opentrafficsim.core.gtu.GTUException;
8   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
9   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
10  import org.opentrafficsim.core.gtu.perception.EgoPerception;
11  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
12  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
13  import org.opentrafficsim.road.gtu.lane.perception.categories.BusStopPerception;
14  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayBusStop;
15  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
16  import org.opentrafficsim.road.gtu.lane.tactical.pt.BusSchedule;
17  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
18  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
19  
20  /**
21   * <p>
22   * Copyright (c) 2013-2017 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 BehavioralCharacteristics behavioralCharacteristics, final LanePerception perception,
36              final CarFollowingModel carFollowingModel, final Desire mandatoryDesire)
37              throws ParameterException, OperationalPlanException
38      {
39  
40          HeadwayBusStop firstStop = null;
41          SortedSet<HeadwayBusStop> stops = perception.getPerceptionCategory(BusStopPerception.class).getBusStops();
42          Time now;
43          try
44          {
45              now = perception.getGtu().getSimulator().getSimulatorTime().getTime();
46          }
47          catch (GTUException exception)
48          {
49              throw new RuntimeException("GTU not initialized.", exception);
50          }
51          for (HeadwayBusStop stop : stops)
52          {
53              try
54              {
55                  if (((BusSchedule) perception.getGtu().getStrategicalPlanner().getRoute()).isLineStop(stop.getId(), now))
56                  {
57                      firstStop = stop;
58                      break;
59                  }
60              }
61              catch (GTUException exception)
62              {
63                  throw new OperationalPlanException("Could not obtain bus schedule.", exception);
64              }
65          }
66  
67          if (firstStop == null)
68          {
69              return new Desire(0, 0);
70          }
71          Speed speed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
72          if (firstStop.getRelativeLane().isCurrent())
73          {
74              double d = -IncentiveRoute.getDesireToLeave(behavioralCharacteristics, firstStop.getDistance(), 1, speed);
75              return new Desire(d, d);
76          }
77  
78          int n = firstStop.getRelativeLane().getNumLanes();
79  
80          double dNotGood = -IncentiveRoute.getDesireToLeave(behavioralCharacteristics, firstStop.getDistance(), n + 1, speed);
81          double dGood = IncentiveRoute.getDesireToLeave(behavioralCharacteristics, firstStop.getDistance(), n, speed);
82          return firstStop.getRelativeLane().getLateralDirectionality().isRight() ? new Desire(dNotGood, dGood)
83                  : new Desire(dGood, dNotGood);
84  
85      }
86  
87      @Override
88      public final String toString()
89      {
90          return "IncentiveBusStop";
91      }
92  
93  }