View Javadoc
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   * Behavioral adaptation which sets parameters for situational awareness and reaction time.
17   * 
18   * <pre>
19   *      / SA_MAX,                                                                         taskSaturation &lt; TS_CRIT
20   * SA = | SA_MAX - (SA_MAX - SA_MIN) * (taskSaturation - TS_CRIT) / (TS_MAX - TS_CRIT),   TS_CRIT &lt;= taskSaturation &lt; TS_MAX 
21   *      \ SA_MIN,                                                                         taskSaturation &gt;= TS_MAX
22   * 
23   * TR = (S_MAX - SA) * TR_MAX
24   * </pre>
25   * <p>
26   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
28   * </p>
29   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
31   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
32   */
33  public class AdaptationSituationalAwareness implements BehavioralAdaptation
34  {
35  
36      /** Situational awareness. */
37      public static final ParameterTypeDouble SA = new ParameterTypeDouble("SA", "Situational awareness", 1.0, POSITIVEZERO);
38  
39      /** Minimum situational awareness. */
40      public static final ParameterTypeDouble SA_MIN =
41              new ParameterTypeDouble("SAmin", "Min. situational awareness", 0.5, POSITIVE)
42              {
43                  /** */
44                  private static final long serialVersionUID = 20180403L;
45  
46                  @Override
47                  public void check(final Double value, final Parameters params) throws ParameterException
48                  {
49                      Double saMax = params.getParameterOrNull(SA_MAX);
50                      Throw.when(saMax != null && value > saMax, ParameterException.class,
51                              "Value for SA_MIN should not be larger than SA_MAX.");
52                  }
53              };
54  
55      /** Maximum situational awareness. */
56      public static final ParameterTypeDouble SA_MAX =
57              new ParameterTypeDouble("SAmax", "Max. situational awareness", 1.0, POSITIVE)
58              {
59                  /** */
60                  private static final long serialVersionUID = 20180403L;
61  
62                  @Override
63                  public void check(final Double value, final Parameters params) throws ParameterException
64                  {
65                      Double saMin = params.getParameterOrNull(SA_MIN);
66                      Throw.when(saMin != null && value < saMin, ParameterException.class,
67                              "Value for SA_MAX should not be larger than SA_MIN.");
68                  }
69              };
70  
71      /** Maximum reaction time at 0 situational awareness. */
72      public static final ParameterTypeDuration TR_MAX =
73              new ParameterTypeDuration("TRmax", "Maximum reaction time", Duration.instantiateSI(2.0), POSITIVE);
74  
75      @Override
76      public void adapt(final Parameters parameters, final double taskSaturation) throws ParameterException
77      {
78          // situational awareness
79          double tsCrit = parameters.getParameter(Fuller.TS_CRIT);
80          double tsMax = parameters.getParameter(Fuller.TS_MAX);
81          double saMin = parameters.getParameter(SA_MIN);
82          double saMax = parameters.getParameter(SA_MAX);
83          double sa = taskSaturation < tsCrit ? saMax
84                  : (taskSaturation >= tsMax ? saMin : saMax - (saMax - saMin) * (taskSaturation - tsCrit) / (tsMax - tsCrit));
85          parameters.setParameter(SA, sa);
86          // reaction time
87          parameters.setParameter(ParameterTypes.TR, parameters.getParameter(TR_MAX).times(saMax - sa));
88      }
89  
90  }