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.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 Acceleration b = params.getParameter(ParameterTypes.B);
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 && leader.getAcceleration().gt(params.getParameter(ParameterTypes.BCRIT).neg()))
96 {
97 Acceleration aSingle = LmrsUtil.singleAcceleration(leader.getDistance(), ownSpeed, leader.getSpeed(),
98 desire, params, sli, cfm);
99 a = Acceleration.min(a, aSingle);
100 }
101 }
102 return Acceleration.max(a, b.neg());
103 }
104 };
105
106
107 Cooperation ACTIVE = new Cooperation()
108 {
109 @Override
110 public Acceleration cooperate(final LanePerception perception, final Parameters params, final SpeedLimitInfo sli,
111 final CarFollowingModel cfm, final LateralDirectionality lat, final Desire ownDesire)
112 throws ParameterException, OperationalPlanException
113 {
114
115 if ((lat.isLeft() && !perception.getLaneStructure().getExtendedCrossSection().contains(RelativeLane.LEFT))
116 || (lat.isRight() && !perception.getLaneStructure().getExtendedCrossSection().contains(RelativeLane.RIGHT)))
117 {
118 return new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
119 }
120 Acceleration a = new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
121 double dCoop = params.getParameter(DCOOP);
122 Speed ownSpeed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
123 RelativeLane relativeLane = new RelativeLane(lat, 1);
124 for (HeadwayGTU leader : Synchronization.removeAllUpstreamOfConflicts(Synchronization.removeAllUpstreamOfConflicts(
125 perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(relativeLane), perception,
126 relativeLane), perception, RelativeLane.CURRENT))
127 {
128 Parameters params2 = leader.getParameters();
129 double desire = lat.equals(LateralDirectionality.LEFT) ? params2.getParameter(DRIGHT)
130 : lat.equals(LateralDirectionality.RIGHT) ? params2.getParameter(DLEFT) : 0;
131 if (desire >= dCoop && leader.getDistance().gt0()
132 && leader.getAcceleration().gt(params.getParameter(ParameterTypes.BCRIT).neg()))
133 {
134 Acceleration aSingle = LmrsUtil.singleAcceleration(leader.getDistance(), ownSpeed, leader.getSpeed(),
135 desire, params, sli, cfm);
136 a = Acceleration.min(a, Synchronization.gentleUrgency(aSingle, desire, params));
137 }
138 }
139 return a;
140 }
141 };
142
143
144
145
146
147
148
149
150
151
152
153
154
155 Acceleration cooperate(LanePerception perception, Parameters params, SpeedLimitInfo sli, CarFollowingModel cfm,
156 LateralDirectionality lat, Desire ownDesire) throws ParameterException, OperationalPlanException;
157 }