View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.following;
2   
3   import static org.opentrafficsim.base.parameters.constraint.NumericConstraint.POSITIVE;
4   
5   import org.djunits.unit.AccelerationUnit;
6   import org.djunits.value.vdouble.scalar.Acceleration;
7   import org.djunits.value.vdouble.scalar.Length;
8   import org.djunits.value.vdouble.scalar.Speed;
9   import org.opentrafficsim.base.parameters.ParameterException;
10  import org.opentrafficsim.base.parameters.ParameterTypeInteger;
11  import org.opentrafficsim.base.parameters.Parameters;
12  import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
13  import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
14  
15  /**
16   * <p>
17   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
19   * <p>
20   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 22, 2016 <br>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  
24  public class IDMPlusMulti extends AbstractIDM
25  {
26  
27      /** Number of leaders considered parameter. */
28      public static final ParameterTypeInteger NLEADERS =
29              new ParameterTypeInteger("nLeaders", "Number of leaders in car-following model.", 2, POSITIVE);
30  
31      /**
32       * Default constructor using default models for desired headway and desired speed.
33       */
34      public IDMPlusMulti()
35      {
36          super(HEADWAY, DESIRED_SPEED);
37      }
38  
39      /**
40       * Constructor with modular models for desired headway and desired speed.
41       * @param desiredHeadwayModel DesiredHeadwayModel; desired headway model
42       * @param desiredSpeedModel DesiredSpeedModel; desired speed model
43       */
44      public IDMPlusMulti(final DesiredHeadwayModel desiredHeadwayModel, final DesiredSpeedModel desiredSpeedModel)
45      {
46          super(desiredHeadwayModel, desiredSpeedModel);
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public final String getName()
52      {
53          return "IDM+multi";
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public final String getLongName()
59      {
60          return "Intelligent Driver Model+ with multi-leader anticipation.";
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      protected final Acceleration combineInteractionTerm(final Acceleration aFree, final Parameters parameters,
66              final Speed speed, final Speed desiredSpeed, final Length desiredHeadway,
67              final PerceptionIterable<? extends Headway> leaders) throws ParameterException
68      {
69          Acceleration a = parameters.getParameter(A);
70          double aIntMulti = Double.POSITIVE_INFINITY;
71          int i = 1;
72          double cumulVehicleLengths = 0;
73          int n = parameters.getParameter(NLEADERS);
74          for (Headway leader : leaders)
75          {
76              // desired headway is scaled to the i'th leader
77              // current headway is the sum of net headways (i.e. vehicle lengths of vehicles in between are subtracted)
78              double sRatio = dynamicDesiredHeadway(parameters, speed, desiredHeadway.multiplyBy(i), leader.getSpeed()).si
79                      / (leader.getDistance().si - cumulVehicleLengths);
80              double aIntSingle = a.si * (1 - sRatio * sRatio);
81              aIntMulti = aIntMulti < aIntSingle ? aIntMulti : aIntSingle;
82              i++;
83              if (i > n)
84              {
85                  break;
86              }
87              cumulVehicleLengths += leader.getLength().si;
88          }
89          return new Acceleration(aIntMulti < aFree.si ? aIntMulti : aFree.si, AccelerationUnit.SI);
90      }
91  
92  }