IdmPlusOld.java

  1. package org.opentrafficsim.road.gtu.lane.tactical.following;

  2. import java.io.Serializable;

  3. import org.djunits.unit.AccelerationUnit;
  4. import org.djunits.unit.DurationUnit;
  5. import org.djunits.unit.LengthUnit;
  6. import org.djunits.unit.SpeedUnit;
  7. import org.djunits.value.vdouble.scalar.Acceleration;
  8. import org.djunits.value.vdouble.scalar.Duration;
  9. import org.djunits.value.vdouble.scalar.Length;
  10. import org.djunits.value.vdouble.scalar.Speed;
  11. import org.opentrafficsim.base.parameters.ParameterException;
  12. import org.opentrafficsim.base.parameters.Parameters;
  13. import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
  14. import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
  15. import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
  16. import org.opentrafficsim.road.network.speed.SpeedLimitTypes;

  17. /**
  18.  * IDMPlus implements the <i>Integrated Lane Change Model with Relaxation and Synchronization</i> as published by Wouter J.
  19.  * Schakel, Bart van Arem, Member, IEEE, and Bart D. Netten. 2012. <br>
  20.  * There are two nasty type setting errors in equation 7 in this published version of the paper. Both times an equals sign
  21.  * (<cite>=</cite>) after <cite>a<sub>gain</sub></cite> should <b>not</b> be there.
  22.  * <p>
  23.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  24.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  25.  * </p>
  26.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  27.  */
  28. public class IdmPlusOld extends AbstractGtuFollowingModelMobil implements Serializable
  29. {
  30.     /** */
  31.     private static final long serialVersionUID = 20140704L;

  32.     /** Preferred net longitudinal distance when stopped [m]. */
  33.     private final Length s0;

  34.     /** Longitudinal acceleration [m/s^2]. */
  35.     private Acceleration a;

  36.     /** Longitudinal deceleration [m/s^2]. (Should be a positive value even though it is a <b>de</b>celeration.) */
  37.     private final Acceleration b;

  38.     /** Safe time headway. */
  39.     private Duration tSafe;

  40.     /**
  41.      * Mean speed limit adherence (1.0: mean free speed equals the speed limit; 1.1: mean free speed equals 110% of the speed
  42.      * limit, etc.).
  43.      */
  44.     private double delta;

  45.     /**
  46.      * Default step size used by IDMPlus (not defined in the paper, but 0.5s is a reasonable trade-off between computational
  47.      * speed and accuracy).
  48.      */
  49.     private static final Duration DEFAULT_STEP_SIZE = new Duration(0.5, DurationUnit.SECOND);

  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. Schakel,
  53.      * Victor L. Knoop, and Bart van Arem, published in Transportation Research Record: Journal of the Transportation Research
  54.      * Board, No. 2316, Transportation Research Board of the National Academies, Washington, D.C., 2012, pp. 47–57.
  55.      */
  56.     public IdmPlusOld()
  57.     {
  58.         this.a = new Acceleration(1.56, AccelerationUnit.METER_PER_SECOND_2);
  59.         this.b = new Acceleration(2.09, AccelerationUnit.METER_PER_SECOND_2);
  60.         this.s0 = new Length(3, LengthUnit.METER);
  61.         this.tSafe = new Duration(1.2, DurationUnit.SECOND);
  62.         this.delta = 1d;
  63.     }

  64.     /**
  65.      * Construct a new IDMPlus car following model.
  66.      * @param a Acceleration; the maximum acceleration of a stationary vehicle (normal value is 1 m/s/s)
  67.      * @param b Acceleration; the maximum deemed-safe deceleration (this is a positive value)
  68.      * @param s0 Length; the minimum stationary headway
  69.      * @param tSafe Duration; the minimum time-headway
  70.      * @param delta double; the speed limit adherence (1.0; mean free speed equals the speed limit; 1.1: mean free speed equals
  71.      *            110% of the speed limit; etc.)
  72.      */
  73.     public IdmPlusOld(final Acceleration a, final Acceleration b, final Length s0, final Duration tSafe, final double delta)
  74.     {
  75.         this.a = a;
  76.         this.b = b;
  77.         this.s0 = s0;
  78.         this.tSafe = tSafe;
  79.         this.delta = delta;
  80.     }

  81.     /**
  82.      * Desired speed (taking into account the urge to drive a little faster or slower than the posted speed limit).
  83.      * @param speedLimit Speed; the speed limit
  84.      * @param followerMaximumSpeed Speed; the maximum speed that the follower can drive
  85.      * @return DoubleScalarRel&lt;SpeedUnit&gt;; the desired speed
  86.      */
  87.     private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
  88.     {
  89.         return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
  94.             final Speed leaderSpeed, final Length headway, final Speed speedLimit)
  95.     {
  96.         return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, DEFAULT_STEP_SIZE);
  97.     }

  98.     /** {@inheritDoc} */
  99.     @Override
  100.     public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
  101.             final Speed leaderSpeed, final Length headway, final Speed speedLimit, final Duration stepSize)
  102.     {
  103.         // TODO maxDistance
  104.         double leftComponent = 1 - Math.pow(followerSpeed.getSI() / vDes(speedLimit, followerMaximumSpeed).getSI(), 4);
  105.         if (Double.isNaN(leftComponent))
  106.         {
  107.             leftComponent = 0;
  108.         }
  109.         // limit deceleration for free term (= leftComponent)
  110.         if (leftComponent * this.a.si < -0.5)
  111.         {
  112.             leftComponent = -0.5 / this.a.si;
  113.         }
  114.         Acceleration logWeightedAccelerationTimes2 =
  115.                 new Acceleration(Math.sqrt(this.a.getSI() * this.b.getSI()), AccelerationUnit.SI).times(2);
  116.         // don't forget the times 2

  117.         Speed dV = followerSpeed.minus(leaderSpeed);
  118.         Length sStar = this.s0.plus(followerSpeed.times(this.tSafe))
  119.                 .plus(dV.times(followerSpeed.divide(logWeightedAccelerationTimes2)));

  120.         /*-
  121.         this.s0.plus(Calc.speedTimesTime(followerSpeed, this.tSafe)).plus(
  122.         Calc.speedTimesTime(dV, Calc.speedDividedByAcceleration(followerSpeed, logWeightedAccelerationTimes2)));
  123.          */
  124.         if (sStar.getSI() < 0)
  125.         {
  126.             // Negative value should be treated as 0? This is NOT in the LMRS paper
  127.             // Without this "fix" a higher speed of the leader may cause a lower acceleration (which is crazy)
  128.             sStar = new Length(0, LengthUnit.SI);
  129.         }

  130.         double rightComponent = 1 - Math.pow(sStar.getSI() / headway.getSI(), 2);
  131.         Acceleration newAcceleration = new Acceleration(this.a).times(Math.min(leftComponent, rightComponent));
  132.         if (newAcceleration.getSI() * stepSize.getSI() + followerSpeed.getSI() < 0)
  133.         {
  134.             newAcceleration = new Acceleration(-followerSpeed.getSI() / stepSize.getSI(), AccelerationUnit.SI);
  135.         }
  136.         return newAcceleration;
  137.     }

  138.     /** {@inheritDoc} */
  139.     @Override
  140.     public final Duration getStepSize()
  141.     {
  142.         return DEFAULT_STEP_SIZE;
  143.     }

  144.     /** {@inheritDoc} */
  145.     @Override
  146.     public final Acceleration getMaximumSafeDeceleration()
  147.     {
  148.         return this.b;
  149.     }

  150.     /** {@inheritDoc} */
  151.     @Override
  152.     public final String getName()
  153.     {
  154.         return "IDM+";
  155.     }

  156.     /** {@inheritDoc} */
  157.     @Override
  158.     public final String getLongName()
  159.     {
  160.         return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(),
  161.                 this.a.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
  162.     }

  163.     /** {@inheritDoc} */
  164.     @Override
  165.     public final void setA(final Acceleration a)
  166.     {
  167.         this.a = a;
  168.     }

  169.     /** {@inheritDoc} */
  170.     @Override
  171.     public final void setT(final Duration t)
  172.     {
  173.         this.tSafe = t;
  174.     }

  175.     /** {@inheritDoc} */
  176.     @Override
  177.     public final void setFspeed(final double fSpeed)
  178.     {
  179.         this.delta = fSpeed;
  180.     }

  181.     // The following is inherited from CarFollowingModel

  182.     /** {@inheritDoc} */
  183.     @Override
  184.     public final Speed desiredSpeed(final Parameters parameters, final SpeedLimitInfo speedInfo) throws ParameterException
  185.     {
  186.         throw new UnsupportedOperationException("Old car-following model does not support desired speed.");
  187.     }

  188.     /** {@inheritDoc} */
  189.     @Override
  190.     public final Length desiredHeadway(final Parameters parameters, final Speed speed) throws ParameterException
  191.     {
  192.         throw new UnsupportedOperationException("Old car-following model does not support desired headway.");
  193.     }

  194.     /** {@inheritDoc} */
  195.     @Override
  196.     public final Acceleration followingAcceleration(final Parameters parameters, final Speed speed,
  197.             final SpeedLimitInfo speedInfo, final PerceptionIterable<? extends Headway> leaders) throws ParameterException
  198.     {
  199.         Length headway;
  200.         Speed leaderSpeed;
  201.         if (leaders.isEmpty())
  202.         {
  203.             headway = new Length(Double.MAX_VALUE, LengthUnit.SI);
  204.             leaderSpeed = speed;
  205.         }
  206.         else
  207.         {
  208.             Headway leader = leaders.first();
  209.             headway = leader.getDistance();
  210.             leaderSpeed = leader.getSpeed();
  211.         }
  212.         return this.computeAcceleration(speed, speedInfo.getSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED), leaderSpeed, headway,
  213.                 speedInfo.getSpeedInfo(SpeedLimitTypes.FIXED_SIGN));
  214.     }

  215.     /** {@inheritDoc} */
  216.     @Override
  217.     public final String toString()
  218.     {
  219.         return "IDMPlusOld [s0=" + this.s0 + ", a=" + this.a + ", b=" + this.b + ", tSafe=" + this.tSafe + ", delta="
  220.                 + this.delta + ", stepSize=" + DEFAULT_STEP_SIZE + "]";
  221.     }

  222. }