1 package org.opentrafficsim.road.gtu.lane.perception.mental;
2
3 import java.util.HashMap;
4 import java.util.Iterator;
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.gtu.lane.perception.mental.Fuller.Task;
18 import org.opentrafficsim.road.network.lane.object.Distraction;
19
20
21
22
23
24
25
26
27
28
29
30
31 public class TaskRoadSideDistraction implements Task
32 {
33
34
35 private Map<Distraction, Double> odos = new HashMap<>();
36
37
38 @Override
39 public double demand(final LanePerception perception, final LaneBasedGTU gtu, final Parameters parameters)
40 throws ParameterException, GTUException
41 {
42 Map<RelativeLane, SortedSet<Entry<Distraction>>> map =
43 perception.getLaneStructure().getDownstreamObjects(Distraction.class, gtu, RelativePosition.FRONT);
44
45 double odo = gtu.getOdometer().si;
46 for (RelativeLane lane : map.keySet())
47 {
48 for (Entry<Distraction> entry : map.get(lane))
49 {
50 this.odos.put(entry.getLaneBasedObject(), odo + entry.getDistance().si);
51 }
52 }
53
54 Iterator<Distraction> it = this.odos.keySet().iterator();
55 double demand = 0.0;
56 while (it.hasNext())
57 {
58 Distraction next = it.next();
59 Double distraction = next.getDistraction(Length.createSI(odo - this.odos.get(next)));
60 if (distraction == null)
61 {
62 it.remove();
63 }
64 else
65 {
66 demand += distraction;
67 }
68 }
69 return demand;
70 }
71
72 }