View Javadoc
1   package org.opentrafficsim.simulationengine.properties;
2   
3   import java.util.ArrayList;
4   
5   import org.opentrafficsim.core.OTS_SCALAR;
6   
7   /**
8    * Compound property for IDM or IDMPlus parameters
9    * <p>
10   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12   * <p>
13   * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
14   * initial version 5 jan. 2015 <br>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   */
17  public final class IDMPropertySet implements OTS_SCALAR
18  {
19      /**
20       * This class shall never be instantiated.
21       */
22      private IDMPropertySet()
23      {
24          // Prevent instantiation of this class
25      }
26  
27      /**
28       * Create a CompoundProperty for the IDM or IDMPlus parameters for a specified car type.
29       * @param carType String; the type of the car
30       * @param a DoubleScalar.Abs&lt;AccelerationUnit&gt;; the maximum acceleration of the car
31       * @param b DoubleScalar.Abs&lt;AccelerationUnit&gt;; the maximum comfortable deceleration of the car
32       * @param s0 DoubleScalar.Rel&lt;LengthUnit&gt;; the stationary distance headway
33       * @param tSafe DoubleScalar.Rel&lt;TimeUnit&gt;; the time headway
34       * @param displayPriority int; the display priority of the returned CompoundProperty
35       * @return CompoundProperty
36       */
37      public static CompoundProperty makeIDMPropertySet(final String carType, final Acceleration.Abs a,
38          final Acceleration.Abs b, final Length.Rel s0, final Time.Rel tSafe, final int displayPriority)
39      {
40          ArrayList<AbstractProperty<?>> subProperties = new ArrayList<AbstractProperty<?>>();
41          subProperties.add(new ContinuousProperty("a", "maximum acceleration [m/s/s]", a.doubleValue(), 0.5, 5.0,
42              "maximum acceleration %.2fm/s\u00b2", false, 0));
43          subProperties.add(new ContinuousProperty("b", "safe deceleration [m/s/s]", b.doubleValue(), 1.0, 4.0,
44              "maximum comfortable deceleration %.2fm/s\u00b2", false, 0));
45          subProperties.add(new ContinuousProperty("s0", "stationary distance headway [m]", s0.doubleValue(), 1.0, 10.0,
46              "distance headway %.2fm", false, 2));
47          subProperties.add(new ContinuousProperty("tSafe", "time headway", tSafe.doubleValue(), 0.5, 1.5,
48              "time headway %.2fs", false, 3));
49          return new CompoundProperty("IDM/IDM+ " + carType + " params", "Parameters for the " + carType
50              + " car following parameters", subProperties, true, displayPriority);
51      }
52  
53      /**
54       * Return the maximum acceleration.
55       * @param set CompoundProperty (should have been created with makeIDMPropertySet)
56       * @return DoubleScalar.Abs&lt;AccelerationUnit&gt;
57       */
58      public static Acceleration.Abs getA(final CompoundProperty set)
59      {
60          return new Acceleration.Abs(findSubProperty("a", set), METER_PER_SECOND_2);
61      }
62  
63      /**
64       * Return the maximum comfortable deceleration.
65       * @param set CompoundProperty (should have been created with makeIDMPropertySet)
66       * @return DoubleScalar.Abs&lt;AccelerationUnit&gt;
67       */
68      public static Acceleration.Abs getB(final CompoundProperty set)
69      {
70          return new Acceleration.Abs(findSubProperty("b", set), METER_PER_SECOND_2);
71      }
72  
73      /**
74       * Return the static headway.
75       * @param set CompoundProperty (should have been created with makeIDMPropertySet)
76       * @return DoubleScalar.Abs&lt;LengthUnit&gt;
77       */
78      public static Length.Rel getS0(final CompoundProperty set)
79      {
80          return new Length.Rel(findSubProperty("s0", set), METER);
81      }
82  
83      /**
84       * Return the time headway.
85       * @param set CompoundProperty (should have been created with makeIDMPropertySet)
86       * @return DoubleScalar.Abs&lt;TimeUnit&gt;
87       */
88      public static Time.Rel getTSafe(final CompoundProperty set)
89      {
90          return new Time.Rel(findSubProperty("tSafe", set), SECOND);
91      }
92  
93      /**
94       * Find the Continuous sub property with the specified name.
95       * @param name String; name of the sub property
96       * @param set CompoundProperty; the set to search
97       * @return Double; the value of the Continuous sub property with the specified name
98       */
99      private static Double findSubProperty(final String name, final CompoundProperty set)
100     {
101         AbstractProperty<?> pp = set.findByShortName(name);
102         if (null == pp)
103         {
104             throw new Error("Cannot find sub property " + name);
105         }
106         if (pp instanceof ContinuousProperty)
107         {
108             return ((ContinuousProperty) pp).getValue();
109         }
110         throw new Error("Cannot find Continuous sub property " + name + " in " + set.getShortName());
111     }
112 
113 }