VehicleModel.java

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

  2. import org.djunits.value.vdouble.scalar.Acceleration;
  3. import org.djunits.value.vdouble.scalar.Mass;

  4. /**
  5.  * Interface for vehicle models.
  6.  * <p>
  7.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  8.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  9.  * <p>
  10.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 22 mei 2018 <br>
  11.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  12.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  13.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  14.  */
  15. public interface VehicleModel
  16. {

  17.     /** No bounds. */
  18.     VehicleModel NONE = new VehicleModel()
  19.     {
  20.         @Override
  21.         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGTU gtu)
  22.         {
  23.             return acceleration;
  24.         }

  25.         /** {@inheritDoc} */
  26.         @Override
  27.         public String toString()
  28.         {
  29.             return "VehicleModel [None]";
  30.         }
  31.     };

  32.     /** Acceleration bounded by GTU min and max acceleration. */
  33.     VehicleModel MINMAX = new VehicleModel()
  34.     {
  35.         @Override
  36.         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGTU gtu)
  37.         {
  38.             return acceleration.si > gtu.getMaximumDeceleration().si
  39.                     ? (acceleration.si < gtu.getMaximumAcceleration().si ? acceleration : gtu.getMaximumAcceleration())
  40.                     : gtu.getMaximumDeceleration();
  41.         }

  42.         /** {@inheritDoc} */
  43.         @Override
  44.         public String toString()
  45.         {
  46.             return "VehicleModel [MinMax]";
  47.         }
  48.     };

  49.     /**
  50.      * Returns a bounded acceleration.
  51.      * @param acceleration Acceleration; intended acceleration
  52.      * @param gtu LaneBasedGTU; gtu
  53.      * @return Acceleration; possible acceleration
  54.      */
  55.     Acceleration boundAcceleration(Acceleration acceleration, LaneBasedGTU gtu);

  56.     /**
  57.      * GTU mass.
  58.      * @return GTU mass
  59.      */
  60.     default Mass getMass()
  61.     {
  62.         return null;
  63.     }

  64.     /**
  65.      * Moment of inertia about z-axis and center point of gravity.
  66.      * @return moment of inertia about z-axis
  67.      */
  68.     default double getMomentOfInertiaAboutZ()
  69.     {
  70.         return 0;
  71.     }

  72.     /**
  73.      * Defines (fixed) mass and moment of inertia about z-axis.
  74.      * <p>
  75.      * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
  76.      * <br>
  77.      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  78.      * <p>
  79.      * @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 jan. 2019 <br>
  80.      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  81.      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  82.      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  83.      */
  84.     class MassBased implements VehicleModel
  85.     {
  86.         /** Mass. */
  87.         private final Mass mass;

  88.         /** Moment of inertia about z-axis. */
  89.         private final double momentOfInertiaAboutZ;

  90.         /**
  91.          * @param mass Mass; mass
  92.          * @param momentOfInertiaAboutZ double; moment of inertia about z-axis
  93.          */
  94.         public MassBased(final Mass mass, final double momentOfInertiaAboutZ)
  95.         {
  96.             this.mass = mass;
  97.             this.momentOfInertiaAboutZ = momentOfInertiaAboutZ;
  98.         }

  99.         /** {@inheritDoc} */
  100.         @Override
  101.         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGTU gtu)
  102.         {
  103.             return MINMAX.boundAcceleration(acceleration, gtu);
  104.         }

  105.         /** {@inheritDoc} */
  106.         @Override
  107.         public Mass getMass()
  108.         {
  109.             return this.mass;
  110.         }

  111.         /** {@inheritDoc} */
  112.         @Override
  113.         public double getMomentOfInertiaAboutZ()
  114.         {
  115.             return this.momentOfInertiaAboutZ;
  116.         }
  117.     }

  118. }