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 protected static final ParameterTypeAcceleration A = ParameterTypes.A;
36
37
38 protected static final ParameterTypeAcceleration B = ParameterTypes.B;
39
40
41 protected static final ParameterTypeDuration T = ParameterTypes.T;
42
43
44 protected static final ParameterTypeLength S0 = ParameterTypes.S0;
45
46
47 protected static final ParameterTypeAcceleration B0 = ParameterTypes.B0;
48
49
50 protected static final ParameterTypeDouble FSPEED = ParameterTypes.FSPEED;
51
52
53 public static final ParameterTypeDouble DELTA = new ParameterTypeDouble("delta",
54 "Acceleration flattening exponent towards desired speed.", 4.0, ConstraintInterface.POSITIVE);
55
56
57 public static final DesiredHeadwayModel HEADWAY = new DesiredHeadwayModel()
58 {
59 @Override
60 public Length desiredHeadway(final Parameters parameters, final Speed speed) throws ParameterException
61 {
62 return Length.createSI(parameters.getParameter(S0).si + speed.si * parameters.getParameter(T).si);
63 }
64 };
65
66
67 public static final DesiredSpeedModel DESIRED_SPEED = new DesiredSpeedModel()
68 {
69 @Override
70 public Speed desiredSpeed(final Parameters parameters, final SpeedLimitInfo speedInfo) throws ParameterException
71 {
72 Speed consideredSpeed = SpeedLimitUtil.getLegalSpeedLimit(speedInfo).multiplyBy(parameters.getParameter(FSPEED));
73 Speed maxVehicleSpeed = SpeedLimitUtil.getMaximumVehicleSpeed(speedInfo);
74 return consideredSpeed.le(maxVehicleSpeed) ? consideredSpeed : maxVehicleSpeed;
75 }
76 };
77
78
79
80
81
82
83 public AbstractIDM(final DesiredHeadwayModel desiredHeadwayModel, final DesiredSpeedModel desiredSpeedModel)
84 {
85 super(desiredHeadwayModel, desiredSpeedModel);
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 @Override
104 @SuppressWarnings("checkstyle:designforextension")
105 protected Acceleration followingAcceleration(final Parameters parameters, final Speed speed, final Speed desiredSpeed,
106 final Length desiredHeadway, final PerceptionIterable<? extends Headway> leaders) throws ParameterException
107 {
108 Acceleration a = parameters.getParameter(A);
109 Acceleration b0 = parameters.getParameter(B0);
110 double delta = parameters.getParameter(DELTA);
111 double aFree = a.si * (1 - Math.pow(speed.si / desiredSpeed.si, delta));
112
113 aFree = aFree > -b0.si ? aFree : -b0.si;
114
115 if (leaders.isEmpty())
116 {
117 return Acceleration.createSI(aFree);
118 }
119
120 return combineInteractionTerm(Acceleration.createSI(aFree), parameters, speed, desiredSpeed, desiredHeadway, leaders);
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135 protected abstract Acceleration combineInteractionTerm(Acceleration aFree, Parameters parameters, Speed speed,
136 Speed desiredSpeed, Length desiredHeadway, PerceptionIterable<? extends Headway> leaders) throws ParameterException;
137
138
139
140
141
142
143
144
145
146
147 protected final Length dynamicDesiredHeadway(final Parameters parameters, final Speed speed, final Length desiredHeadway,
148 final Speed leaderSpeed) throws ParameterException
149 {
150 double sStar = desiredHeadway.si + dynamicHeadwayTerm(parameters, speed, leaderSpeed).si;
151
152
153
154
155
156
157
158 Length s0 = parameters.getParameter(S0);
159
160
161
162
163 return Length.createSI(sStar >= s0.si ? sStar : s0.si);
164 }
165
166
167
168
169
170
171
172
173
174 protected final Length dynamicHeadwayTerm(final Parameters parameters, final Speed speed, final Speed leaderSpeed)
175 throws ParameterException
176 {
177 Acceleration a = parameters.getParameter(A);
178 Acceleration b = parameters.getParameter(B);
179 return Length.createSI(speed.si * (speed.si - leaderSpeed.si) / (2 * Math.sqrt(a.si * b.si)));
180 }
181
182 }