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.Parameters;
8 import org.opentrafficsim.core.gtu.GtuException;
9 import org.opentrafficsim.core.gtu.perception.EgoPerception;
10 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
11 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
12 import org.opentrafficsim.road.gtu.lane.perception.FilteredIterable;
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.ConflictUtil;
24 import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil.ConflictPlans;
25 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
26
27
28
29
30
31
32
33
34
35
36
37 public class AccelerationConflicts implements AccelerationIncentive, Blockable
38 {
39
40
41
42 private final ConflictPlans yieldPlans = new ConflictPlans();
43
44
45 @Override
46 public final void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final Length mergeDistance,
47 final LaneBasedGtu gtu, final LanePerception perception, final CarFollowingModel carFollowingModel,
48 final Speed speed, final Parameters params, final SpeedLimitInfo speedLimitInfo)
49 throws OperationalPlanException, ParameterException, GtuException
50 {
51 EgoPerception<?, ?> ego = perception.getPerceptionCategory(EgoPerception.class);
52 Acceleration acceleration = ego.getAcceleration();
53 Length length = ego.getLength();
54 Length width = ego.getWidth();
55 Iterable<HeadwayConflict> conflicts = perception.getPerceptionCategory(IntersectionPerception.class).getConflicts(lane);
56 PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders =
57 perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(lane);
58 if (!lane.isCurrent())
59 {
60 conflicts = new FilteredIterable<>(conflicts, (conflict) ->
61 {
62 return conflict.getDistance().gt(mergeDistance);
63 });
64 }
65 conflicts = onRoute(conflicts, gtu);
66 Acceleration a = ConflictUtil.approachConflicts(params, conflicts, leaders, carFollowingModel, length, width, speed,
67 acceleration, speedLimitInfo, this.yieldPlans, gtu, lane);
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
79
80 @Override
81 public boolean isBlocking()
82 {
83 return this.yieldPlans.isBlocking();
84 }
85
86
87 @Override
88 public final String toString()
89 {
90 return "AccelerationConflicts";
91 }
92
93 }