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