1 package org.opentrafficsim.road.gtu.lane.perception.categories;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Duration;
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djunits.value.vdouble.scalar.Speed;
7
8
9
10
11
12
13
14
15
16
17
18
19 public interface Anticipation
20 {
21
22
23 public final static Anticipation NONE = new Anticipation()
24 {
25 @Override
26 public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
27 final Length traveledDistance)
28 {
29 return neighborTriplet;
30 }
31
32 @Override
33 public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
34 {
35 return Length.ZERO;
36 }
37 };
38
39
40 public final static Anticipation CONSTANT_SPEED = new Anticipation()
41 {
42 @Override
43 public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
44 final Length traveledDistance)
45 {
46 return new NeighborTriplet(
47 neighborTriplet.getHeadway().plus(neighborTriplet.getSpeed().multiplyBy(duration)).minus(traveledDistance),
48 neighborTriplet.getSpeed(), neighborTriplet.getAcceleration());
49 }
50
51 @Override
52 public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
53 {
54 return speed.multiplyBy(duration);
55 }
56 };
57
58
59 public final static Anticipation CONSTANT_ACCELERATION = new Anticipation()
60 {
61 @Override
62 public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
63 final Length traveledDistance)
64 {
65 if (neighborTriplet.getSpeed().si < -neighborTriplet.getAcceleration().si * duration.si)
66 {
67
68 double t = neighborTriplet.getSpeed().si / -neighborTriplet.getAcceleration().si;
69 double dx = neighborTriplet.getSpeed().si * t + .5 * neighborTriplet.getAcceleration().si * t * t;
70 return new NeighborTriplet(Length.createSI(neighborTriplet.getHeadway().si + dx - traveledDistance.si),
71 Speed.ZERO, Acceleration.ZERO);
72 }
73 double dx = neighborTriplet.getSpeed().si * duration.si
74 + .5 * neighborTriplet.getAcceleration().si * duration.si * duration.si;
75 double dv = neighborTriplet.getAcceleration().si * duration.si;
76 return new NeighborTriplet(Length.createSI(neighborTriplet.getHeadway().si + dx - traveledDistance.si),
77 Speed.createSI(neighborTriplet.getSpeed().si + dv), neighborTriplet.getAcceleration());
78 }
79
80 @Override
81 public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
82 {
83 return speed.multiplyBy(duration);
84 }
85 };
86
87
88
89
90
91
92
93
94 NeighborTriplet anticipate(NeighborTriplet neighborTriplet, Duration duration, Length traveledDistance);
95
96
97
98
99
100
101
102
103 Length egoAnticipation(Speed speed, Acceleration acceleration, Duration duration);
104
105
106
107
108
109
110
111
112
113
114
115
116
117 public static class NeighborTriplet
118 {
119
120
121 private final Length headway;
122
123
124 private final Speed speed;
125
126
127 private final Acceleration acceleration;
128
129
130
131
132
133
134 NeighborTriplet(final Length headway, final Speed speed, final Acceleration acceleration)
135 {
136 this.headway = headway;
137 this.speed = speed;
138 this.acceleration = acceleration;
139 }
140
141
142
143
144 public Length getHeadway()
145 {
146 return this.headway;
147 }
148
149
150
151
152 public Speed getSpeed()
153 {
154 return this.speed;
155 }
156
157
158
159
160 public Acceleration getAcceleration()
161 {
162 return this.acceleration;
163 }
164
165
166 @Override
167 public final String toString()
168 {
169 return "NeighborTriplet [headway=" + this.headway + ", speed=" + this.speed + ", acceleration=" + this.acceleration
170 + "]";
171 }
172 }
173 }