View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.following;
2   
3   import java.util.SortedMap;
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.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
10  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
11  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
12  
13  /**
14   * <p>
15   * Copyright (c) 2013-2016 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/current/license.html">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 22, 2016 <br>
19   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
20   */
21  
22  public class IDMPlusMulti extends AbstractIDM
23  {
24  
25      /** {@inheritDoc} */
26      @Override
27      public final String getName()
28      {
29          return "IDM+multi";
30      }
31  
32      /** {@inheritDoc} */
33      @Override
34      public final String getLongName()
35      {
36          return "Intelligent Driver Model+ with multi-leader anticipation.";
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      protected final Acceleration combineInteractionTerm(final Acceleration aFree,
42          final BehavioralCharacteristics behavioralCharacteristics, final Speed speed, final Speed desiredSpeed,
43          final Length desiredHeadway, final SortedMap<Length, Speed> leaders) throws ParameterException
44      {
45          Acceleration a = behavioralCharacteristics.getParameter(ParameterTypes.A);
46          double aIntMulti = Double.POSITIVE_INFINITY;
47          int i = 1;
48          double cumulVehicleLengths = 0;
49          for (Length headway : leaders.keySet())
50          {
51              // desired headway is scaled to the i'th leader
52              // current headway is the sum of net headways (i.e. vehicle lengths of vehicles in between are subtracted)
53              double sRatio =
54                  dynamicDesiredHeadway(behavioralCharacteristics, speed, desiredHeadway.multiplyBy(i), leaders.get(headway)).si
55                      / (headway.si - cumulVehicleLengths);
56              double aIntSingle = a.si * (1 - sRatio * sRatio);
57              aIntMulti = aIntMulti < aIntSingle ? aIntMulti : aIntSingle;
58              i++;
59              cumulVehicleLengths += 0; // TODO add vehicle length corresponding to key 'headway'
60          }
61          return new Acceleration(aIntMulti < aFree.si ? aIntMulti : aFree.si, AccelerationUnit.SI);
62      }
63  
64  }