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