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 java.util.Optional;
7   
8   import org.djunits.value.vdouble.scalar.Duration;
9   import org.djutils.exceptions.Throw;
10  import org.opentrafficsim.base.parameters.ParameterException;
11  import org.opentrafficsim.base.parameters.ParameterTypeDouble;
12  import org.opentrafficsim.base.parameters.ParameterTypeDuration;
13  import org.opentrafficsim.base.parameters.ParameterTypes;
14  import org.opentrafficsim.base.parameters.Parameters;
15  
16  /**
17   * Behavioral adaptation which sets parameters for situational awareness and reaction time.
18   *
19   * <pre>
20   *      / SA_MAX,                                                                         taskSaturation &lt; TS_CRIT
21   * SA = | SA_MAX - (SA_MAX - SA_MIN) * (taskSaturation - TS_CRIT) / (TS_MAX - TS_CRIT),   TS_CRIT &lt;= taskSaturation &lt; TS_MAX
22   *      \ SA_MIN,                                                                         taskSaturation &gt;= TS_MAX
23   *
24   * TR = (S_MAX - SA) * TR_MAX
25   * </pre>
26   * <p>
27   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
28   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
29   * </p>
30   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
31   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
32   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
33   */
34  public class AdaptationSituationalAwareness implements BehavioralAdaptation
35  {
36  
37      /** Situational awareness. */
38      public static final ParameterTypeDouble SA = new ParameterTypeDouble("SA", "Situational awareness", 1.0, POSITIVEZERO);
39  
40      /** Minimum situational awareness. */
41      public static final ParameterTypeDouble SA_MIN =
42              new ParameterTypeDouble("SAmin", "Min. situational awareness", 0.5, POSITIVE)
43              {
44                  @Override
45                  public void check(final Double value, final Parameters params) throws ParameterException
46                  {
47                      Optional<Double> saMax = params.getOptionalParameter(SA_MAX);
48                      Throw.when(saMax.isPresent() && value > saMax.get(), ParameterException.class,
49                              "Value for SA_MIN should not be larger than SA_MAX.");
50                  }
51              };
52  
53      /** Maximum situational awareness. */
54      public static final ParameterTypeDouble SA_MAX =
55              new ParameterTypeDouble("SAmax", "Max. situational awareness", 1.0, POSITIVE)
56              {
57                  @Override
58                  public void check(final Double value, final Parameters params) throws ParameterException
59                  {
60                      Optional<Double> saMin = params.getOptionalParameter(SA_MIN);
61                      Throw.when(saMin.isPresent() && value < saMin.get(), ParameterException.class,
62                              "Value for SA_MAX should not be larger than SA_MIN.");
63                  }
64              };
65  
66      /** Maximum reaction time at 0 situational awareness. */
67      public static final ParameterTypeDuration TR_MAX =
68              new ParameterTypeDuration("TRmax", "Maximum reaction time", Duration.ofSI(2.0), POSITIVE);
69  
70      /**
71       * Constructor.
72       */
73      public AdaptationSituationalAwareness()
74      {
75          //
76      }
77  
78      @Override
79      public void adapt(final Parameters parameters) throws ParameterException
80      {
81          // situational awareness
82          double taskSaturation = parameters.getParameter(Fuller.TS);
83          double tsCrit = parameters.getOptionalParameter(SumFuller.TS_CRIT).orElse(1.0);
84          double tsMax = parameters.getParameter(SumFuller.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.setClaimedParameter(SA, sa, this);
90  
91          // estimation factor
92          parameters.setParameter(FactorEstimation.EST_FACTOR, 1.0 + parameters.getParameter(Fuller.OVER_EST) * (saMax - sa));
93  
94          // reaction time
95          parameters.setParameter(ParameterTypes.TR, parameters.getParameter(TR_MAX).times(saMax - sa));
96      }
97  
98  }