1 package org.opentrafficsim.road.gtu.lane.tactical;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import nl.tudelft.simulation.language.d3.DirectedPoint;
7
8 import org.djunits.unit.TimeUnit;
9 import org.djunits.value.vdouble.scalar.Time;
10 import org.opentrafficsim.core.gtu.GTU;
11 import org.opentrafficsim.core.gtu.GTUException;
12 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
13 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan.Segment;
14 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
15 import org.opentrafficsim.core.network.NetworkException;
16 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
17 import org.opentrafficsim.road.gtu.lane.perception.LanePerceptionFull;
18 import org.opentrafficsim.road.gtu.lane.tactical.following.AccelerationStep;
19 import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;
20 import org.opentrafficsim.road.gtu.lane.tactical.following.HeadwayGTU;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class LaneBasedGTUFollowingTacticalPlanner extends AbstractLaneBasedTacticalPlanner
38 {
39
40 private static final long serialVersionUID = 20151125L;
41
42
43
44
45 public LaneBasedGTUFollowingTacticalPlanner()
46 {
47 super();
48 }
49
50
51 @Override
52 public OperationalPlan generateOperationalPlan(final GTU gtu, final Time.Abs startTime,
53 final DirectedPoint locationAtStartTime) throws OperationalPlanException, NetworkException, GTUException
54 {
55
56 LaneBasedGTU laneBasedGTU = (LaneBasedGTU) gtu;
57 LanePerceptionFull perception = laneBasedGTU.getPerception();
58
59
60 if (laneBasedGTU.getMaximumVelocity().si < OperationalPlan.DRIFTING_SPEED_SI)
61 {
62 return new OperationalPlan(gtu, locationAtStartTime, startTime, new Time.Rel(1.0, TimeUnit.SECOND));
63 }
64
65
66 perception.perceive();
67
68
69 GTUFollowingModelOld gtuFollowingModel =
70 laneBasedGTU.getStrategicalPlanner().getDrivingCharacteristics().getGTUFollowingModel();
71
72
73 LanePathInfo lanePathInfo =
74 buildLanePathInfo(laneBasedGTU, laneBasedGTU.getBehavioralCharacteristics().getForwardHeadwayDistance());
75
76
77 HeadwayGTU headwayGTU = perception.getForwardHeadwayGTU();
78 AccelerationStep accelerationStep = null;
79 if (headwayGTU.getGtuId() == null)
80 {
81 accelerationStep =
82 gtuFollowingModel.computeAccelerationStepWithNoLeader(laneBasedGTU, lanePathInfo.getPath().getLength(),
83 perception.getSpeedLimit());
84 }
85 else
86 {
87 accelerationStep =
88 gtuFollowingModel.computeAccelerationStep(laneBasedGTU, headwayGTU.getGtuSpeed(), headwayGTU.getDistance(),
89 lanePathInfo.getPath().getLength(), perception.getSpeedLimit());
90 }
91
92
93 if (accelerationStep.getAcceleration().si < 1E-6
94 && laneBasedGTU.getVelocity().si < OperationalPlan.DRIFTING_SPEED_SI)
95 {
96 return new OperationalPlan(gtu, locationAtStartTime, startTime, accelerationStep.getDuration());
97 }
98
99 List<Segment> operationalPlanSegmentList = new ArrayList<>();
100 if (accelerationStep.getAcceleration().si == 0.0)
101 {
102 Segment segment = new OperationalPlan.SpeedSegment(accelerationStep.getDuration());
103 operationalPlanSegmentList.add(segment);
104 }
105 else
106 {
107 Segment segment =
108 new OperationalPlan.AccelerationSegment(accelerationStep.getDuration(),
109 accelerationStep.getAcceleration());
110 operationalPlanSegmentList.add(segment);
111 }
112 OperationalPlan op =
113 new OperationalPlan(gtu, lanePathInfo.getPath(), startTime, gtu.getVelocity(), operationalPlanSegmentList);
114 return op;
115 }
116 }