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