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
22
23
24
25
26
27
28
29
30 public class IncentiveBusStop implements MandatoryIncentive
31 {
32
33
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 }