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.ParameterTypeAcceleration;
8 import org.opentrafficsim.base.parameters.ParameterTypeSpeed;
9 import org.opentrafficsim.base.parameters.ParameterTypes;
10 import org.opentrafficsim.base.parameters.Parameters;
11 import org.opentrafficsim.core.gtu.GtuException;
12 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
13 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
14 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
15 import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
16 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
17 import org.opentrafficsim.road.gtu.lane.perception.categories.TrafficPerception;
18 import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
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.following.CarFollowingModel;
22 import org.opentrafficsim.road.gtu.lane.tactical.util.CarFollowingUtil;
23 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
24
25
26
27
28
29
30
31
32
33
34
35 public class AccelerationNoRightOvertake implements AccelerationIncentive
36 {
37
38
39 public static final ParameterTypeSpeed VCONG = ParameterTypes.VCONG;
40
41
42 public static final ParameterTypeAcceleration B0 = ParameterTypes.B0;
43
44
45 @Override
46 public 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
52 if (lane.isCurrent() && perception.getLaneStructure().exists(RelativeLane.LEFT))
53 {
54 Speed vCong = params.getParameter(VCONG);
55 if (perception.getPerceptionCategory(TrafficPerception.class).getSpeed(RelativeLane.CURRENT).si > vCong.si)
56 {
57 PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders =
58 perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(RelativeLane.LEFT);
59 if (!leaders.isEmpty())
60 {
61 HeadwayGtu leader = leaders.first();
62 Speed desiredSpeed = perception.getGtu().getDesiredSpeed();
63 if (desiredSpeed.si > leader.getSpeed().si)
64 {
65 Acceleration b0 = params.getParameter(B0);
66
67 Acceleration a =
68 CarFollowingUtil.followSingleLeader(carFollowingModel, params, speed, speedLimitInfo, leader);
69 simplePlan.minimizeAcceleration(a.si < -b0.si ? b0.neg() : a);
70 }
71 }
72 }
73 }
74 }
75
76 }