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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11 * </p>
12 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
13 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
14 * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
15 */
16 public interface VehicleModel
17 {
18
19 /** No bounds. */
20 VehicleModel NONE = new VehicleModel()
21 {
22 @Override
23 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
24 {
25 return acceleration;
26 }
27
28 /** {@inheritDoc} */
29 @Override
30 public String toString()
31 {
32 return "VehicleModel [None]";
33 }
34 };
35
36 /** Acceleration bounded by GTU min and max acceleration. */
37 VehicleModel MINMAX = new VehicleModel()
38 {
39 @Override
40 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
41 {
42 return acceleration.si > gtu.getMaximumDeceleration().si
43 ? (acceleration.si < gtu.getMaximumAcceleration().si ? acceleration : gtu.getMaximumAcceleration())
44 : gtu.getMaximumDeceleration();
45 }
46
47 /** {@inheritDoc} */
48 @Override
49 public String toString()
50 {
51 return "VehicleModel [MinMax]";
52 }
53 };
54
55 /**
56 * Returns a bounded acceleration.
57 * @param acceleration Acceleration; intended acceleration
58 * @param gtu LaneBasedGtu; gtu
59 * @return Acceleration; possible acceleration
60 */
61 Acceleration boundAcceleration(Acceleration acceleration, LaneBasedGtu gtu);
62
63 /**
64 * GTU mass.
65 * @return GTU mass
66 */
67 default Mass getMass()
68 {
69 return null;
70 }
71
72 /**
73 * Moment of inertia about z-axis and center point of gravity.
74 * @return moment of inertia about z-axis
75 */
76 default double getMomentOfInertiaAboutZ()
77 {
78 return 0;
79 }
80
81 /**
82 * Defines (fixed) mass and moment of inertia about z-axis. Acceleration is limited using {@code VehicleModel.MINMAX}.
83 * <p>
84 * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
85 * <br>
86 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
87 * </p>
88 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
89 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
90 * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
91 */
92 class MassBased implements VehicleModel
93 {
94 /** Mass. */
95 private final Mass mass;
96
97 /** Moment of inertia about z-axis. */
98 private final double momentOfInertiaAboutZ;
99
100 /**
101 * @param mass Mass; mass
102 * @param momentOfInertiaAboutZ double; moment of inertia about z-axis
103 */
104 public MassBased(final Mass mass, final double momentOfInertiaAboutZ)
105 {
106 this.mass = mass;
107 this.momentOfInertiaAboutZ = momentOfInertiaAboutZ;
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
113 {
114 return MINMAX.boundAcceleration(acceleration, gtu);
115 }
116
117 /** {@inheritDoc} */
118 @Override
119 public Mass getMass()
120 {
121 return this.mass;
122 }
123
124 /** {@inheritDoc} */
125 @Override
126 public double getMomentOfInertiaAboutZ()
127 {
128 return this.momentOfInertiaAboutZ;
129 }
130 }
131
132 }