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.Length;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.djunits.value.vdouble.scalar.Time;
7 import org.opentrafficsim.base.parameters.ParameterException;
8 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9 import org.opentrafficsim.road.gtu.lane.perception.mental.AdaptationSituationalAwareness;
10
11
12
13
14
15
16
17
18
19
20
21
22 public interface Estimation
23 {
24
25 Estimation NONE = new Estimation()
26 {
27 @Override
28 public NeighborTriplet estimate(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
29 final Length distance, final boolean downstream, final Time when) throws ParameterException
30 {
31 return new NeighborTriplet(distance, perceivedGtu.getSpeed(), perceivedGtu.getAcceleration());
32 }
33 };
34
35
36 Estimation UNDERESTIMATION = new FactorEstimation()
37 {
38
39 @Override
40 boolean overEstimation()
41 {
42 return false;
43 }
44 };
45
46
47 Estimation OVERESTIMATION = new FactorEstimation()
48 {
49
50 @Override
51 boolean overEstimation()
52 {
53 return true;
54 }
55 };
56
57
58
59
60
61
62
63
64
65
66
67 NeighborTriplet estimate(LaneBasedGTU perceivingGtu, LaneBasedGTU perceivedGtu, Length distance, boolean downstream,
68 Time when) throws ParameterException;
69
70
71
72
73
74
75
76
77
78
79
80
81
82 abstract class FactorEstimation implements Estimation
83 {
84
85
86 private final double sign;
87
88
89
90
91 FactorEstimation()
92 {
93 this.sign = overEstimation() ? 1.0 : -1.0;
94 }
95
96
97 @Override
98 public NeighborTriplet estimate(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
99 final Length distance, final boolean downstream, final Time when) throws ParameterException
100 {
101 double factor = 1.0 + this.sign * (perceivingGtu.getParameters().getParameter(AdaptationSituationalAwareness.SA_MAX)
102 - perceivingGtu.getParameters().getParameter(AdaptationSituationalAwareness.SA));
103 double delta = (perceivedGtu.getOdometer().si - perceivedGtu.getOdometer(when).si)
104 - (perceivingGtu.getOdometer().si - perceivingGtu.getOdometer(when).si);
105 if (downstream)
106 {
107 delta = -delta;
108 }
109 Length headway = Length.createSI((distance.si + delta) * factor);
110 double egoSpeed = perceivingGtu.getSpeed(when).si;
111 Speed speed = Speed.createSI(egoSpeed + factor * (perceivedGtu.getSpeed(when).si - egoSpeed));
112 Acceleration acceleration = perceivedGtu.getAcceleration(when);
113 return new NeighborTriplet(headway, speed, acceleration);
114 }
115
116
117
118
119
120 abstract boolean overEstimation();
121 }
122
123 }