1 package org.opentrafficsim.road.gtu.colorer;
2
3 import java.awt.Color;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.opentrafficsim.core.animation.ColorInterpolator;
8 import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
9 import org.opentrafficsim.core.gtu.GTU;
10 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
11 import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller;
12 import org.opentrafficsim.road.gtu.lane.perception.mental.Mental;
13 import org.opentrafficsim.road.gtu.lane.perception.mental.Task;
14
15
16
17
18
19
20
21
22
23
24
25
26 public class TaskColorer implements GTUColorer
27 {
28
29
30 static final Color HIGH = Color.RED;
31
32
33 static final Color MID = Color.YELLOW;
34
35
36 static final Color LOW = Color.GREEN;
37
38
39 static final Color AR = Color.WHITE;
40
41
42 static final Color NA = Color.BLUE;
43
44
45 static final List<LegendEntry> LEGEND;
46
47 static
48 {
49 LEGEND = new ArrayList<>();
50 LEGEND.add(new LegendEntry(LOW, "low", "low task load"));
51 LEGEND.add(new LegendEntry(MID, "medium", "medium task load"));
52 LEGEND.add(new LegendEntry(HIGH, "high", "high task load"));
53 LEGEND.add(new LegendEntry(AR, "fully anticipation reliant", "task load compensated with anticipation reliance"));
54 LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
55 }
56
57
58 final String id;
59
60
61
62
63
64 public TaskColorer(final String id)
65 {
66 this.id = id;
67 }
68
69
70 @Override
71 public Color getColor(final GTU gtu)
72 {
73 if (gtu.getTacticalPlanner().getPerception() instanceof LanePerception)
74 {
75 Mental mental = ((LanePerception) gtu.getTacticalPlanner().getPerception()).getMental();
76 if (mental != null && mental instanceof Fuller)
77 {
78 for (Task task : ((Fuller) mental).getTasks())
79 {
80 if (task.getId().equals(this.id))
81 {
82 double taskDemand = task.getTaskDemand();
83 if (taskDemand == 0.0)
84 {
85 return LOW;
86 }
87 double anticipationReliance = task.getAnticipationReliance();
88 Color base = taskDemand < 0.5 ? ColorInterpolator.interpolateColor(LOW, MID, taskDemand / 0.5)
89 : ColorInterpolator.interpolateColor(MID, HIGH, (taskDemand - 0.5) / 0.5);
90 return ColorInterpolator.interpolateColor(base, AR, anticipationReliance / taskDemand);
91 }
92 }
93 }
94 }
95 return NA;
96 }
97
98
99 @Override
100 public List<LegendEntry> getLegend()
101 {
102 return LEGEND;
103 }
104
105
106 @Override
107 public String toString()
108 {
109 return "Task load (" + this.id + ")";
110 }
111
112 }