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 import org.djunits.value.vdouble.scalar.Speed;
6
7
8
9
10
11
12
13
14
15
16
17 public interface VehicleModel
18 {
19
20
21 VehicleModel NONE = new VehicleModel()
22 {
23 @Override
24 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
25 {
26 return acceleration;
27 }
28
29 @Override
30 public String toString()
31 {
32 return "VehicleModel [None]";
33 }
34 };
35
36
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 @Override
48 public String toString()
49 {
50 return "VehicleModel [MinMax]";
51 }
52 };
53
54
55
56
57
58
59
60 Acceleration boundAcceleration(Acceleration acceleration, LaneBasedGtu gtu);
61
62
63
64
65
66 default Mass getMass()
67 {
68 return null;
69 }
70
71
72
73
74
75 default double getMomentOfInertiaAboutZ()
76 {
77 return 0;
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92 default boolean isBrakingLightsOn(final Speed speed, final Acceleration acceleration)
93 {
94 return acceleration.si < (speed.si < 6.944 ? 0.0 : -0.2) - 0.15 - 0.00025 * speed.si * speed.si;
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108 class MassBased implements VehicleModel
109 {
110
111 private final Mass mass;
112
113
114 private final double momentOfInertiaAboutZ;
115
116
117
118
119
120 public MassBased(final Mass mass, final double momentOfInertiaAboutZ)
121 {
122 this.mass = mass;
123 this.momentOfInertiaAboutZ = momentOfInertiaAboutZ;
124 }
125
126 @Override
127 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
128 {
129 return MINMAX.boundAcceleration(acceleration, gtu);
130 }
131
132 @Override
133 public Mass getMass()
134 {
135 return this.mass;
136 }
137
138 @Override
139 public double getMomentOfInertiaAboutZ()
140 {
141 return this.momentOfInertiaAboutZ;
142 }
143 }
144
145 }