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
23
24
25 public class IDMPlusOld extends AbstractGTUFollowingModelMobil
26 {
27
28 private final Length.Rel s0;
29
30
31 private final Acceleration a;
32
33
34 private final Acceleration b;
35
36
37 private final Time.Rel tSafe;
38
39
40
41
42
43 private final double delta;
44
45
46
47
48
49 private final Time.Rel stepSize = new Time.Rel(0.5, TimeUnit.SECOND);
50
51
52
53
54
55
56
57 public IDMPlusOld()
58 {
59 this.a = new Acceleration(1.56, AccelerationUnit.METER_PER_SECOND_2);
60 this.b = new Acceleration(2.09, AccelerationUnit.METER_PER_SECOND_2);
61 this.s0 = new Length.Rel(3, LengthUnit.METER);
62 this.tSafe = new Time.Rel(1.2, TimeUnit.SECOND);
63 this.delta = 1d;
64 }
65
66
67
68
69
70
71
72
73
74
75 public IDMPlusOld(final Acceleration a, final Acceleration b, final Length.Rel s0, final Time.Rel tSafe,
76 final double delta)
77 {
78 this.a = a;
79 this.b = b;
80 this.s0 = s0;
81 this.tSafe = tSafe;
82 this.delta = delta;
83 }
84
85
86
87
88
89
90
91 private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
92 {
93 return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
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)
99 {
100 return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, this.stepSize);
101 }
102
103
104 public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
105 final Speed leaderSpeed, final Length.Rel headway, final Speed speedLimit, final Time.Rel stepSize)
106 {
107
108 double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
109 if (Double.isNaN(leftComponent))
110 {
111 leftComponent = 0;
112 }
113
114 if (leftComponent * this.a.si < -0.5)
115 {
116 leftComponent = -0.5 / this.a.si;
117 }
118 Acceleration logWeightedAccelerationTimes2 =
119 new Acceleration(Math.sqrt(this.a.getSI() * this.b.getSI()), AccelerationUnit.SI).multiplyBy(2);
120
121
122 Speed dV = followerSpeed.minus(leaderSpeed);
123 Length.Rel sStar =
124 this.s0.plus(followerSpeed.multiplyBy(this.tSafe)).plus(
125 dV.multiplyBy(followerSpeed.divideBy(logWeightedAccelerationTimes2)));
126
127
128
129
130
131 if (sStar.getSI() < 0)
132 {
133
134
135 sStar = new Length.Rel(0, LengthUnit.SI);
136 }
137
138 double rightComponent = 1 - Math.pow(sStar.getSI() / headway.getSI(), 2);
139 Acceleration newAcceleration = new Acceleration(this.a).multiplyBy(Math.min(leftComponent, rightComponent));
140 if (newAcceleration.getSI() * stepSize.getSI() + followerSpeed.getSI() < 0)
141 {
142 newAcceleration = new Acceleration(-followerSpeed.getSI() / stepSize.getSI(), AccelerationUnit.SI);
143 }
144 return newAcceleration;
145 }
146
147
148 @Override
149 public final Time.Rel getStepSize()
150 {
151 return this.stepSize;
152 }
153
154
155 @Override
156 public final Acceleration getMaximumSafeDeceleration()
157 {
158 return this.b;
159 }
160
161
162 @Override
163 public final String getName()
164 {
165 return "IDM+";
166 }
167
168
169 @Override
170 public final String getLongName()
171 {
172 return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
173 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
174 }
175
176 }