1 package org.opentrafficsim.road.gtu.lane.tactical.following;
2
3 import java.io.Serializable;
4 import java.util.SortedMap;
5
6 import org.djunits.unit.AccelerationUnit;
7 import org.djunits.unit.DurationUnit;
8 import org.djunits.unit.LengthUnit;
9 import org.djunits.unit.SpeedUnit;
10 import org.djunits.value.vdouble.scalar.Acceleration;
11 import org.djunits.value.vdouble.scalar.Duration;
12 import org.djunits.value.vdouble.scalar.Length;
13 import org.djunits.value.vdouble.scalar.Speed;
14 import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
15 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
16 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
17 import org.opentrafficsim.road.network.speed.SpeedLimitTypes;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class IDMPlusOld extends AbstractGTUFollowingModelMobil implements Serializable
33 {
34
35 private static final long serialVersionUID = 20140704L;
36
37
38 private final Length s0;
39
40
41 private Acceleration a;
42
43
44 private final Acceleration b;
45
46
47 private Duration tSafe;
48
49
50
51
52
53 private double delta;
54
55
56
57
58
59 private static final Duration DEFAULT_STEP_SIZE = new Duration(0.5, DurationUnit.SECOND);
60
61
62
63
64
65
66
67 public IDMPlusOld()
68 {
69 this.a = new Acceleration(1.56, AccelerationUnit.METER_PER_SECOND_2);
70 this.b = new Acceleration(2.09, AccelerationUnit.METER_PER_SECOND_2);
71 this.s0 = new Length(3, LengthUnit.METER);
72 this.tSafe = new Duration(1.2, DurationUnit.SECOND);
73 this.delta = 1d;
74 }
75
76
77
78
79
80
81
82
83
84
85 public IDMPlusOld(final Acceleration a, final Acceleration b, final Length s0, final Duration tSafe, final double delta)
86 {
87 this.a = a;
88 this.b = b;
89 this.s0 = s0;
90 this.tSafe = tSafe;
91 this.delta = delta;
92 }
93
94
95
96
97
98
99
100 private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
101 {
102 return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
103 }
104
105
106 @Override
107 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
108 final Speed leaderSpeed, final Length headway, final Speed speedLimit)
109 {
110 return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, DEFAULT_STEP_SIZE);
111 }
112
113
114 @Override
115 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
116 final Speed leaderSpeed, final Length headway, final Speed speedLimit, final Duration stepSize)
117 {
118
119 double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
120 if (Double.isNaN(leftComponent))
121 {
122 leftComponent = 0;
123 }
124
125 if (leftComponent * this.a.si < -0.5)
126 {
127 leftComponent = -0.5 / this.a.si;
128 }
129 Acceleration logWeightedAccelerationTimes2 =
130 new Acceleration(Math.sqrt(this.a.getSI() * this.b.getSI()), AccelerationUnit.SI).multiplyBy(2);
131
132
133 Speed dV = followerSpeed.minus(leaderSpeed);
134 Length sStar = this.s0.plus(followerSpeed.multiplyBy(this.tSafe))
135 .plus(dV.multiplyBy(followerSpeed.divideBy(logWeightedAccelerationTimes2)));
136
137
138
139
140
141 if (sStar.getSI() < 0)
142 {
143
144
145 sStar = new Length(0, LengthUnit.SI);
146 }
147
148 double rightComponent = 1 - Math.pow(sStar.getSI() / headway.getSI(), 2);
149 Acceleration newAcceleration = new Acceleration(this.a).multiplyBy(Math.min(leftComponent, rightComponent));
150 if (newAcceleration.getSI() * stepSize.getSI() + followerSpeed.getSI() < 0)
151 {
152 newAcceleration = new Acceleration(-followerSpeed.getSI() / stepSize.getSI(), AccelerationUnit.SI);
153 }
154 return newAcceleration;
155 }
156
157
158 @Override
159 public final Duration getStepSize()
160 {
161 return DEFAULT_STEP_SIZE;
162 }
163
164
165 @Override
166 public final Acceleration getMaximumSafeDeceleration()
167 {
168 return this.b;
169 }
170
171
172 @Override
173 public final String getName()
174 {
175 return "IDM+";
176 }
177
178
179 @Override
180 public final String getLongName()
181 {
182 return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
183 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
184 }
185
186
187 @Override
188 public final void setA(final Acceleration a)
189 {
190 this.a = a;
191 }
192
193
194 @Override
195 public final void setT(final Duration t)
196 {
197 this.tSafe = t;
198 }
199
200
201 @Override
202 public final void setFspeed(final double fSpeed)
203 {
204 this.delta = fSpeed;
205 }
206
207
208
209
210 @Override
211 public final Speed desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
212 throws ParameterException
213 {
214 throw new UnsupportedOperationException("Old car-following model does not support desired speed.");
215 }
216
217
218 @Override
219 public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
220 throws ParameterException
221 {
222 throw new UnsupportedOperationException("Old car-following model does not support desired headway.");
223 }
224
225
226 @Override
227 public final Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics,
228 final Speed speed, final SpeedLimitInfo speedInfo, final SortedMap<Length, Speed> leaders) throws ParameterException
229 {
230 Length headway;
231 Speed leaderSpeed;
232 if (leaders.isEmpty())
233 {
234 headway = new Length(Double.MAX_VALUE, LengthUnit.SI);
235 leaderSpeed = speed;
236 }
237 else
238 {
239 headway = leaders.firstKey();
240 leaderSpeed = leaders.get(headway);
241 }
242 return this.computeAcceleration(speed, speedInfo.getSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED), leaderSpeed, headway,
243 speedInfo.getSpeedInfo(SpeedLimitTypes.FIXED_SIGN));
244 }
245
246
247 @Override
248 public final String toString()
249 {
250 return "IDMPlusOld [s0=" + this.s0 + ", a=" + this.a + ", b=" + this.b + ", tSafe=" + this.tSafe + ", delta="
251 + this.delta + ", stepSize=" + DEFAULT_STEP_SIZE + "]";
252 }
253
254 }