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.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   * IDMPlus implements the <i>Integrated Lane Change Model with Relaxation and Synchronization</i> as published by Wouter J.
20   * Schakel, Bart van Arem, Member, IEEE, and Bart D. Netten. 2012. <br>
21   * There are two nasty type setting errors in equation 7 in this published version of the paper. Both times an equals sign
22   * (<cite>=</cite>) after <cite>a<sub>gain</sub></cite> should <b>not</b> be there.
23   * <p>
24   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * <p>
27   * @version $Revision: 1408 $, $LastChangedDate: 2015-09-24 15:17:25 +0200 (Thu, 24 Sep 2015) $, by $Author: pknoppers $,
28   *          initial version Jul 4, 2014 <br>
29   * @author <a href="http://www.tudelft.nl/pknoppers">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 final 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 final 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 final double delta;
53  
54      /**
55       * Time slot size used by IDMPlus by (not defined in the paper, but 0.5s is a reasonable trade-off between computational
56       * speed and accuracy).
57       */
58      private final Duration stepSize = new Duration(0.5, TimeUnit.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, TimeUnit.SECOND);
72          this.delta = 1d;
73      }
74  
75      /**
76       * Construct a new IDMPlus car following model.
77       * @param a Acceleration; the maximum acceleration of a stationary vehicle (normal value is 1 m/s/s)
78       * @param b Acceleration; the maximum deemed-safe deceleration (this is a positive value)
79       * @param s0 Length; the minimum stationary headway
80       * @param tSafe Duration; the minimum time-headway
81       * @param delta double; the speed limit adherence (1.0; mean free speed equals the speed limit; 1.1: mean free speed equals
82       *            110% of the speed limit; etc.)
83       */
84      public IDMPlusOld(final Acceleration a, final Acceleration b, final Length s0, final Duration tSafe,
85          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     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, this.stepSize);
110     }
111 
112     /** {@inheritDoc} */
113     public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
114         final Speed leaderSpeed, final Length headway, final Speed speedLimit, final Duration stepSize)
115     {
116         // TODO maxDistance
117         double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
118         if (Double.isNaN(leftComponent))
119         {
120             leftComponent = 0;
121         }
122         // limit deceleration for free term (= leftComponent)
123         if (leftComponent * this.a.si < -0.5)
124         {
125             leftComponent = -0.5 / this.a.si;
126         }
127         Acceleration logWeightedAccelerationTimes2 =
128             new Acceleration(Math.sqrt(this.a.getSI() * this.b.getSI()), AccelerationUnit.SI).multiplyBy(2);
129         // don't forget the times 2
130 
131         Speed dV = followerSpeed.minus(leaderSpeed);
132         Length sStar =
133             this.s0.plus(followerSpeed.multiplyBy(this.tSafe)).plus(
134                 dV.multiplyBy(followerSpeed.divideBy(logWeightedAccelerationTimes2)));
135 
136         /*-
137         this.s0.plus(Calc.speedTimesTime(followerSpeed, this.tSafe)).plus(
138         Calc.speedTimesTime(dV, Calc.speedDividedByAcceleration(followerSpeed, logWeightedAccelerationTimes2)));
139          */
140         if (sStar.getSI() < 0)
141         {
142             // Negative value should be treated as 0? This is NOT in the LMRS paper
143             // Without this "fix" a higher speed of the leader may cause a lower acceleration (which is crazy)
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     /** {@inheritDoc} */
157     @Override
158     public final Duration getStepSize()
159     {
160         return this.stepSize;
161     }
162 
163     /** {@inheritDoc} */
164     @Override
165     public final Acceleration getMaximumSafeDeceleration()
166     {
167         return this.b;
168     }
169 
170     /** {@inheritDoc} */
171     @Override
172     public final String getName()
173     {
174         return "IDM+";
175     }
176 
177     /** {@inheritDoc} */
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(), this.a
182             .getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
183     }
184 
185     // The following is inherited from CarFollowingModel
186 
187     /** {@inheritDoc} */
188     @Override
189     public final Speed desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
190         throws ParameterException
191     {
192         return null;
193     }
194 
195     /** {@inheritDoc} */
196     @Override
197     public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
198         throws ParameterException
199     {
200         return null;
201     }
202 
203     /** {@inheritDoc} */
204     @Override
205     public final Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics,
206         final Speed speed, final SpeedLimitInfo speedInfo, final SortedMap<Length, Speed> leaders) throws ParameterException
207     {
208         return null;
209     }
210 
211     /** {@inheritDoc} */
212     @Override
213     public final String toString()
214     {
215         return "IDMPlusOld [s0=" + this.s0 + ", a=" + this.a + ", b=" + this.b + ", tSafe=" + this.tSafe + ", delta="
216             + this.delta + ", stepSize=" + this.stepSize + "]";
217     }
218 
219 }