1 package org.opentrafficsim.road.gtu.lane.tactical.following;
2
3 import static org.opentrafficsim.base.parameters.constraint.NumericConstraint.POSITIVE;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.value.vdouble.scalar.Acceleration;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.base.parameters.ParameterException;
10 import org.opentrafficsim.base.parameters.ParameterTypeInteger;
11 import org.opentrafficsim.base.parameters.Parameters;
12 import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
13 import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
14
15
16
17
18
19
20
21
22
23
24 public class IDMPlusMulti extends AbstractIDM
25 {
26
27
28 public static final ParameterTypeInteger NLEADERS =
29 new ParameterTypeInteger("nLeaders", "Number of leaders in car-following model.", 2, POSITIVE);
30
31
32
33
34 public IDMPlusMulti()
35 {
36 super(HEADWAY, DESIRED_SPEED);
37 }
38
39
40
41
42
43
44 public IDMPlusMulti(final DesiredHeadwayModel desiredHeadwayModel, final DesiredSpeedModel desiredSpeedModel)
45 {
46 super(desiredHeadwayModel, desiredSpeedModel);
47 }
48
49
50 @Override
51 public final String getName()
52 {
53 return "IDM+multi";
54 }
55
56
57 @Override
58 public final String getLongName()
59 {
60 return "Intelligent Driver Model+ with multi-leader anticipation.";
61 }
62
63
64 @Override
65 protected final Acceleration combineInteractionTerm(final Acceleration aFree, final Parameters parameters,
66 final Speed speed, final Speed desiredSpeed, final Length desiredHeadway,
67 final PerceptionIterable<? extends Headway> leaders) throws ParameterException
68 {
69 Acceleration a = parameters.getParameter(A);
70 double aIntMulti = Double.POSITIVE_INFINITY;
71 int i = 1;
72 double cumulVehicleLengths = 0;
73 int n = parameters.getParameter(NLEADERS);
74 for (Headway leader : leaders)
75 {
76
77
78 double sRatio = dynamicDesiredHeadway(parameters, speed, desiredHeadway.multiplyBy(i), leader.getSpeed()).si
79 / (leader.getDistance().si - cumulVehicleLengths);
80 double aIntSingle = a.si * (1 - sRatio * sRatio);
81 aIntMulti = aIntMulti < aIntSingle ? aIntMulti : aIntSingle;
82 i++;
83 if (i > n)
84 {
85 break;
86 }
87 cumulVehicleLengths += leader.getLength().si;
88 }
89 return new Acceleration(aIntMulti < aFree.si ? aIntMulti : aFree.si, AccelerationUnit.SI);
90 }
91
92 }