1 package org.opentrafficsim.road.gtu.lane.tactical.util.lmrs;
2
3 import static org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.GapAcceptance.egoAcceleration;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.value.vdouble.scalar.Acceleration;
7 import org.djunits.value.vdouble.scalar.Speed;
8 import org.opentrafficsim.base.parameters.ParameterException;
9 import org.opentrafficsim.base.parameters.ParameterTypes;
10 import org.opentrafficsim.base.parameters.Parameters;
11 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
12 import org.opentrafficsim.core.network.LateralDirectionality;
13 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
14 import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
15 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGtu;
16 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
17 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
18
19
20
21
22
23
24
25
26
27
28
29 public interface GapAcceptance
30 {
31
32
33 GapAcceptance INFORMED = new GapAcceptance()
34 {
35
36 @Override
37 public boolean acceptGap(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
38 final CarFollowingModel cfm, final double desire, final Speed ownSpeed, final Acceleration ownAcceleration,
39 final LateralDirectionality lat) throws ParameterException, OperationalPlanException
40 {
41 NeighborsPerception neighbors = perception.getPerceptionCategory(NeighborsPerception.class);
42 if (neighbors.isGtuAlongside(lat))
43 {
44
45 return false;
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 Acceleration b = params.getParameter(ParameterTypes.B);
64 Acceleration aFollow = new Acceleration(Double.POSITIVE_INFINITY, AccelerationUnit.SI);
65 for (HeadwayGtu follower : neighbors.getFirstFollowers(lat))
66 {
67 if (follower.getSpeed().gt0() || follower.getAcceleration().gt0() || follower.getDistance().si < 1.0)
68 {
69 Acceleration a = LmrsUtil.singleAcceleration(follower.getDistance(), follower.getSpeed(), ownSpeed, desire,
70 follower.getParameters(), follower.getSpeedLimitInfo(), follower.getCarFollowingModel());
71 aFollow = Acceleration.min(aFollow, a);
72 }
73 }
74
75 Acceleration aSelf = egoAcceleration(perception, params, sli, cfm, desire, ownSpeed, lat);
76 Acceleration threshold = b.times(-desire);
77 return aFollow.ge(threshold) && aSelf.ge(threshold) && ownAcceleration.ge(threshold);
78 }
79
80
81 @Override
82 public String toString()
83 {
84 return "INFORMED";
85 }
86 };
87
88
89 GapAcceptance EGO_HEADWAY = new GapAcceptance()
90 {
91
92 @Override
93 public boolean acceptGap(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
94 final CarFollowingModel cfm, final double desire, final Speed ownSpeed, final Acceleration ownAcceleration,
95 final LateralDirectionality lat) throws ParameterException, OperationalPlanException
96 {
97 NeighborsPerception neigbors = perception.getPerceptionCategory(NeighborsPerception.class);
98 if (neigbors.isGtuAlongside(lat))
99 {
100
101 return false;
102 }
103
104 Acceleration b = params.getParameter(ParameterTypes.B);
105 Acceleration aFollow = new Acceleration(Double.POSITIVE_INFINITY, AccelerationUnit.SI);
106 for (HeadwayGtu follower : neigbors.getFirstFollowers(lat))
107 {
108 if (follower.getSpeed().gt0() || follower.getAcceleration().gt0())
109 {
110
111 Parameters folParams = follower.getParameters();
112 folParams.setParameterResettable(ParameterTypes.TMIN, params.getParameter(ParameterTypes.TMIN));
113 folParams.setParameterResettable(ParameterTypes.TMAX, params.getParameter(ParameterTypes.TMAX));
114 Acceleration a = LmrsUtil.singleAcceleration(follower.getDistance(), follower.getSpeed(), ownSpeed, desire,
115 folParams, follower.getSpeedLimitInfo(), follower.getCarFollowingModel());
116 aFollow = Acceleration.min(aFollow, a);
117 folParams.resetParameter(ParameterTypes.TMIN);
118 folParams.resetParameter(ParameterTypes.TMAX);
119 }
120 }
121
122 Acceleration aSelf = egoAcceleration(perception, params, sli, cfm, desire, ownSpeed, lat);
123 Acceleration threshold = b.times(-desire);
124 return aFollow.ge(threshold) && aSelf.ge(threshold);
125 }
126
127
128 @Override
129 public String toString()
130 {
131 return "EGO_HEADWAY";
132 }
133 };
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 static Acceleration egoAcceleration(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
149 final CarFollowingModel cfm, final double desire, final Speed ownSpeed, final LateralDirectionality lat)
150 throws ParameterException, OperationalPlanException
151 {
152 Acceleration aSelf = new Acceleration(Double.POSITIVE_INFINITY, AccelerationUnit.SI);
153 if (ownSpeed.gt0())
154 {
155 for (
156
157 HeadwayGtu leader : perception.getPerceptionCategory(NeighborsPerception.class).getFirstLeaders(lat))
158 {
159 Acceleration a = LmrsUtil.singleAcceleration(leader.getDistance(), ownSpeed, leader.getSpeed(), desire, params,
160 sli, cfm);
161 aSelf = Acceleration.min(aSelf, a);
162 }
163 }
164 return aSelf;
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 boolean acceptGap(LanePerception perception, Parameters params, SpeedLimitInfo sli, CarFollowingModel cfm, double desire,
182 Speed ownSpeed, Acceleration ownAcceleration, LateralDirectionality lat)
183 throws ParameterException, OperationalPlanException;
184
185 }