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.Set;
7   
8   import org.opentrafficsim.base.parameters.ParameterException;
9   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
10  import org.opentrafficsim.base.parameters.Parameters;
11  import org.opentrafficsim.core.gtu.GTUException;
12  import org.opentrafficsim.core.gtu.Try;
13  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
14  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
15  
16  import nl.tudelft.simulation.language.Throw;
17  
18  /**
19   * Task-capability interface in accordance to Fuller (2011). Task demand is the sum of demands described by individual
20   * {@code Task}s. These take exogenous information to describe the workload in fundamental relations. Task demand is divided by
21   * task capability to arrive at a task saturation. Task saturation is input to {@code BehavioralAdaptation}s which alter
22   * parameters describing personal traits, such as desired headway and desired speed. In this way, task demand is kept at an
23   * equilibrium as described by Fuller.
24   * <p>
25   * A {@code BehavioralAdaptation} may also determine what the level of situational awareness is, which includes determining
26   * reaction time. Both situational awareness and reaction time parameters can be used in perception to model deteriorated
27   * perception due to a task demand imbalance.
28   * <p>
29   * Fuller, R., Driver control theory: From task difficulty homeostasis to risk allostasis, in Handbook of Traffic Psychology.
30   * 2011. p. 13-26
31   * <p>
32   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
33   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
34   * <p>
35   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 apr. 2018 <br>
36   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
37   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
38   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
39   */
40  public class Fuller implements Mental
41  {
42  
43      // Parameters
44  
45      /** Task capability in nominal task capability units, i.e. mean is 1. */
46      public static final ParameterTypeDouble TC = new ParameterTypeDouble("TC", "Task capability", 1.0, POSITIVE);
47  
48      /** Critical task saturation. */
49      public static final ParameterTypeDouble TS_CRIT =
50              new ParameterTypeDouble("TScrit", "Critical task saturation", 0.8, POSITIVEZERO)
51              {
52                  /** */
53                  private static final long serialVersionUID = 20180403L;
54  
55                  /** {@inheritDoc} */
56                  @Override
57                  public void check(final Double value, final Parameters params) throws ParameterException
58                  {
59                      Double tsMax = params.getParameterOrNull(TS_MAX);
60                      Throw.when(tsMax != null && value > tsMax, ParameterException.class,
61                              "Value for TS_CRIT should not be larger than TS_MAX.");
62                  }
63              };
64  
65      /** Maximum task saturation, pertaining to maximum deterioration. */
66      public static final ParameterTypeDouble TS_MAX =
67              new ParameterTypeDouble("TSmax", "Maximum task saturation", 2.0, POSITIVEZERO)
68              {
69                  /** */
70                  private static final long serialVersionUID = 20180403L;
71  
72                  /** {@inheritDoc} */
73                  @Override
74                  public void check(final Double value, final Parameters params) throws ParameterException
75                  {
76                      Double tsCrit = params.getParameterOrNull(TS_CRIT);
77                      Throw.when(tsCrit != null && value < tsCrit, ParameterException.class,
78                              "Value for TS_MAX should not be smaller than TS_CRIT.");
79                  }
80              };
81  
82      /** Task saturation. */
83      public static final ParameterTypeDouble TS = new ParameterTypeDouble("TS", "Task saturation", 0.0, POSITIVEZERO);
84  
85      // Properties
86  
87      /** Tasks causing task demand. */
88      private final Set<Task> tasks;
89  
90      /** Behavioral adaptations depending on task saturation. */
91      private final Set<BehavioralAdaptation> behavioralAdapatations;
92  
93      /**
94       * Constructor with custom situational awareness.
95       * @param tasks Set&lt;Task&gt;; tasks
96       * @param behavioralAdapatations Set&lt;BehavioralAdaptation&gt;; behavioralAdapatations
97       */
98      public Fuller(final Set<Task> tasks, final Set<BehavioralAdaptation> behavioralAdapatations)
99      {
100         Throw.whenNull(tasks, "Tasks may not be null.");
101         Throw.whenNull(behavioralAdapatations, "Behavioral adaptations may not be null.");
102         this.tasks = tasks;
103         this.behavioralAdapatations = behavioralAdapatations;
104     }
105 
106     /**
107      * Adds a task.
108      * @param task Task; task to add
109      */
110     public void addTask(final Task task)
111     {
112         this.tasks.add(task);
113     }
114     
115     /**
116      * Removes a task.
117      * @param task Task; task to remove
118      */
119     public void removeTask(final Task task)
120     {
121         this.tasks.remove(task);
122     }
123     
124     /** {@inheritDoc} */
125     @Override
126     public void apply(final LanePerception perception) throws ParameterException, GTUException
127     {
128         LaneBasedGTU gtu = Try.assign(() -> perception.getGtu(), "Could not obtain GTU.");
129         Parameters parameters = gtu.getParameters();
130         double taskDemand = 0.0;
131         // a) the fundamental diagrams of task workload are defined in the tasks
132         // b) sum task demand
133         for (Task task : this.tasks)
134         {
135             taskDemand += task.demand(perception, gtu, parameters);
136         }
137         double taskSaturation = taskDemand / parameters.getParameter(TC);
138         if (taskSaturation < 0.0)
139         {
140             System.out.println("oh dear");
141         }
142         parameters.setParameter(TS, taskSaturation);
143         // c) behavioral adaptation
144         for (BehavioralAdaptation behavioralAdapatation : this.behavioralAdapatations)
145         {
146             behavioralAdapatation.adapt(parameters, taskSaturation);
147         }
148         // d) situational awareness can be implemented by one of the behavioral responses
149         // e) perception errors from situational awareness are included in the perception step
150         // f) reaction time from situational awareness are included in the perception step
151     }
152 
153     /**
154      * Interface for tasks, where each describes a fundamental relation between exogenous inputs causing a mental demand.
155      * <p>
156      * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
157      * <br>
158      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
159      * <p>
160      * @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 apr. 2018 <br>
161      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
162      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
163      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
164      */
165     @FunctionalInterface
166     public interface Task
167     {
168         /**
169          * Returns the demand of this task.
170          * @param perception LanePerception; perception
171          * @param gtu LaneBasedGTU; gtu
172          * @param parameters Parameters; parameters
173          * @return double; demand of this task
174          * @throws ParameterException if a parameter is missing or out of bounds
175          * @throws GTUException exceptions pertaining to the GTU
176          */
177         double demand(LanePerception perception, LaneBasedGTU gtu, Parameters parameters)
178                 throws ParameterException, GTUException;
179         
180         /**
181          * Class for constant demand.
182          */
183         class Constant implements Task
184         {
185             /** Task demand. */
186             private double taskDemand;
187             
188             /**
189              * Constructor.
190              * @param taskDemand double; task demand
191              */
192             public Constant(final double taskDemand)
193             {
194                 this.taskDemand = taskDemand;
195             }
196             
197             /** {@inheritDoc} */
198             @Override
199             public double demand(final LanePerception perception, final LaneBasedGTU gtu, final Parameters parameters)
200                     throws ParameterException, GTUException
201             {
202                 return this.taskDemand;
203             }
204         }
205     }
206 
207     /**
208      * Behavioral adaptation by changing parameter values.
209      * <p>
210      * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
211      * <br>
212      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
213      * <p>
214      * @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 apr. 2018 <br>
215      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
216      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
217      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
218      */
219     @FunctionalInterface
220     public interface BehavioralAdaptation
221     {
222         /**
223          * Adapt to task saturation by changing parameter values.
224          * @param parameters Parameters; parameters
225          * @param taskSaturation double; task saturation
226          * @throws ParameterException if a parameter is missing or out of bounds
227          */
228         void adapt(Parameters parameters, double taskSaturation) throws ParameterException;
229     }
230 
231 }