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 public class IDMOld extends AbstractGTUFollowingModelMobil implements Serializable
30 {
31
32 private static final long serialVersionUID = 20141119L;
33
34
35 private final Length s0;
36
37
38 private Acceleration a;
39
40
41 private final Acceleration b;
42
43
44 private Duration tSafe;
45
46
47
48
49
50 private static final Duration DEFAULT_STEP_SIZE = new Duration(0.5, DurationUnit.SECOND);
51
52
53
54
55
56 private double delta;
57
58
59
60
61 public IDMOld()
62 {
63 this.a = new Acceleration(1.56, AccelerationUnit.METER_PER_SECOND_2);
64 this.b = new Acceleration(2.09, AccelerationUnit.METER_PER_SECOND_2);
65 this.s0 = new Length(3, LengthUnit.METER);
66 this.tSafe = new Duration(1.2, DurationUnit.SECOND);
67 this.delta = 1.0;
68 }
69
70
71
72
73
74
75
76
77
78
79 public IDMOld(final Acceleration a, final Acceleration b, final Length s0, final Duration tSafe, final double delta)
80 {
81 this.a = a;
82 this.b = b;
83 this.s0 = s0;
84 this.tSafe = tSafe;
85 this.delta = delta;
86 }
87
88
89
90
91
92
93
94 private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
95 {
96 return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
97 }
98
99
100 @Override
101 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
102 final Speed leaderSpeed, final Length headway, final Speed speedLimit)
103 {
104 return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, DEFAULT_STEP_SIZE);
105 }
106
107
108 @Override
109 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
110 final Speed leaderSpeed, final Length headway, final Speed speedLimit, final Duration stepSize)
111 {
112
113
114 Speed dV = followerSpeed.minus(leaderSpeed);
115 double sStar = this.s0.si + followerSpeed.si * this.tSafe.si
116 + dV.si * followerSpeed.si / (2.0 * Math.sqrt(this.a.si * this.b.si));
117 if (sStar < 0.0 && headway.si < 0.0)
118 {
119 return new Acceleration(Double.NEGATIVE_INFINITY, AccelerationUnit.SI);
120 }
121 sStar = sStar >= 0.0 ? sStar : 0.0;
122 double s = headway.si > 0.0 ? headway.si : 1E-99;
123 Acceleration aInteraction = new Acceleration(this.a.si * (sStar / s) * (sStar / s), AccelerationUnit.SI);
124 Acceleration aFree =
125 new Acceleration(this.a.si * (1.0 - Math.pow(followerSpeed.si / vDes(speedLimit, followerMaximumSpeed).si, 4)),
126 AccelerationUnit.SI);
127
128 if (aFree.si < -0.5)
129 {
130 aFree = new Acceleration(-0.5, AccelerationUnit.SI);
131 }
132 Acceleration newAcceleration = aFree.minus(aInteraction);
133 if (newAcceleration.si * stepSize.si + followerSpeed.si < 0)
134 {
135 newAcceleration = new Acceleration(-followerSpeed.si / stepSize.si, AccelerationUnit.SI);
136 }
137 return newAcceleration;
138 }
139
140
141 @Override
142 public final Duration getStepSize()
143 {
144 return DEFAULT_STEP_SIZE;
145 }
146
147
148 @Override
149 public final Acceleration getMaximumSafeDeceleration()
150 {
151 return this.b;
152 }
153
154
155 @Override
156 public final String getName()
157 {
158 return "IDM";
159 }
160
161
162 @Override
163 public final String getLongName()
164 {
165 return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
166 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
167 }
168
169
170 @Override
171 public final void setA(final Acceleration a)
172 {
173 this.a = a;
174 }
175
176
177 @Override
178 public final void setT(final Duration t)
179 {
180 this.tSafe = t;
181 }
182
183
184 @Override
185 public final void setFspeed(final double fSpeed)
186 {
187 this.delta = fSpeed;
188 }
189
190
191
192
193 @Override
194 public final Speed desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
195 throws ParameterException
196 {
197 throw new UnsupportedOperationException("Old car-following model does not support desired speed.");
198 }
199
200
201 @Override
202 public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
203 throws ParameterException
204 {
205 throw new UnsupportedOperationException("Old car-following model does not support desired headway.");
206 }
207
208
209 @Override
210 public final Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics,
211 final Speed speed, final SpeedLimitInfo speedInfo, final SortedMap<Length, Speed> leaders) throws ParameterException
212 {
213 Length headway;
214 Speed leaderSpeed;
215 if (leaders.isEmpty())
216 {
217 headway = new Length(Double.MAX_VALUE, LengthUnit.SI);
218 leaderSpeed = speed;
219 }
220 else
221 {
222 headway = leaders.firstKey();
223 leaderSpeed = leaders.get(headway);
224 }
225 return this.computeAcceleration(speed, speedInfo.getSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED), leaderSpeed, headway,
226 speedInfo.getSpeedInfo(SpeedLimitTypes.FIXED_SIGN));
227 }
228
229
230 @Override
231 public final String toString()
232 {
233 return "IDMOld [s0=" + this.s0 + ", a=" + this.a + ", b=" + this.b + ", tSafe=" + this.tSafe + ", stepSize="
234 + DEFAULT_STEP_SIZE + ", delta=" + this.delta + "]";
235 }
236
237 }