1 package org.opentrafficsim.road.gtu.lane.perception.categories.neighbors;
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 Anticipation NONE = new Anticipation()
24 {
25 @Override
26 public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
27 final Length traveledDistance, final boolean downstream)
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 Anticipation CONSTANT_SPEED = new Anticipation()
41 {
42 @Override
43 public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
44 final Length traveledDistance, final boolean downstream)
45 {
46
47 Length distance = downstream
48 ? neighborTriplet.getHeadway().plus(neighborTriplet.getSpeed().multiplyBy(duration)).minus(traveledDistance)
49 : neighborTriplet.getHeadway().minus(neighborTriplet.getSpeed().multiplyBy(duration))
50 .plus(traveledDistance);
51 return new NeighborTriplet(distance, neighborTriplet.getSpeed(), neighborTriplet.getAcceleration());
52 }
53
54 @Override
55 public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
56 {
57 return speed.multiplyBy(duration);
58 }
59 };
60
61
62 Anticipation CONSTANT_ACCELERATION = new Anticipation()
63 {
64 @Override
65 public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
66 final Length traveledDistance, final boolean downstream)
67 {
68 if (neighborTriplet.getSpeed().si < -neighborTriplet.getAcceleration().si * duration.si)
69 {
70
71 double t = neighborTriplet.getSpeed().si / -neighborTriplet.getAcceleration().si;
72 double dx = neighborTriplet.getSpeed().si * t + .5 * neighborTriplet.getAcceleration().si * t * t;
73 dx = downstream ? dx : -dx;
74 return new NeighborTriplet(Length.createSI(neighborTriplet.getHeadway().si + dx - traveledDistance.si),
75 Speed.ZERO, Acceleration.ZERO);
76 }
77 double dx = neighborTriplet.getSpeed().si * duration.si
78 + .5 * neighborTriplet.getAcceleration().si * duration.si * duration.si;
79 double dv = neighborTriplet.getAcceleration().si * duration.si;
80 return new NeighborTriplet(Length.createSI(neighborTriplet.getHeadway().si + dx - traveledDistance.si),
81 Speed.createSI(neighborTriplet.getSpeed().si + dv), neighborTriplet.getAcceleration());
82 }
83
84 @Override
85 public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
86 {
87 return speed.multiplyBy(duration);
88 }
89 };
90
91
92
93
94
95
96
97
98
99 NeighborTriplet anticipate(NeighborTriplet neighborTriplet, Duration duration, Length traveledDistance, boolean downstream);
100
101
102
103
104
105
106
107
108 Length egoAnticipation(Speed speed, Acceleration acceleration, Duration duration);
109 }