View Javadoc
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   * IDMPlus implements the <i>Integrated Lane Change Model with Relaxation and Synchronization</i> as published by Wouter J.
14   * Schakel, Bart van Arem, Member, IEEE, and Bart D. Netten. 2012. <br>
15   * There are two nasty type setting errors in equation 7 in this published version of the paper. Both times an equals sign
16   * (<cite>=</cite>) after <cite>a<sub>gain</sub></cite> should <b>not</b> be there.
17   * <p>
18   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * <p>
21   * @version $Revision: 1408 $, $LastChangedDate: 2015-09-24 15:17:25 +0200 (Thu, 24 Sep 2015) $, by $Author: pknoppers $,
22   *          initial version Jul 4, 2014 <br>
23   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
24   */
25  public class IDMPlusOld extends AbstractGTUFollowingModelMobil
26  {
27      /** Preferred net longitudinal distance when stopped [m]. */
28      private final Length.Rel s0;
29  
30      /** Longitudinal acceleration [m/s^2]. */
31      private final Acceleration a;
32  
33      /** Longitudinal deceleration [m/s^2]. (Should be a positive value even though it is a <b>de</b>celeration.) */
34      private final Acceleration b;
35  
36      /** Safe time headway. */
37      private final Time.Rel tSafe;
38  
39      /**
40       * Mean speed limit adherence (1.0: mean free speed equals the speed limit; 1.1: mean free speed equals 110% of the speed
41       * limit, etc.).
42       */
43      private final double delta;
44  
45      /**
46       * Time slot size used by IDMPlus by (not defined in the paper, but 0.5s is a reasonable trade-off between computational
47       * speed and accuracy).
48       */
49      private final Time.Rel stepSize = new Time.Rel(0.5, TimeUnit.SECOND);
50  
51      /**
52       * Construct a new IDM+ car following model with reasonable values (reasonable for passenger cars). <br>
53       * These values are from <b>Integrated Lane Change Model with Relaxation and Synchronization</b> by Wouter J. Schakel,
54       * Victor L. Knoop, and Bart van Arem, published in Transportation Research Record: Journal of the Transportation Research
55       * Board, No. 2316, Transportation Research Board of the National Academies, Washington, D.C., 2012, pp. 47–57.
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       * Construct a new IDMPlus car following model.
68       * @param a Acceleration; the maximum acceleration of a stationary vehicle (normal value is 1 m/s/s)
69       * @param b Acceleration; the maximum deemed-safe deceleration (this is a positive value)
70       * @param s0 Length.Rel; the minimum stationary headway
71       * @param tSafe Time.Rel; the minimum time-headway
72       * @param delta double; the speed limit adherence (1.0; mean free speed equals the speed limit; 1.1: mean free speed equals
73       *            110% of the speed limit; etc.)
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       * Desired speed (taking into account the urge to drive a little faster or slower than the posted speed limit).
87       * @param speedLimit DoubleScalarAbs&lt;SpeedUnit&gt;; the speed limit
88       * @param followerMaximumSpeed Speed; the maximum speed that the follower can drive
89       * @return DoubleScalarRel&lt;SpeedUnit&gt;; the desired speed
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      /** {@inheritDoc} */
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     /** {@inheritDoc} */
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         // TODO maxDistance
108         double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
109         if (Double.isNaN(leftComponent))
110         {
111             leftComponent = 0;
112         }
113         // limit deceleration for free term  (= leftComponent)
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         // don't forget the times 2
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         this.s0.plus(Calc.speedTimesTime(followerSpeed, this.tSafe)).plus(
129         Calc.speedTimesTime(dV, Calc.speedDividedByAcceleration(followerSpeed, logWeightedAccelerationTimes2)));
130          */
131         if (sStar.getSI() < 0)
132         {
133             // Negative value should be treated as 0? This is NOT in the LMRS paper
134             // Without this "fix" a higher speed of the leader may cause a lower acceleration (which is crazy)
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     /** {@inheritDoc} */
148     @Override
149     public final Time.Rel getStepSize()
150     {
151         return this.stepSize;
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public final Acceleration getMaximumSafeDeceleration()
157     {
158         return this.b;
159     }
160 
161     /** {@inheritDoc} */
162     @Override
163     public final String getName()
164     {
165         return "IDM+";
166     }
167 
168     /** {@inheritDoc} */
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 }