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   * The Intelligent Driver Model by Treiber, Hennecke and Helbing.
14   * <p>
15   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision: 1408 $, $LastChangedDate: 2015-09-24 15:17:25 +0200 (Thu, 24 Sep 2015) $, by $Author: pknoppers $,
19   *          initial version 19 nov. 2014 <br>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   */
22  public class IDMOld extends AbstractGTUFollowingModelMobil
23  {
24      /** Preferred net longitudinal distance when stopped [m]. */
25      private final Length.Rel s0;
26  
27      /** Maximum longitudinal acceleration [m/s^2]. */
28      private final Acceleration a;
29  
30      /** Longitudinal deceleration [m/s^2]. (Should be a positive value even though it is a <b>de</b>celeration.) */
31      private final Acceleration b;
32  
33      /** Safe time headway. */
34      private final Time.Rel tSafe;
35  
36      /**
37       * Time slot size used by IDM (not defined in the paper, but 0.5s is a reasonable trade-off between computational speed and
38       * accuracy).
39       */
40      private final Time.Rel stepSize = new Time.Rel(0.5, TimeUnit.SECOND);
41  
42      /**
43       * Mean speed limit adherence (1.0: mean free speed equals the speed limit; 1.1: mean speed limit equals 110% of the speed
44       * limit, etc.).
45       */
46      private final double delta;
47  
48      /**
49       * Construct a new IDM car following model with reasonable values (reasonable for passenger cars).
50       */
51      public IDMOld()
52      {
53          this.a = new Acceleration(1.56, AccelerationUnit.METER_PER_SECOND_2);
54          this.b = new Acceleration(2.09, AccelerationUnit.METER_PER_SECOND_2);
55          this.s0 = new Length.Rel(3, LengthUnit.METER);
56          this.tSafe = new Time.Rel(1.2, TimeUnit.SECOND);
57          this.delta = 1d;
58      }
59  
60      /**
61       * Construct a new IDM car following model.
62       * @param a Acceleration; the maximum acceleration of a stationary vehicle (normal value is 1 m/s/s)
63       * @param b Acceleration; the maximum deemed-safe deceleration (this is a positive value). Normal value is 1.5 m/s/s.
64       * @param s0 Length.Rel; the minimum stationary headway (normal value is 2 m)
65       * @param tSafe Time.Rel; the minimum time-headway (normal value is 1s)
66       * @param delta double; the speed limit adherence (1.0; mean free speed equals the speed limit; 1.1: mean free speed equals
67       *            110% of the speed limit; etc.)
68       */
69      public IDMOld(final Acceleration a, final Acceleration b, final Length.Rel s0, final Time.Rel tSafe, final double delta)
70      {
71          this.a = a;
72          this.b = b;
73          this.s0 = s0;
74          this.tSafe = tSafe;
75          this.delta = delta;
76      }
77  
78      /**
79       * Desired speed (taking into account the urge to drive a little faster or slower than the posted speed limit).
80       * @param speedLimit DoubleScalarAbs&lt;SpeedUnit&gt;; the speed limit
81       * @param followerMaximumSpeed Speed; the maximum speed that the follower can drive
82       * @return DoubleScalarRel&lt;SpeedUnit&gt;; the desired speed
83       */
84      private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
85      {
86          return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
87      }
88  
89      /** {@inheritDoc} */
90      public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
91          final Speed leaderSpeed, final Length.Rel headway, final Speed speedLimit)
92      {
93          return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, this.stepSize);
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, final Time.Rel stepSize)
99      {
100         // TODO maxDistance
101         // dV is the approach speed
102         Speed dV = followerSpeed.minus(leaderSpeed);
103         double sStar =
104             this.s0.si + followerSpeed.si * this.tSafe.si + dV.si * followerSpeed.si
105                 / (2.0 * Math.sqrt(this.a.si * this.b.si));
106         if (sStar < 0.0 && headway.si < 0.0)
107         {
108             return new Acceleration(Double.NEGATIVE_INFINITY, AccelerationUnit.SI);
109         }
110         sStar = sStar >= 0.0 ? sStar : 0.0;
111         double s = headway.si > 0.0 ? headway.si : 1E-99;
112         Acceleration aInteraction = new Acceleration(this.a.si * (sStar / s) * (sStar / s), AccelerationUnit.SI);
113         Acceleration aFree =
114             new Acceleration(this.a.si
115                 * (1.0 - Math.pow(followerSpeed.si / vDes(speedLimit, followerMaximumSpeed).si, 4)),
116                 AccelerationUnit.SI);
117         // limit deceleration for free term  (= aFree)
118         if (aFree.si < -0.5)
119         {
120             aFree = new Acceleration(-0.5, AccelerationUnit.SI);
121         }
122         Acceleration newAcceleration = aFree.minus(aInteraction);
123         if (newAcceleration.si * stepSize.si + followerSpeed.si < 0)
124         {
125             newAcceleration = new Acceleration(-followerSpeed.si / stepSize.si, AccelerationUnit.SI);
126         }
127         return newAcceleration;
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     public final Time.Rel getStepSize()
133     {
134         return this.stepSize;
135     }
136 
137     /** {@inheritDoc} */
138     @Override
139     public final Acceleration getMaximumSafeDeceleration()
140     {
141         return this.b;
142     }
143 
144     /** {@inheritDoc} */
145     @Override
146     public final String getName()
147     {
148         return "IDM";
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public final String getLongName()
154     {
155         return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
156             this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
157     }
158 
159 }