1 package org.opentrafficsim.road.gtu.lane.tactical.following;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Length;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.base.parameters.ParameterException;
7 import org.opentrafficsim.base.parameters.ParameterTypeAcceleration;
8 import org.opentrafficsim.base.parameters.ParameterTypeDouble;
9 import org.opentrafficsim.base.parameters.ParameterTypeDuration;
10 import org.opentrafficsim.base.parameters.ParameterTypeLength;
11 import org.opentrafficsim.base.parameters.ParameterTypes;
12 import org.opentrafficsim.base.parameters.Parameters;
13 import org.opentrafficsim.base.parameters.constraint.ConstraintInterface;
14 import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
15 import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
16 import org.opentrafficsim.road.gtu.lane.tactical.util.SpeedLimitUtil;
17 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public abstract class AbstractIdm extends AbstractCarFollowingModel
32 {
33
34
35
36 protected static final ParameterTypeAcceleration A = ParameterTypes.A;
37
38
39 protected static final ParameterTypeAcceleration B = ParameterTypes.B;
40
41
42 protected static final ParameterTypeDuration T = ParameterTypes.T;
43
44
45 protected static final ParameterTypeLength S0 = ParameterTypes.S0;
46
47
48 protected static final ParameterTypeAcceleration B0 = ParameterTypes.B0;
49
50
51 protected static final ParameterTypeDouble FSPEED = ParameterTypes.FSPEED;
52
53
54
55 public static final ParameterTypeDouble DELTA = new ParameterTypeDouble("delta",
56 "Acceleration flattening exponent towards desired speed", 4.0, ConstraintInterface.POSITIVE);
57
58
59 public static final DesiredHeadwayModel HEADWAY = new DesiredHeadwayModel()
60 {
61 @Override
62 public Length desiredHeadway(final Parameters parameters, final Speed speed) throws ParameterException
63 {
64 return Length.instantiateSI(parameters.getParameter(S0).si + speed.si * parameters.getParameter(T).si);
65 }
66 };
67
68
69 public static final DesiredSpeedModel DESIRED_SPEED = new DesiredSpeedModel()
70 {
71 @Override
72 public Speed desiredSpeed(final Parameters parameters, final SpeedLimitInfo speedInfo) throws ParameterException
73 {
74 Speed consideredSpeed = SpeedLimitUtil.getLegalSpeedLimit(speedInfo).times(parameters.getParameter(FSPEED));
75 Speed maxVehicleSpeed = SpeedLimitUtil.getMaximumVehicleSpeed(speedInfo);
76 return consideredSpeed.le(maxVehicleSpeed) ? consideredSpeed : maxVehicleSpeed;
77 }
78 };
79
80
81
82
83
84
85 public AbstractIdm(final DesiredHeadwayModel desiredHeadwayModel, final DesiredSpeedModel desiredSpeedModel)
86 {
87 super(desiredHeadwayModel, desiredSpeedModel);
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 @Override
106 @SuppressWarnings("checkstyle:designforextension")
107 protected Acceleration followingAcceleration(final Parameters parameters, final Speed speed, final Speed desiredSpeed,
108 final Length desiredHeadway, final PerceptionIterable<? extends Headway> leaders) throws ParameterException
109 {
110 Acceleration a = parameters.getParameter(A);
111 Acceleration b0 = parameters.getParameter(B0);
112 double delta = parameters.getParameter(DELTA);
113 double aFree = a.si * (1 - Math.pow(speed.si / desiredSpeed.si, delta));
114
115 aFree = aFree > -b0.si ? aFree : -b0.si;
116
117 if (leaders.isEmpty())
118 {
119 return Acceleration.instantiateSI(aFree);
120 }
121
122 return combineInteractionTerm(Acceleration.instantiateSI(aFree), parameters, speed, desiredSpeed, desiredHeadway,
123 leaders);
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138 protected abstract Acceleration combineInteractionTerm(Acceleration aFree, Parameters parameters, Speed speed,
139 Speed desiredSpeed, Length desiredHeadway, PerceptionIterable<? extends Headway> leaders) throws ParameterException;
140
141
142
143
144
145
146
147
148
149
150 protected final Length dynamicDesiredHeadway(final Parameters parameters, final Speed speed, final Length desiredHeadway,
151 final Speed leaderSpeed) throws ParameterException
152 {
153 double sStar = desiredHeadway.si + dynamicHeadwayTerm(parameters, speed, leaderSpeed).si;
154
155
156
157
158
159
160
161 Length s0 = parameters.getParameter(S0);
162
163
164
165
166 return Length.instantiateSI(sStar >= s0.si ? sStar : s0.si);
167 }
168
169
170
171
172
173
174
175
176
177 protected final Length dynamicHeadwayTerm(final Parameters parameters, final Speed speed, final Speed leaderSpeed)
178 throws ParameterException
179 {
180 Acceleration a = parameters.getParameter(A);
181 Acceleration b = parameters.getParameter(B);
182 return Length.instantiateSI(speed.si * (speed.si - leaderSpeed.si) / (2 * Math.sqrt(a.si * b.si)));
183 }
184
185 }