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