View Javadoc
1   package org.opentrafficsim.road.gtu.lane;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.djunits.value.vdouble.scalar.Mass;
5   
6   /**
7    * Interface for vehicle models.
8    * <p>
9    * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
11   * <p>
12   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 22 mei 2018 <br>
13   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
14   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
15   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
16   */
17  public interface VehicleModel
18  {
19  
20      /** No bounds. */
21      VehicleModelane/VehicleModel.html#VehicleModel">VehicleModel NONE = new VehicleModel()
22      {
23          @Override
24          public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGTU gtu)
25          {
26              return acceleration;
27          }
28  
29          /** {@inheritDoc} */
30          @Override
31          public String toString()
32          {
33              return "VehicleModel [None]";
34          }
35      };
36  
37      /** Acceleration bounded by GTU min and max acceleration. */
38      VehicleModele/VehicleModel.html#VehicleModel">VehicleModel MINMAX = new VehicleModel()
39      {
40          @Override
41          public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGTU gtu)
42          {
43              return acceleration.si > gtu.getMaximumDeceleration().si
44                      ? (acceleration.si < gtu.getMaximumAcceleration().si ? acceleration : gtu.getMaximumAcceleration())
45                      : gtu.getMaximumDeceleration();
46          }
47  
48          /** {@inheritDoc} */
49          @Override
50          public String toString()
51          {
52              return "VehicleModel [MinMax]";
53          }
54      };
55  
56      /**
57       * Returns a bounded acceleration.
58       * @param acceleration Acceleration; intended acceleration
59       * @param gtu LaneBasedGTU; gtu
60       * @return Acceleration; possible acceleration
61       */
62      Acceleration boundAcceleration(Acceleration acceleration, LaneBasedGTU gtu);
63  
64      /**
65       * GTU mass.
66       * @return GTU mass
67       */
68      default Mass getMass()
69      {
70          return null;
71      }
72  
73      /**
74       * Moment of inertia about z-axis and center point of gravity.
75       * @return moment of inertia about z-axis
76       */
77      default double getMomentOfInertiaAboutZ()
78      {
79          return 0;
80      }
81  
82      /**
83       * Defines (fixed) mass and moment of inertia about z-axis.
84       * <p>
85       * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
86       * <br>
87       * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
88       * <p>
89       * @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 jan. 2019 <br>
90       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
91       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
92       * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
93       */
94      class MassBased implements VehicleModel
95      {
96          /** Mass. */
97          private final Mass mass;
98  
99          /** Moment of inertia about z-axis. */
100         private final double momentOfInertiaAboutZ;
101 
102         /**
103          * @param mass Mass; mass
104          * @param momentOfInertiaAboutZ double; moment of inertia about z-axis
105          */
106         public MassBased(final Mass mass, final double momentOfInertiaAboutZ)
107         {
108             this.mass = mass;
109             this.momentOfInertiaAboutZ = momentOfInertiaAboutZ;
110         }
111 
112         /** {@inheritDoc} */
113         @Override
114         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGTU gtu)
115         {
116             return MINMAX.boundAcceleration(acceleration, gtu);
117         }
118 
119         /** {@inheritDoc} */
120         @Override
121         public Mass getMass()
122         {
123             return this.mass;
124         }
125 
126         /** {@inheritDoc} */
127         @Override
128         public double getMomentOfInertiaAboutZ()
129         {
130             return this.momentOfInertiaAboutZ;
131         }
132     }
133 
134 }