1 package org.opentrafficsim.road.gtu.lane.tactical.following;
2
3 import org.djunits.unit.AccelerationUnit;
4 import org.djunits.unit.LengthUnit;
5 import org.djunits.unit.SpeedUnit;
6 import org.djunits.unit.TimeUnit;
7 import org.djunits.value.vdouble.scalar.Acceleration;
8 import org.djunits.value.vdouble.scalar.Length;
9 import org.djunits.value.vdouble.scalar.Speed;
10 import org.djunits.value.vdouble.scalar.Time;
11
12
13
14
15
16
17
18
19
20
21
22 public class IDMOld extends AbstractGTUFollowingModelMobil
23 {
24
25 private final Length.Rel s0;
26
27
28 private final Acceleration a;
29
30
31 private final Acceleration b;
32
33
34 private final Time.Rel tSafe;
35
36
37
38
39
40 private final Time.Rel stepSize = new Time.Rel(0.5, TimeUnit.SECOND);
41
42
43
44
45
46 private final double delta;
47
48
49
50
51 public IDMOld()
52 {
53 this.a = new Acceleration(1.56, AccelerationUnit.METER_PER_SECOND_2);
54 this.b = new Acceleration(2.09, AccelerationUnit.METER_PER_SECOND_2);
55 this.s0 = new Length.Rel(3, LengthUnit.METER);
56 this.tSafe = new Time.Rel(1.2, TimeUnit.SECOND);
57 this.delta = 1d;
58 }
59
60
61
62
63
64
65
66
67
68
69 public IDMOld(final Acceleration a, final Acceleration b, final Length.Rel s0, final Time.Rel tSafe, final double delta)
70 {
71 this.a = a;
72 this.b = b;
73 this.s0 = s0;
74 this.tSafe = tSafe;
75 this.delta = delta;
76 }
77
78
79
80
81
82
83
84 private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
85 {
86 return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
87 }
88
89
90 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
91 final Speed leaderSpeed, final Length.Rel headway, final Speed speedLimit)
92 {
93 return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, this.stepSize);
94 }
95
96
97 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
98 final Speed leaderSpeed, final Length.Rel headway, final Speed speedLimit, final Time.Rel stepSize)
99 {
100
101
102 Speed dV = followerSpeed.minus(leaderSpeed);
103 double sStar =
104 this.s0.si + followerSpeed.si * this.tSafe.si + dV.si * followerSpeed.si
105 / (2.0 * Math.sqrt(this.a.si * this.b.si));
106 if (sStar < 0.0 && headway.si < 0.0)
107 {
108 return new Acceleration(Double.NEGATIVE_INFINITY, AccelerationUnit.SI);
109 }
110 sStar = sStar >= 0.0 ? sStar : 0.0;
111 double s = headway.si > 0.0 ? headway.si : 1E-99;
112 Acceleration aInteraction = new Acceleration(this.a.si * (sStar / s) * (sStar / s), AccelerationUnit.SI);
113 Acceleration aFree =
114 new Acceleration(this.a.si
115 * (1.0 - Math.pow(followerSpeed.si / vDes(speedLimit, followerMaximumSpeed).si, 4)),
116 AccelerationUnit.SI);
117
118 if (aFree.si < -0.5)
119 {
120 aFree = new Acceleration(-0.5, AccelerationUnit.SI);
121 }
122 Acceleration newAcceleration = aFree.minus(aInteraction);
123 if (newAcceleration.si * stepSize.si + followerSpeed.si < 0)
124 {
125 newAcceleration = new Acceleration(-followerSpeed.si / stepSize.si, AccelerationUnit.SI);
126 }
127 return newAcceleration;
128 }
129
130
131 @Override
132 public final Time.Rel getStepSize()
133 {
134 return this.stepSize;
135 }
136
137
138 @Override
139 public final Acceleration getMaximumSafeDeceleration()
140 {
141 return this.b;
142 }
143
144
145 @Override
146 public final String getName()
147 {
148 return "IDM";
149 }
150
151
152 @Override
153 public final String getLongName()
154 {
155 return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
156 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
157 }
158
159 }