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