1 package org.opentrafficsim.road.gtu.lane.perception.mental;
2
3 import java.util.Iterator;
4 import java.util.LinkedHashMap;
5 import java.util.Map;
6 import java.util.SortedSet;
7
8 import org.djunits.value.vdouble.scalar.Length;
9 import org.opentrafficsim.base.parameters.ParameterException;
10 import org.opentrafficsim.base.parameters.Parameters;
11 import org.opentrafficsim.core.gtu.GTUException;
12 import org.opentrafficsim.core.gtu.RelativePosition;
13 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
14 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
15 import org.opentrafficsim.road.gtu.lane.perception.LaneStructure.Entry;
16 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
17 import org.opentrafficsim.road.network.lane.object.Distraction;
18
19
20
21
22
23
24
25
26
27
28
29
30 public class TaskRoadSideDistraction extends AbstractTask
31 {
32
33
34 private Map<Distraction, Double> odos = new LinkedHashMap<>();
35
36
37 public TaskRoadSideDistraction()
38 {
39 super("road-side distraction");
40 }
41
42
43 @Override
44 public double calculateTaskDemand(final LanePerception perception, final LaneBasedGTU gtu, final Parameters parameters)
45 throws ParameterException, GTUException
46 {
47 Map<RelativeLane, SortedSet<Entry<Distraction>>> map =
48 perception.getLaneStructure().getDownstreamObjects(Distraction.class, gtu, RelativePosition.FRONT);
49
50 double odo = gtu.getOdometer().si;
51 for (RelativeLane lane : map.keySet())
52 {
53 for (Entry<Distraction> entry : map.get(lane))
54 {
55 this.odos.put(entry.getLaneBasedObject(), odo + entry.getDistance().si);
56 }
57 }
58
59 Iterator<Distraction> it = this.odos.keySet().iterator();
60 double demand = 0.0;
61 while (it.hasNext())
62 {
63 Distraction next = it.next();
64 Double distraction = next.getDistraction(Length.instantiateSI(odo - this.odos.get(next)));
65 if (distraction == null)
66 {
67 it.remove();
68 }
69 else
70 {
71 demand += distraction;
72 }
73 }
74 return demand;
75 }
76
77 }