1 package org.opentrafficsim.road.gtu.lane.tactical.following;
2
3 import static org.opentrafficsim.core.gtu.behavioralcharacteristics.AbstractParameterType.Check.POSITIVE;
4
5 import java.util.SortedMap;
6
7 import org.djunits.unit.AccelerationUnit;
8 import org.djunits.unit.LengthUnit;
9 import org.djunits.value.vdouble.scalar.Acceleration;
10 import org.djunits.value.vdouble.scalar.Length;
11 import org.djunits.value.vdouble.scalar.Speed;
12 import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
13 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
14 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypeDouble;
15 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
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 public static final ParameterTypeDouble DELTA = new ParameterTypeDouble("delta",
36 "Acceleration flattening exponent towards desired speed.", 4.0, POSITIVE);
37
38
39 @Override
40 public final Speed desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
41 throws ParameterException
42 {
43 Speed consideredSpeed =
44 SpeedLimitUtil.getLegalSpeedLimit(speedInfo).multiplyBy(behavioralCharacteristics.getParameter(ParameterTypes.FSPEED));
45 Speed maxVehicleSpeed = SpeedLimitUtil.getMaximumVehicleSpeed(speedInfo);
46 return consideredSpeed.le(maxVehicleSpeed) ? consideredSpeed : maxVehicleSpeed;
47 }
48
49
50 @Override
51 public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
52 throws ParameterException
53 {
54 return behavioralCharacteristics.getParameter(ParameterTypes.S0).plus(
55 speed.multiplyBy(behavioralCharacteristics.getParameter(ParameterTypes.T)));
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 @Override
73 @SuppressWarnings("checkstyle:designforextension")
74 protected Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed,
75 final Speed desiredSpeed, final Length desiredHeadway, final SortedMap<Length, Speed> leaders)
76 throws ParameterException
77 {
78 Acceleration a = behavioralCharacteristics.getParameter(ParameterTypes.A);
79 Acceleration b0 = behavioralCharacteristics.getParameter(ParameterTypes.B0);
80 double delta = behavioralCharacteristics.getParameter(DELTA);
81 double aFree = a.si * (1 - Math.pow(speed.si / desiredSpeed.si, delta));
82
83 aFree = aFree > -b0.si ? aFree : -b0.si;
84
85 if (leaders.isEmpty())
86 {
87 return new Acceleration(aFree, AccelerationUnit.SI);
88 }
89
90 return combineInteractionTerm(new Acceleration(aFree, AccelerationUnit.SI), behavioralCharacteristics, speed,
91 desiredSpeed, desiredHeadway, leaders);
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105 protected abstract Acceleration combineInteractionTerm(Acceleration aFree,
106 BehavioralCharacteristics behavioralCharacteristics, Speed speed, Speed desiredSpeed, Length desiredHeadway,
107 SortedMap<Length, Speed> leaders) throws ParameterException;
108
109
110
111
112
113
114
115
116
117
118 protected final Length dynamicDesiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed,
119 final Length desiredHeadway, final Speed leaderSpeed) throws ParameterException
120 {
121 double sStar = desiredHeadway.si + dynamicHeadwayTerm(behavioralCharacteristics, speed, leaderSpeed).si;
122
123
124
125
126
127
128
129 return new Length(sStar >= 0 ? sStar : 0, LengthUnit.SI);
130 }
131
132
133
134
135
136
137
138
139
140 protected final Length dynamicHeadwayTerm(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed,
141 final Speed leaderSpeed) throws ParameterException
142 {
143 Acceleration a = behavioralCharacteristics.getParameter(ParameterTypes.A);
144 Acceleration b = behavioralCharacteristics.getParameter(ParameterTypes.B);
145 return new Length(speed.si * (speed.si - leaderSpeed.si) / (2 * Math.sqrt(a.si * b.si)), LengthUnit.SI);
146 }
147
148 }