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