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