View Javadoc
1   package org.opentrafficsim.road.gtu.lane;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djunits.value.vdouble.scalar.Speed;
5   import org.opentrafficsim.core.gtu.GTUException;
6   import org.opentrafficsim.core.gtu.GTUType;
7   import org.opentrafficsim.core.network.OTSNetwork;
8   
9   import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
10  
11  /**
12   * Specific type of LaneBasedGTU. This class adds length, width, maximum speed and a reference to the simulator to the
13   * AbstractLaneBasedGTU.
14   * <p>
15   * Copyright (c) 2013-2018 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/license.html">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
19   *          initial version Jan 1, 2015 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
22   */
23  public abstract class AbstractLaneBasedIndividualGTU extends AbstractLaneBasedGTU
24  {
25      /** */
26      private static final long serialVersionUID = 20140822L;
27  
28      /** The maximum length of the GTU (parallel with driving direction). */
29      private final Length length;
30  
31      /** The maximum width of the GTU (perpendicular to driving direction). */
32      private final Length width;
33  
34      /** The maximum speed of the GTU (in the driving direction). */
35      private final Speed maximumSpeed;
36  
37      /** Distance over which the GTU should not change lane after being created. */
38      private Length noLaneChangeDistance;
39  
40      /**
41       * Construct a new AbstractLaneBasedIndividualGTU.
42       * @param id the id of the GTU
43       * @param gtuType the type of GTU, e.g. TruckType, CarType, BusType
44       * @param length the maximum length of the GTU (parallel with driving direction)
45       * @param width the maximum width of the GTU (perpendicular to driving direction)
46       * @param maximumSpeed the maximum speed of the GTU (in the driving direction)
47       * @param simulator the simulator
48       * @param network the network that the GTU is initially registered in
49       * @throws GTUException when a parameter is invalid
50       */
51      @SuppressWarnings("checkstyle:parameternumber")
52      public AbstractLaneBasedIndividualGTU(final String id, final GTUType gtuType, final Length length, final Length width,
53              final Speed maximumSpeed, final DEVSSimulatorInterface.TimeDoubleUnit simulator, final OTSNetwork network) throws GTUException
54      {
55          super(id, gtuType, simulator, network);
56          this.length = length;
57          this.width = width;
58          if (null == maximumSpeed)
59          {
60              throw new GTUException("maximumSpeed may not be null");
61          }
62          this.maximumSpeed = maximumSpeed;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public final Length getLength()
68      {
69          return this.length;
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public final Length getWidth()
75      {
76          return this.width;
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public final Speed getMaximumSpeed()
82      {
83          return this.maximumSpeed;
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public final void setNoLaneChangeDistance(final Length distance)
89      {
90          this.noLaneChangeDistance = distance;
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      public final boolean laneChangeAllowed()
96      {
97          return this.noLaneChangeDistance == null ? true : getOdometer().gt(this.noLaneChangeDistance);
98      }
99  
100 }