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