AbstractLaneBasedIndividualGTU.java

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

  2. import org.djunits.value.vdouble.scalar.Length;
  3. import org.djunits.value.vdouble.scalar.Speed;
  4. import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
  5. import org.opentrafficsim.core.gtu.GTUException;
  6. import org.opentrafficsim.core.gtu.GTUType;
  7. import org.opentrafficsim.road.network.OTSRoadNetwork;

  8. /**
  9.  * Specific type of LaneBasedGTU. This class adds length, width, maximum speed and a reference to the simulator to the
  10.  * AbstractLaneBasedGTU.
  11.  * <p>
  12.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  13.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  14.  * <p>
  15.  * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
  16.  *          initial version Jan 1, 2015 <br>
  17.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  18.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  19.  */
  20. public abstract class AbstractLaneBasedIndividualGTU extends AbstractLaneBasedGTU2
  21. {
  22.     /** */
  23.     private static final long serialVersionUID = 20140822L;

  24.     /** The maximum length of the GTU (parallel with driving direction). */
  25.     private final Length length;

  26.     /** The maximum width of the GTU (perpendicular to driving direction). */
  27.     private final Length width;

  28.     /** The maximum speed of the GTU (in the driving direction). */
  29.     private final Speed maximumSpeed;

  30.     /** Distance over which the GTU should not change lane after being created. */
  31.     private Length noLaneChangeDistance;

  32.     /**
  33.      * Construct a new AbstractLaneBasedIndividualGTU.
  34.      * @param id String; the id of the GTU
  35.      * @param gtuType GTUType; the type of GTU, e.g. TruckType, CarType, BusType
  36.      * @param length Length; the maximum length of the GTU (parallel with driving direction)
  37.      * @param width Length; the maximum width of the GTU (perpendicular to driving direction)
  38.      * @param maximumSpeed Speed; the maximum speed of the GTU (in the driving direction)
  39.      * @param simulator OTSSimulatorInterface; the simulator
  40.      * @param network OTSRoadNetwork; the network that the GTU is initially registered in
  41.      * @throws GTUException when a parameter is invalid
  42.      */
  43.     @SuppressWarnings("checkstyle:parameternumber")
  44.     public AbstractLaneBasedIndividualGTU(final String id, final GTUType gtuType, final Length length, final Length width,
  45.             final Speed maximumSpeed, final OTSSimulatorInterface simulator, final OTSRoadNetwork network) throws GTUException
  46.     {
  47.         super(id, gtuType, network);
  48.         this.length = length;
  49.         this.width = width;
  50.         if (null == maximumSpeed)
  51.         {
  52.             throw new GTUException("maximumSpeed may not be null");
  53.         }
  54.         this.maximumSpeed = maximumSpeed;
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public final Length getLength()
  59.     {
  60.         return this.length;
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public final Length getWidth()
  65.     {
  66.         return this.width;
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public final Speed getMaximumSpeed()
  71.     {
  72.         return this.maximumSpeed;
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public final void setNoLaneChangeDistance(final Length distance)
  77.     {
  78.         this.noLaneChangeDistance = distance;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public final boolean laneChangeAllowed()
  83.     {
  84.         return this.noLaneChangeDistance == null ? true : getOdometer().gt(this.noLaneChangeDistance);
  85.     }

  86. }