View Javadoc
1   package org.opentrafficsim.core.gtu.following;
2   
3   import org.opentrafficsim.core.unit.AccelerationUnit;
4   import org.opentrafficsim.core.unit.LengthUnit;
5   import org.opentrafficsim.core.unit.SpeedUnit;
6   import org.opentrafficsim.core.unit.TimeUnit;
7   import org.opentrafficsim.core.value.conversions.Calc;
8   import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
9   import org.opentrafficsim.core.value.vdouble.scalar.MutableDoubleScalar;
10  
11  /**
12   * IDMPlus implements the <i>Integrated Lane Change Model with Relaxation and Synchronization</i> as published by Wouter
13   * J. Schakel, Bart van Arem, Member, IEEE, and Bart D. Netten. 2012. <br>
14   * There are two nasty type setting errors in equation 7 in this published version of the paper. Both times an equals
15   * sign (<cite>=</cite>) after <cite>a<sub>gain</sub></cite> should <b>not</b> be there.
16   * <p>
17   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
18   * reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
20   * <p>
21   * @version Jul 4, 2014 <br>
22   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
23   */
24  public class IDMPlus extends AbstractGTUFollowingModel
25  {
26      /** Preferred net longitudinal distance when stopped [m]. */
27      private final DoubleScalar.Rel<LengthUnit> s0;
28  
29      /** Longitudinal acceleration [m/s^2]. */
30      private final DoubleScalar.Abs<AccelerationUnit> a;
31  
32      /** Longitudinal deceleration [m/s^2]. (Should be a positive value even though it is a <b>de</b>celeration.) */
33      private final DoubleScalar.Abs<AccelerationUnit> b;
34  
35      /** Safe time headway. */
36      private final DoubleScalar.Rel<TimeUnit> tSafe;
37  
38      /**
39       * Mean speed limit adherence (1.0: mean free speed equals the speed limit; 1.1: mean free speed equals 110% of the
40       * speed limit, etc.).
41       */
42      private final double delta;
43  
44      /**
45       * Time slot size used by IDMPlus by (not defined in the paper, but 0.5s is a reasonable trade-off between
46       * computational speed and accuracy).
47       */
48      private final DoubleScalar.Rel<TimeUnit> stepSize = new DoubleScalar.Rel<TimeUnit>(0.5, TimeUnit.SECOND);
49  
50      /**
51       * Construct a new IDM+ car following model with reasonable values (reasonable for passenger cars). <br>
52       * These values are from <b>Integrated Lane Change Model with Relaxation and Synchronization</b> by Wouter J.
53       * Schakel, Victor L. Knoop, and Bart van Arem, published in Transportation Research Record: Journal of the
54       * Transportation Research Board, No. 2316, Transportation Research Board of the National Academies, Washington,
55       * D.C., 2012, pp. 47–57.
56       */
57      public IDMPlus()
58      {
59          this.a = new DoubleScalar.Abs<AccelerationUnit>(1.56, AccelerationUnit.METER_PER_SECOND_2);
60          this.b = new DoubleScalar.Abs<AccelerationUnit>(2.09, AccelerationUnit.METER_PER_SECOND_2);
61          this.s0 = new DoubleScalar.Rel<LengthUnit>(3, LengthUnit.METER);
62          this.tSafe = new DoubleScalar.Rel<TimeUnit>(1.2, TimeUnit.SECOND);
63          this.delta = 1d;
64      }
65  
66      /**
67       * Construct a new IDMPlus car following model.
68       * @param a DoubleScalar.Abs&lt;AccelerationUnit&gt;; the maximum acceleration of a stationary vehicle (normal value
69       *            is 1 m/s/s)
70       * @param b DoubleScalar.Abs&lt;AccelerationUnit&gt;; the maximum deemed-safe deceleration (this is a positive
71       *            value)
72       * @param s0 DoubleScalar.Rel&lt;LengthUnit&gt;; the minimum stationary headway
73       * @param tSafe DoubleScalar.Rel&lt;TimeUnit&gt;; the minimum time-headway
74       * @param delta double; the speed limit adherence (1.0; mean free speed equals the speed limit; 1.1: mean free speed
75       *            equals 110% of the speed limit; etc.)
76       */
77      public IDMPlus(final DoubleScalar.Abs<AccelerationUnit> a, final DoubleScalar.Abs<AccelerationUnit> b,
78              final DoubleScalar.Rel<LengthUnit> s0, final DoubleScalar.Rel<TimeUnit> 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 DoubleScalar.Abs&lt;SpeedUnit&gt;; the maximum speed that the follower can drive
91       * @return DoubleScalarRel&lt;SpeedUnit&gt;; the desired speed
92       */
93      private DoubleScalar.Rel<SpeedUnit> vDes(final DoubleScalar.Abs<SpeedUnit> speedLimit,
94              final DoubleScalar.Abs<SpeedUnit> followerMaximumSpeed)
95      {
96          return new DoubleScalar.Rel<SpeedUnit>(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()),
97                  SpeedUnit.METER_PER_SECOND);
98      }
99  
100     /** {@inheritDoc} */
101     public final DoubleScalar.Abs<AccelerationUnit> computeAcceleration(
102             final DoubleScalar.Abs<SpeedUnit> followerSpeed, final DoubleScalar.Abs<SpeedUnit> followerMaximumSpeed,
103             final DoubleScalar.Abs<SpeedUnit> leaderSpeed, final DoubleScalar.Rel<LengthUnit> headway,
104             final DoubleScalar.Abs<SpeedUnit> speedLimit)
105     {
106         double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
107         if (Double.isNaN(leftComponent))
108         {
109             leftComponent = 0;
110         }
111         // if (leftComponent < 0)
112         // {
113         // System.out.println("leftComponent is " + leftComponent);
114         // }
115         MutableDoubleScalar.Rel<AccelerationUnit> logWeightedAccelerationTimes2 =
116                 new MutableDoubleScalar.Rel<AccelerationUnit>(Math.sqrt(this.a.getSI() * this.b.getSI()),
117                         AccelerationUnit.METER_PER_SECOND_2);
118         logWeightedAccelerationTimes2.multiply(2); // don't forget the times 2
119 
120         DoubleScalar.Rel<SpeedUnit> dV = DoubleScalar.minus(followerSpeed, leaderSpeed).immutable();
121         // System.out.println("dV is " + dV);
122         // System.out.println(" v is " + gtu.speed(thisEvaluationTime));
123         // System.out.println("s0 is " + this.s0);
124         DoubleScalar.Rel<LengthUnit> sStar =
125                 DoubleScalar.plus(
126                         DoubleScalar.plus(this.s0, Calc.speedTimesTime(followerSpeed, this.tSafe)).immutable(),
127                         Calc.speedTimesTime(
128                                 dV,
129                                 Calc.speedDividedByAcceleration(followerSpeed,
130                                         logWeightedAccelerationTimes2.immutable()))).immutable();
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 DoubleScalar.Rel<LengthUnit>(0, LengthUnit.METER);
136         }
137         // System.out.println("s* is " + sStar);
138 
139         double rightComponent = 1 - Math.pow(sStar.getSI() / headway.getSI(), 2);
140         // if (rightComponent < 0)
141         // {
142         // System.out.println("rightComponent is " + rightComponent);
143         // }
144         MutableDoubleScalar.Abs<AccelerationUnit> newAcceleration =
145                 new MutableDoubleScalar.Abs<AccelerationUnit>(this.a);
146         newAcceleration.multiply(Math.min(leftComponent, rightComponent));
147         // System.out.println("newAcceleration is " + newAcceleration);
148         if (newAcceleration.getSI() * this.stepSize.getSI() + followerSpeed.getSI() < 0)
149         {
150             // System.out.println("Preventing follower from driving backwards " + follower);
151             newAcceleration =
152                     new MutableDoubleScalar.Abs<AccelerationUnit>(-followerSpeed.getSI() / this.stepSize.getSI(),
153                             AccelerationUnit.METER_PER_SECOND_2);
154         }
155         // System.out.println("newAcceleration is " + newAcceleration);
156         return newAcceleration.immutable();
157     }
158 
159     /** {@inheritDoc} */
160     @Override
161     public final DoubleScalar.Rel<TimeUnit> getStepSize()
162     {
163         return new DoubleScalar.Rel<TimeUnit>(this.stepSize);
164     }
165 
166     /** {@inheritDoc} */
167     @Override
168     public final DoubleScalar.Abs<AccelerationUnit> maximumSafeDeceleration()
169     {
170         return this.b;
171     }
172 
173     /** {@inheritDoc} */
174     @Override
175     public final String getName()
176     {
177         return "IDM+";
178     }
179 
180     /** {@inheritDoc} */
181     @Override
182     public final String getLongName()
183     {
184         return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
185                 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
186     }
187 
188 }