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