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.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   * 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-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
28   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
29   * <p>
30   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 5 apr. 2018 <br>
31   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
33   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
34   */
35  public class AdaptationSituationalAwareness implements BehavioralAdaptation
36  {
37  
38      /** Situational awareness. */
39      public static final ParameterTypeDouble SA = new ParameterTypeDouble("SA", "Situational awareness", 1.0, POSITIVEZERO);
40  
41      /** Minimum situational awareness. */
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                  /** {@inheritDoc} */
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      /** Maximum situational awareness. */
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                  /** {@inheritDoc} */
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      /** Maximum reaction time at 0 situational awareness. */
76      public static final ParameterTypeDuration TR_MAX =
77              new ParameterTypeDuration("TRmax", "Maximum reaction time", Duration.createSI(2.0), POSITIVE);
78  
79      /** {@inheritDoc} */
80      @Override
81      public void adapt(final Parameters parameters, final double taskSaturation) throws ParameterException
82      {
83          // situational awareness
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          // reaction time
92          parameters.setParameter(ParameterTypes.TR, parameters.getParameter(TR_MAX).multiplyBy(saMax - sa));
93      }
94  
95  }