1 package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djunits.value.vdouble.scalar.Speed;
5 import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
6 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
7 import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
8 import org.opentrafficsim.core.gtu.perception.EgoPerception;
9 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
10 import org.opentrafficsim.road.gtu.lane.perception.InfrastructureLaneChangeInfo;
11 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
12 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
13 import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
14 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
15 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
16 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class IncentiveRoute implements MandatoryIncentive
32 {
33
34
35 @Override
36 public final Desire determineDesire(final BehavioralCharacteristics behavioralCharacteristics,
37 final LanePerception perception, final CarFollowingModel carFollowingModel, final Desire mandatoryDesire)
38 throws ParameterException, OperationalPlanException
39 {
40
41 double dLeft = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.LEFT);
42 double dCurr = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.CURRENT);
43 double dRigh = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.RIGHT);
44
45 dLeft = dLeft < dCurr ? dCurr : dLeft > dCurr ? -dLeft : 0;
46 dRigh = dRigh < dCurr ? dCurr : dRigh > dCurr ? -dRigh : 0;
47 return new Desire(dLeft, dRigh);
48 }
49
50
51
52
53
54
55
56
57
58
59 private double getDesireToLeave(final BehavioralCharacteristics bc, final LanePerception perception,
60 final RelativeLane lane) throws ParameterException, OperationalPlanException
61 {
62 Speed v = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
63 double dOut = Double.NEGATIVE_INFINITY;
64 if (perception.getPerceptionCategory(InfrastructurePerception.class).getCrossSection().contains(lane))
65 {
66 for (InfrastructureLaneChangeInfo info : perception.getPerceptionCategory(InfrastructurePerception.class)
67 .getInfrastructureLaneChangeInfo(lane))
68 {
69 double d = getDesireToLeave(bc, info.getRemainingDistance(), info.getRequiredNumberOfLaneChanges(), v);
70 dOut = d > dOut ? d : dOut;
71 }
72 }
73 return dOut;
74 }
75
76
77
78
79
80
81
82
83
84
85 private double getDesireToLeave(final BehavioralCharacteristics bc, final Length x, final int n, final Speed v)
86 throws ParameterException
87 {
88 double d1 = 1 - x.si / (n * bc.getParameter(ParameterTypes.LOOKAHEAD).si);
89 double d2 = 1 - (x.si / v.si) / (n * bc.getParameter(ParameterTypes.T0).si);
90 d1 = d2 > d1 ? d2 : d1;
91 return d1 < 0 ? 0 : d1;
92 }
93
94
95 @Override
96 public final String toString()
97 {
98 return "IncentiveRoute";
99 }
100
101 }