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