1 package org.opentrafficsim.road.gtu.lane.perception.mental;
2
3 import org.djunits.value.vdouble.scalar.Duration;
4 import org.djunits.value.vdouble.scalar.Speed;
5 import org.opentrafficsim.base.parameters.ParameterException;
6 import org.opentrafficsim.base.parameters.ParameterTypes;
7 import org.opentrafficsim.base.parameters.Parameters;
8 import org.opentrafficsim.core.gtu.perception.EgoPerception;
9 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
10 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
11
12
13
14
15
16
17
18
19
20
21
22 public abstract class TaskHeadwayBased extends AbstractTask
23 {
24
25
26
27
28
29 public TaskHeadwayBased(final String id)
30 {
31 super(id);
32 }
33
34
35 private Speed speed;
36
37
38 @Override
39 public double calculateTaskDemand(final LanePerception perception, final LaneBasedGtu gtu, final Parameters parameters)
40 throws ParameterException
41 {
42 double a = gtu.getAcceleration().si;
43 double b = parameters.getParameter(ParameterTypes.B).si;
44 double tMin = parameters.getParameter(ParameterTypes.TMIN).si;
45 double hMin = a < -b ? (1.0 - (a + b) / (8.0 - b)) * tMin : tMin;
46 EgoPerception<?, ?> ego = perception.getPerceptionCategoryOrNull(EgoPerception.class);
47 this.speed = ego.getSpeed();
48 Duration h = getHeadway(perception, gtu, parameters);
49 if (h == null)
50 {
51 return 0.0;
52 }
53 return h.si <= hMin ? 1.0 : (h.si > 3.0 ? 0.5 : 1.0 - (1.0 - 0.5) * (h.si - hMin) / (3.0 - hMin));
54 }
55
56
57
58
59
60 protected Speed getSpeed()
61 {
62 return this.speed;
63 }
64
65
66
67
68
69
70
71
72
73 protected abstract Duration getHeadway(LanePerception perception, LaneBasedGtu gtu, Parameters parameters)
74 throws ParameterException;
75
76 }