1 package org.opentrafficsim.road.gtu.lane.perception.mental.ar;
2
3 import java.util.Set;
4
5 import org.djutils.exceptions.Throw;
6 import org.opentrafficsim.base.parameters.ParameterException;
7 import org.opentrafficsim.base.parameters.ParameterTypeDouble;
8 import org.opentrafficsim.base.parameters.Parameters;
9 import org.opentrafficsim.base.parameters.constraint.DualBound;
10 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
11 import org.opentrafficsim.road.gtu.lane.perception.mental.BehavioralAdaptation;
12 import org.opentrafficsim.road.gtu.lane.perception.mental.SumFuller;
13
14
15
16
17
18
19
20
21
22
23
24 public class ArFuller extends SumFuller<ArTask>
25 {
26
27
28 public static final ParameterTypeDouble ALPHA = new ParameterTypeDouble("alpha",
29 "Fraction of primary task that can be reduced by anticipation reliance.", 0.8, DualBound.UNITINTERVAL);
30
31
32 public static final ParameterTypeDouble BETA = new ParameterTypeDouble("beta",
33 "Fraction of auxiliary tasks that can be reduced by anticipation reliance.", 0.6, DualBound.UNITINTERVAL);
34
35
36 private final String primaryTaskId;
37
38
39
40
41
42
43
44 public ArFuller(final Set<ArTask> tasks, final Set<BehavioralAdaptation> behavioralAdapatations, final String primaryTaskId)
45 {
46 super(tasks, behavioralAdapatations);
47 this.primaryTaskId = primaryTaskId;
48 }
49
50 @Override
51 protected double getTotalTaskDemand(final LanePerception perception) throws ParameterException
52 {
53 manage(perception);
54 return getTasks().stream().mapToDouble((t) -> t.getTaskDemand() - t.getAnticipationReliance()).sum();
55 }
56
57
58
59
60
61
62
63 protected void manage(final LanePerception perception) throws ParameterException
64 {
65 ArTask primary = null;
66 for (ArTask task : getTasks())
67 {
68 if (task.getId().equals(this.primaryTaskId))
69 {
70 primary = task;
71 break;
72 }
73 }
74 Throw.whenNull(primary, "There is no primary task with id '%s'.", this.primaryTaskId);
75 double primaryTaskDemand = primary.getTaskDemand(perception);
76
77 Parameters parameters = perception.getGtu().getParameters();
78 double a = parameters.getParameter(ALPHA);
79 double b = parameters.getParameter(BETA);
80 primary.setAnticipationReliance(a * primaryTaskDemand * (1.0 - primaryTaskDemand));
81 for (ArTask auxiliary : getTasks())
82 {
83 if (!auxiliary.getId().equals(this.primaryTaskId))
84 {
85 double auxiliaryTaskLoad = auxiliary.getTaskDemand(perception);
86
87 auxiliary.setAnticipationReliance(b * auxiliaryTaskLoad * primaryTaskDemand);
88 }
89 }
90 }
91
92 @Override
93 public String toString()
94 {
95 return "ArFuller [tasks=" + getTasks() + "]";
96 }
97
98 }