1 package org.opentrafficsim.road.gtu.lane.perception.mental;
2
3 import static org.opentrafficsim.base.parameters.constraint.NumericConstraint.POSITIVE;
4 import static org.opentrafficsim.base.parameters.constraint.NumericConstraint.POSITIVEZERO;
5
6 import org.djunits.value.vdouble.scalar.Duration;
7 import org.djutils.exceptions.Throw;
8 import org.opentrafficsim.base.parameters.ParameterException;
9 import org.opentrafficsim.base.parameters.ParameterTypeDouble;
10 import org.opentrafficsim.base.parameters.ParameterTypeDuration;
11 import org.opentrafficsim.base.parameters.ParameterTypes;
12 import org.opentrafficsim.base.parameters.Parameters;
13 import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller.BehavioralAdaptation;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public class AdaptationSituationalAwareness implements BehavioralAdaptation
35 {
36
37
38 public static final ParameterTypeDouble SA = new ParameterTypeDouble("SA", "Situational awareness", 1.0, POSITIVEZERO);
39
40
41 public static final ParameterTypeDouble SA_MIN =
42 new ParameterTypeDouble("SAmin", "Min. situational awareness", 0.5, POSITIVE)
43 {
44
45 private static final long serialVersionUID = 20180403L;
46
47
48 @Override
49 public void check(final Double value, final Parameters params) throws ParameterException
50 {
51 Double saMax = params.getParameterOrNull(SA_MAX);
52 Throw.when(saMax != null && value > saMax, ParameterException.class,
53 "Value for SA_MIN should not be larger than SA_MAX.");
54 }
55 };
56
57
58 public static final ParameterTypeDouble SA_MAX =
59 new ParameterTypeDouble("SAmax", "Max. situational awareness", 1.0, POSITIVE)
60 {
61
62 private static final long serialVersionUID = 20180403L;
63
64
65 @Override
66 public void check(final Double value, final Parameters params) throws ParameterException
67 {
68 Double saMin = params.getParameterOrNull(SA_MIN);
69 Throw.when(saMin != null && value < saMin, ParameterException.class,
70 "Value for SA_MAX should not be larger than SA_MIN.");
71 }
72 };
73
74
75 public static final ParameterTypeDuration TR_MAX =
76 new ParameterTypeDuration("TRmax", "Maximum reaction time", Duration.createSI(2.0), POSITIVE);
77
78
79 @Override
80 public void adapt(final Parameters parameters, final double taskSaturation) throws ParameterException
81 {
82
83 double tsCrit = parameters.getParameter(Fuller.TS_CRIT);
84 double tsMax = parameters.getParameter(Fuller.TS_MAX);
85 double saMin = parameters.getParameter(SA_MIN);
86 double saMax = parameters.getParameter(SA_MAX);
87 double sa = taskSaturation < tsCrit ? saMax
88 : (taskSaturation >= tsMax ? saMin : saMax - (saMax - saMin) * (taskSaturation - tsCrit) / (tsMax - tsCrit));
89 parameters.setParameter(SA, sa);
90
91 parameters.setParameter(ParameterTypes.TR, parameters.getParameter(TR_MAX).multiplyBy(saMax - sa));
92 }
93
94 }