1 package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Length;
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.GTUException;
10 import org.opentrafficsim.core.gtu.perception.EgoPerception;
11 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
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.IntersectionPerception;
17 import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
18 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayConflict;
19 import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
20 import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
21 import org.opentrafficsim.road.gtu.lane.tactical.Blockable;
22 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
23 import org.opentrafficsim.road.gtu.lane.tactical.util.CarFollowingUtil;
24 import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil;
25 import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil.ConflictPlans;
26 import org.opentrafficsim.road.network.lane.conflict.Conflict;
27 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
28
29
30
31
32
33
34
35
36
37
38
39
40 public class AccelerationConflicts implements AccelerationIncentive, Blockable
41 {
42
43
44 private final ConflictPlans yieldPlans = new ConflictPlans();
45
46
47 @Override
48 public final void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final LaneBasedGTU gtu,
49 final LanePerception perception, final CarFollowingModel carFollowingModel, final Speed speed,
50 final Parameters params, final SpeedLimitInfo speedLimitInfo)
51 throws OperationalPlanException, ParameterException, GTUException
52 {
53
54 EgoPerception ego = perception.getPerceptionCategory(EgoPerception.class);
55 Acceleration acceleration = ego.getAcceleration();
56 Length length = ego.getLength();
57 Length width = ego.getWidth();
58 PerceptionCollectable<HeadwayConflict, Conflict> conflicts =
59 perception.getPerceptionCategory(IntersectionPerception.class).getConflicts(lane);
60 PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders =
61 perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(lane);
62
63 Acceleration a;
64 if (lane.isCurrent())
65 {
66 a = ConflictUtil.approachConflicts(params, conflicts, leaders, carFollowingModel, length, width, speed,
67 acceleration, speedLimitInfo, this.yieldPlans, gtu);
68 simplePlan.minimizeAcceleration(a);
69 if (this.yieldPlans.getIndicatorIntent().isLeft())
70 {
71 simplePlan.setIndicatorIntentLeft(this.yieldPlans.getIndicatorObjectDistance());
72 }
73 else if (this.yieldPlans.getIndicatorIntent().isRight())
74 {
75 simplePlan.setIndicatorIntentRight(this.yieldPlans.getIndicatorObjectDistance());
76 }
77 }
78 else if (!conflicts.isEmpty() && conflicts.first().getDistance().gt0())
79 {
80
81 a = CarFollowingUtil.followSingleLeader(carFollowingModel, params, speed, speedLimitInfo,
82 conflicts.first().getDistance(), Speed.ZERO);
83
84 a = Acceleration.max(a, params.getParameter(ParameterTypes.BCRIT).neg());
85 simplePlan.minimizeAcceleration(a);
86 }
87 }
88
89
90 @Override
91 public boolean isBlocking()
92 {
93 return this.yieldPlans.isBlocking();
94 }
95
96
97 @Override
98 public final String toString()
99 {
100 return "AccelerationConflicts";
101 }
102
103 }