View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.following;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.AccelerationUnit;
6   import org.djunits.unit.DurationUnit;
7   import org.djunits.unit.LengthUnit;
8   import org.djunits.unit.SpeedUnit;
9   import org.djunits.value.vdouble.scalar.Acceleration;
10  import org.djunits.value.vdouble.scalar.Duration;
11  import org.djunits.value.vdouble.scalar.Length;
12  import org.djunits.value.vdouble.scalar.Speed;
13  import org.opentrafficsim.base.parameters.ParameterException;
14  import org.opentrafficsim.base.parameters.Parameters;
15  import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
16  import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
17  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
18  import org.opentrafficsim.road.network.speed.SpeedLimitTypes;
19  
20  /**
21   * IDMPlus implements the <i>Integrated Lane Change Model with Relaxation and Synchronization</i> as published by Wouter J.
22   * Schakel, Bart van Arem, Member, IEEE, and Bart D. Netten. 2012. <br>
23   * There are two nasty type setting errors in equation 7 in this published version of the paper. Both times an equals sign
24   * (<cite>=</cite>) after <cite>a<sub>gain</sub></cite> should <b>not</b> be there.
25   * <p>
26   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
28   * </p>
29   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
30   */
31  public class IdmPlusOld extends AbstractGtuFollowingModelMobil implements Serializable
32  {
33      /** */
34      private static final long serialVersionUID = 20140704L;
35  
36      /** Preferred net longitudinal distance when stopped [m]. */
37      private final Length s0;
38  
39      /** Longitudinal acceleration [m/s^2]. */
40      private Acceleration a;
41  
42      /** Longitudinal deceleration [m/s^2]. (Should be a positive value even though it is a <b>de</b>celeration.) */
43      private final Acceleration b;
44  
45      /** Safe time headway. */
46      private Duration tSafe;
47  
48      /**
49       * Mean speed limit adherence (1.0: mean free speed equals the speed limit; 1.1: mean free speed equals 110% of the speed
50       * limit, etc.).
51       */
52      private double delta;
53  
54      /**
55       * Default step size used by IDMPlus (not defined in the paper, but 0.5s is a reasonable trade-off between computational
56       * speed and accuracy).
57       */
58      private static final Duration DEFAULT_STEP_SIZE = new Duration(0.5, DurationUnit.SECOND);
59  
60      /**
61       * Construct a new IDM+ car following model with reasonable values (reasonable for passenger cars). <br>
62       * These values are from <b>Integrated Lane Change Model with Relaxation and Synchronization</b> by Wouter J. Schakel,
63       * Victor L. Knoop, and Bart van Arem, published in Transportation Research Record: Journal of the Transportation Research
64       * Board, No. 2316, Transportation Research Board of the National Academies, Washington, D.C., 2012, pp. 47–57.
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, DurationUnit.SECOND);
72          this.delta = 1d;
73      }
74  
75      /**
76       * Construct a new IDMPlus car following model.
77       * @param a the maximum acceleration of a stationary vehicle (normal value is 1 m/s/s)
78       * @param b the maximum deemed-safe deceleration (this is a positive value)
79       * @param s0 the minimum stationary headway
80       * @param tSafe the minimum time-headway
81       * @param delta the speed limit adherence (1.0; mean free speed equals the speed limit; 1.1: mean free speed equals 110% of
82       *            the speed limit; etc.)
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       * Desired speed (taking into account the urge to drive a little faster or slower than the posted speed limit).
95       * @param speedLimit the speed limit
96       * @param followerMaximumSpeed the maximum speed that the follower can drive
97       * @return the desired speed
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     @Override
105     public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
106             final Speed leaderSpeed, final Length headway, final Speed speedLimit)
107     {
108         return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, DEFAULT_STEP_SIZE);
109     }
110 
111     @Override
112     public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
113             final Speed leaderSpeed, final Length headway, final Speed speedLimit, final Duration stepSize)
114     {
115         // TODO maxDistance
116         double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
117         if (Double.isNaN(leftComponent))
118         {
119             leftComponent = 0;
120         }
121         // limit deceleration for free term (= leftComponent)
122         if (leftComponent * this.a.si < -0.5)
123         {
124             leftComponent = -0.5 / this.a.si;
125         }
126         Acceleration logWeightedAccelerationTimes2 =
127                 new Acceleration(Math.sqrt(this.a.getSI() * this.b.getSI()), AccelerationUnit.SI).times(2);
128         // don't forget the times 2
129 
130         Speed dV = followerSpeed.minus(leaderSpeed);
131         Length sStar = this.s0.plus(followerSpeed.times(this.tSafe))
132                 .plus(dV.times(followerSpeed.divide(logWeightedAccelerationTimes2)));
133 
134         /*-
135         this.s0.plus(Calc.speedTimesTime(followerSpeed, this.tSafe)).plus(
136         Calc.speedTimesTime(dV, Calc.speedDividedByAcceleration(followerSpeed, logWeightedAccelerationTimes2)));
137          */
138         if (sStar.getSI() < 0)
139         {
140             // Negative value should be treated as 0? This is NOT in the LMRS paper
141             // Without this "fix" a higher speed of the leader may cause a lower acceleration (which is crazy)
142             sStar = new Length(0, LengthUnit.SI);
143         }
144 
145         double rightComponent = 1 - Math.pow(sStar.getSI() / headway.getSI(), 2);
146         Acceleration newAcceleration = new Acceleration(this.a).times(Math.min(leftComponent, rightComponent));
147         if (newAcceleration.getSI() * stepSize.getSI() + followerSpeed.getSI() < 0)
148         {
149             newAcceleration = new Acceleration(-followerSpeed.getSI() / stepSize.getSI(), AccelerationUnit.SI);
150         }
151         return newAcceleration;
152     }
153 
154     @Override
155     public final Duration getStepSize()
156     {
157         return DEFAULT_STEP_SIZE;
158     }
159 
160     @Override
161     public final Acceleration getMaximumSafeDeceleration()
162     {
163         return this.b;
164     }
165 
166     @Override
167     public final String getName()
168     {
169         return "IDM+";
170     }
171 
172     @Override
173     public final String getLongName()
174     {
175         return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
176                 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
177     }
178 
179     @Override
180     public final void setA(final Acceleration a)
181     {
182         this.a = a;
183     }
184 
185     @Override
186     public final void setT(final Duration t)
187     {
188         this.tSafe = t;
189     }
190 
191     @Override
192     public final void setFspeed(final double fSpeed)
193     {
194         this.delta = fSpeed;
195     }
196 
197     // The following is inherited from CarFollowingModel
198 
199     @Override
200     public final Speed desiredSpeed(final Parameters parameters, final SpeedLimitInfo speedInfo) throws ParameterException
201     {
202         throw new UnsupportedOperationException("Old car-following model does not support desired speed.");
203     }
204 
205     @Override
206     public final Length desiredHeadway(final Parameters parameters, final Speed speed) throws ParameterException
207     {
208         throw new UnsupportedOperationException("Old car-following model does not support desired headway.");
209     }
210 
211     @Override
212     public final Acceleration followingAcceleration(final Parameters parameters, final Speed speed,
213             final SpeedLimitInfo speedInfo, final PerceptionIterable<? extends Headway> leaders) throws ParameterException
214     {
215         Length headway;
216         Speed leaderSpeed;
217         if (leaders.isEmpty())
218         {
219             headway = new Length(Double.MAX_VALUE, LengthUnit.SI);
220             leaderSpeed = speed;
221         }
222         else
223         {
224             Headway leader = leaders.first();
225             headway = leader.getDistance();
226             leaderSpeed = leader.getSpeed();
227         }
228         return this.computeAcceleration(speed, speedInfo.getSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED), leaderSpeed, headway,
229                 speedInfo.getSpeedInfo(SpeedLimitTypes.FIXED_SIGN));
230     }
231 
232     @Override
233     public final String toString()
234     {
235         return "IDMPlusOld [s0=" + this.s0 + ", a=" + this.a + ", b=" + this.b + ", tSafe=" + this.tSafe + ", delta="
236                 + this.delta + ", stepSize=" + DEFAULT_STEP_SIZE + "]";
237     }
238 
239 }