1 package org.opentrafficsim.simulationengine.properties;
2
3 import java.util.ArrayList;
4
5 import org.opentrafficsim.core.OTS_SCALAR;
6
7
8
9
10
11
12
13
14
15
16
17 public final class IDMPropertySet implements OTS_SCALAR
18 {
19
20
21
22 private IDMPropertySet()
23 {
24
25 }
26
27
28
29
30
31
32
33
34
35
36
37 public static CompoundProperty makeIDMPropertySet(final String carType, final Acceleration.Abs a,
38 final Acceleration.Abs b, final Length.Rel s0, final Time.Rel tSafe, final int displayPriority)
39 {
40 ArrayList<AbstractProperty<?>> subProperties = new ArrayList<AbstractProperty<?>>();
41 subProperties.add(new ContinuousProperty("a", "maximum acceleration [m/s/s]", a.doubleValue(), 0.5, 5.0,
42 "maximum acceleration %.2fm/s\u00b2", false, 0));
43 subProperties.add(new ContinuousProperty("b", "safe deceleration [m/s/s]", b.doubleValue(), 1.0, 4.0,
44 "maximum comfortable deceleration %.2fm/s\u00b2", false, 0));
45 subProperties.add(new ContinuousProperty("s0", "stationary distance headway [m]", s0.doubleValue(), 1.0, 10.0,
46 "distance headway %.2fm", false, 2));
47 subProperties.add(new ContinuousProperty("tSafe", "time headway", tSafe.doubleValue(), 0.5, 1.5,
48 "time headway %.2fs", false, 3));
49 return new CompoundProperty("IDM/IDM+ " + carType + " params", "Parameters for the " + carType
50 + " car following parameters", subProperties, true, displayPriority);
51 }
52
53
54
55
56
57
58 public static Acceleration.Abs getA(final CompoundProperty set)
59 {
60 return new Acceleration.Abs(findSubProperty("a", set), METER_PER_SECOND_2);
61 }
62
63
64
65
66
67
68 public static Acceleration.Abs getB(final CompoundProperty set)
69 {
70 return new Acceleration.Abs(findSubProperty("b", set), METER_PER_SECOND_2);
71 }
72
73
74
75
76
77
78 public static Length.Rel getS0(final CompoundProperty set)
79 {
80 return new Length.Rel(findSubProperty("s0", set), METER);
81 }
82
83
84
85
86
87
88 public static Time.Rel getTSafe(final CompoundProperty set)
89 {
90 return new Time.Rel(findSubProperty("tSafe", set), SECOND);
91 }
92
93
94
95
96
97
98
99 private static Double findSubProperty(final String name, final CompoundProperty set)
100 {
101 AbstractProperty<?> pp = set.findByShortName(name);
102 if (null == pp)
103 {
104 throw new Error("Cannot find sub property " + name);
105 }
106 if (pp instanceof ContinuousProperty)
107 {
108 return ((ContinuousProperty) pp).getValue();
109 }
110 throw new Error("Cannot find Continuous sub property " + name + " in " + set.getShortName());
111 }
112
113 }