1 package org.opentrafficsim.road.gtu.lane.tactical.util.lmrs;
2
3 import org.djunits.unit.AccelerationUnit;
4 import org.djunits.value.vdouble.scalar.Acceleration;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.base.parameters.ParameterException;
7 import org.opentrafficsim.base.parameters.ParameterTypes;
8 import org.opentrafficsim.base.parameters.Parameters;
9 import org.opentrafficsim.core.gtu.perception.EgoPerception;
10 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
11 import org.opentrafficsim.core.network.LateralDirectionality;
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.PerceptionCollectable;
15 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
16 import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
17 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGtu;
18 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
19 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
20
21
22
23
24
25
26
27
28
29
30
31 public interface Cooperation extends LmrsParameters
32 {
33
34
35 Cooperation PASSIVE = new Cooperation()
36 {
37
38 @Override
39 public Acceleration cooperate(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
40 final CarFollowingModel cfm, final LateralDirectionality lat, final Desire ownDesire)
41 throws ParameterException, OperationalPlanException
42 {
43 if (!perception.getLaneStructure().exists(lat.isRight() ? RelativeLane.RIGHT : RelativeLane.LEFT))
44 {
45 return new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
46 }
47 Acceleration b = params.getParameter(ParameterTypes.B);
48 Acceleration a = new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
49 double dCoop = params.getParameter(DCOOP);
50 Speed ownSpeed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
51 RelativeLane relativeLane = new RelativeLane(lat, 1);
52 for (HeadwayGtu leader : perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(relativeLane))
53 {
54 Parameters params2 = leader.getParameters();
55 double desire = lat.equals(LateralDirectionality.LEFT) ? params2.getParameter(DRIGHT)
56 : lat.equals(LateralDirectionality.RIGHT) ? params2.getParameter(DLEFT) : 0;
57 if (desire >= dCoop && (leader.getSpeed().gt0() || leader.getDistance().gt0()))
58 {
59 Acceleration aSingle = LmrsUtil.singleAcceleration(leader.getDistance(), ownSpeed, leader.getSpeed(),
60 desire, params, sli, cfm);
61 a = Acceleration.min(a, aSingle);
62 }
63 }
64 return Acceleration.max(a, b.neg());
65 }
66
67
68 @Override
69 public String toString()
70 {
71 return "PASSIVE";
72 }
73 };
74
75
76 Cooperation PASSIVE_MOVING = new Cooperation()
77 {
78
79 @Override
80 public Acceleration cooperate(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
81 final CarFollowingModel cfm, final LateralDirectionality lat, final Desire ownDesire)
82 throws ParameterException, OperationalPlanException
83 {
84 if (!perception.getLaneStructure().exists(lat.isRight() ? RelativeLane.RIGHT : RelativeLane.LEFT))
85 {
86 return new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
87 }
88 Acceleration bCrit = params.getParameter(ParameterTypes.BCRIT);
89 Acceleration a = new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
90 double dCoop = params.getParameter(DCOOP);
91 Speed ownSpeed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
92 RelativeLane relativeLane = new RelativeLane(lat, 1);
93 NeighborsPerception neighbours = perception.getPerceptionCategory(NeighborsPerception.class);
94 PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders = neighbours.getLeaders(RelativeLane.CURRENT);
95 Speed thresholdSpeed = Speed.instantiateSI(6.86);
96 boolean leaderInCongestion = leaders.isEmpty() ? false : leaders.first().getSpeed().lt(thresholdSpeed);
97 for (HeadwayGtu leader : neighbours.getLeaders(relativeLane))
98 {
99 Parameters params2 = leader.getParameters();
100 double desire = lat.equals(LateralDirectionality.LEFT) ? params2.getParameter(DRIGHT)
101 : lat.equals(LateralDirectionality.RIGHT) ? params2.getParameter(DLEFT) : 0;
102
103
104 if (desire >= dCoop && (leader.getSpeed().gt0() || leader.getDistance().gt0())
105 && (leader.getSpeed().ge(thresholdSpeed) || leaderInCongestion))
106 {
107 Acceleration aSingle = LmrsUtil.singleAcceleration(leader.getDistance(), ownSpeed, leader.getSpeed(),
108 desire, params, sli, cfm);
109 a = Acceleration.min(a, aSingle);
110 }
111 }
112 return Acceleration.max(a, bCrit.neg());
113 }
114
115
116 @Override
117 public String toString()
118 {
119 return "PASSIVE_MOVING";
120 }
121 };
122
123
124 Cooperation ACTIVE = new Cooperation()
125 {
126
127 @Override
128 public Acceleration cooperate(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
129 final CarFollowingModel cfm, final LateralDirectionality lat, final Desire ownDesire)
130 throws ParameterException, OperationalPlanException
131 {
132 if (!perception.getLaneStructure().exists(lat.isRight() ? RelativeLane.RIGHT : RelativeLane.LEFT))
133 {
134 return new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
135 }
136 Acceleration a = new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
137 double dCoop = params.getParameter(DCOOP);
138 Speed ownSpeed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
139 RelativeLane relativeLane = new RelativeLane(lat, 1);
140 for (HeadwayGtu leader : perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(relativeLane))
141 {
142 Parameters params2 = leader.getParameters();
143 double desire = lat.equals(LateralDirectionality.LEFT) ? params2.getParameter(DRIGHT)
144 : lat.equals(LateralDirectionality.RIGHT) ? params2.getParameter(DLEFT) : 0;
145 if (desire >= dCoop && leader.getDistance().gt0()
146 && leader.getAcceleration().gt(params.getParameter(ParameterTypes.BCRIT).neg()))
147 {
148 Acceleration aSingle = LmrsUtil.singleAcceleration(leader.getDistance(), ownSpeed, leader.getSpeed(),
149 desire, params, sli, cfm);
150 a = Acceleration.min(a, Synchronization.gentleUrgency(aSingle, desire, params));
151 }
152 }
153 return a;
154 }
155
156
157 @Override
158 public String toString()
159 {
160 return "ACTIVE";
161 }
162 };
163
164
165
166
167
168
169
170
171
172
173
174
175
176 Acceleration cooperate(LanePerception perception, Parameters params, SpeedLimitInfo sli, CarFollowingModel cfm,
177 LateralDirectionality lat, Desire ownDesire) throws ParameterException, OperationalPlanException;
178 }