1 package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2
3 import java.util.SortedSet;
4
5 import org.djunits.unit.LengthUnit;
6 import org.djunits.value.vdouble.scalar.Acceleration;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.djunits.value.vdouble.scalar.Time;
10 import org.opentrafficsim.core.gtu.GTUException;
11 import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
12 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
13 import org.opentrafficsim.core.gtu.perception.EgoPerception;
14 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
15 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
16 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
17 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
18 import org.opentrafficsim.road.gtu.lane.perception.categories.BusStopPerception;
19 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayBusStop;
20 import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
21 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
22 import org.opentrafficsim.road.gtu.lane.tactical.pt.BusSchedule;
23 import org.opentrafficsim.road.gtu.lane.tactical.util.CarFollowingUtil;
24 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
25
26
27
28
29
30
31
32
33
34
35
36 public class AccelerationBusStop implements AccelerationIncentive
37 {
38
39
40
41 private static final Length STOP_DISTANCE = new Length(15.0, LengthUnit.SI);
42
43
44 @Override
45 @SuppressWarnings("checkstyle:parameternumber")
46 public void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final LaneBasedGTU gtu,
47 final LanePerception perception, final CarFollowingModel carFollowingModel, final Speed speed,
48 final BehavioralCharacteristics bc, final SpeedLimitInfo speedLimitInfo)
49 throws OperationalPlanException, ParameterException, GTUException
50 {
51 SortedSet<HeadwayBusStop> stops = perception.getPerceptionCategory(BusStopPerception.class).getBusStops();
52 if (stops.isEmpty())
53 {
54 return;
55 }
56 BusSchedule busSchedule = (BusSchedule) gtu.getStrategicalPlanner().getRoute();
57 Time now = gtu.getSimulator().getSimulatorTime().getTime();
58 for (HeadwayBusStop stop : stops)
59 {
60 String busStopId = stop.getId();
61 if (busSchedule.isLineStop(busStopId, now))
62 {
63
64
65 boolean stoppedAtStop = stop.getRelativeLane().isCurrent() && stop.getDistance().le(STOP_DISTANCE)
66 && perception.getPerceptionCategory(EgoPerception.class).getSpeed().eq0();
67 if (busSchedule.getActualDepartureBusStop(busStopId) == null)
68 {
69 if (stoppedAtStop)
70 {
71
72 Time departureTime = now.plus(busSchedule.getDwellTime(busStopId));
73 if (busSchedule.isForceSchedule(busStopId))
74 {
75 departureTime = Time.max(departureTime, busSchedule.getDepartureTime(busStopId));
76 }
77 busSchedule.setActualDeparture(busStopId, stop.getConflictIds(), departureTime);
78 }
79 }
80
81
82 if (busSchedule.getActualDepartureBusStop(busStopId) == null
83 || now.lt(busSchedule.getActualDepartureBusStop(busStopId)))
84 {
85 if (stoppedAtStop)
86 {
87
88 simplePlan.minimizeAcceleration(Acceleration.ZERO);
89 }
90 else
91 {
92
93 simplePlan.minimizeAcceleration(
94 CarFollowingUtil.stop(carFollowingModel, bc, speed, speedLimitInfo, stop.getDistance()));
95 }
96 }
97 }
98 }
99 }
100
101
102 @Override
103 public String toString()
104 {
105 return "AccelerationBusStop";
106 }
107
108 }