1 package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2
3 import java.util.LinkedHashSet;
4
5 import nl.tudelft.simulation.language.d3.DirectedPoint;
6
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.behavioralcharacteristics.ParameterTypes;
14 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
15 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
16 import org.opentrafficsim.core.network.NetworkException;
17 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
18 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
19 import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
20 import org.opentrafficsim.road.gtu.lane.perception.categories.IntersectionPerception;
21 import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
22 import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
23 import org.opentrafficsim.road.gtu.lane.plan.operational.LaneOperationalPlanBuilder.LaneChange;
24 import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlanner;
25 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
26 import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil;
27 import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil.ConflictPlans;
28 import org.opentrafficsim.road.gtu.lane.tactical.util.SpeedLimitUtil;
29 import org.opentrafficsim.road.gtu.lane.tactical.util.TrafficLightUtil;
30 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil;
31 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
32 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
33 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil.LmrsStatus;
34 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
35 import org.opentrafficsim.road.network.speed.SpeedLimitProspect;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class LMRS extends AbstractLaneBasedTacticalPlanner
52 {
53
54
55 private static final long serialVersionUID = 20160300L;
56
57
58 private final ConflictPlans yieldPlans = new ConflictPlans();
59
60
61 private final LaneChange laneChange = new LaneChange();
62
63
64 private final LmrsStatus lmrsStatus = new LmrsStatus();
65
66
67 private final LinkedHashSet<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();
68
69
70 private final LinkedHashSet<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();
71
72
73
74
75
76
77 public LMRS(final CarFollowingModel carFollowingModel, final LaneBasedGTU gtu)
78 {
79 super(carFollowingModel, gtu);
80 }
81
82
83
84
85
86 public final void addMandatoryIncentive(final MandatoryIncentive incentive)
87 {
88 if (incentive != null)
89 {
90 this.mandatoryIncentives.add(incentive);
91 }
92 }
93
94
95
96
97
98 public final void addVoluntaryIncentive(final VoluntaryIncentive incentive)
99 {
100 if (incentive != null)
101 {
102 this.voluntaryIncentives.add(incentive);
103 }
104 }
105
106
107
108
109 public final void setDefaultIncentives()
110 {
111 this.mandatoryIncentives.clear();
112 this.voluntaryIncentives.clear();
113 this.mandatoryIncentives.add(new IncentiveRoute());
114 this.voluntaryIncentives.add(new IncentiveSpeedWithCourtesy());
115 this.voluntaryIncentives.add(new IncentiveKeep());
116 }
117
118
119 @Override
120 public final OperationalPlan generateOperationalPlan(final Time startTime, final DirectedPoint locationAtStartTime)
121 throws OperationalPlanException, GTUException, NetworkException, ParameterException
122 {
123
124 getPerception().perceive();
125 SpeedLimitProspect slp = getPerception().getPerceptionCategory(InfrastructurePerception.class)
126 .getSpeedLimitProspect(RelativeLane.CURRENT);
127 SpeedLimitInfo sli = slp.getSpeedLimitInfo(Length.ZERO);
128 BehavioralCharacteristics bc = getGtu().getBehavioralCharacteristics();
129
130
131 SimpleOperationalPlan simplePlan = LmrsUtil.determinePlan(getGtu(), startTime, this.lmrsStatus, getCarFollowingModel(),
132 this.laneChange, getPerception(), this.mandatoryIncentives, this.voluntaryIncentives);
133
134
135 Speed speed = getGtu().getSpeed();
136 simplePlan.minimumAcceleration(SpeedLimitUtil.considerSpeedLimitTransitions(bc, speed, slp, getCarFollowingModel()));
137
138
139
140 simplePlan.minimumAcceleration(TrafficLightUtil.respondToTrafficLights(bc,
141 getPerception().getPerceptionCategory(IntersectionPerception.class).getTrafficLights(RelativeLane.CURRENT),
142 getCarFollowingModel(), speed, sli));
143
144
145 simplePlan.minimumAcceleration(ConflictUtil.approachConflicts(bc,
146 getPerception().getPerceptionCategory(IntersectionPerception.class).getConflicts(RelativeLane.CURRENT),
147 getPerception().getPerceptionCategory(NeighborsPerception.class).getLeaders(RelativeLane.CURRENT),
148 getCarFollowingModel(), getGtu().getLength(), speed, sli, this.yieldPlans));
149
150
151 return buildPlanFromSimplePlan(getGtu(), startTime, bc, simplePlan, this.laneChange);
152
153 }
154
155
156 @Override
157 public final String toString()
158 {
159 String mandatory;
160 mandatory = "mandatoryIncentives=" + this.mandatoryIncentives + ", ";
161 String voluntary;
162 if (!this.voluntaryIncentives.isEmpty())
163 {
164 voluntary = "voluntaryIncentives=" + this.voluntaryIncentives;
165 }
166 else
167 {
168 voluntary = "voluntaryIncentives=[]";
169 }
170 return "LMRS [" + mandatory + voluntary + "]";
171 }
172
173 }