View Javadoc
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   * Makes a GTU follow leaders in the left lane, with limited deceleration.
27   * <p>
28   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
30   * </p>
31   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
33   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
34   */
35  public class AccelerationNoRightOvertake implements AccelerationIncentive
36  {
37  
38      /** Speed threshold below which traffic is considered congested. */
39      public static final ParameterTypeSpeed VCONG = ParameterTypes.VCONG;
40  
41      /** Maximum adjustment deceleration, e.g. when speed limit drops. */
42      public static final ParameterTypeAcceleration B0 = ParameterTypes.B0;
43  
44      /** {@inheritDoc} */
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          // TODO ignore incentive if we need to change lane for the route
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                          // TODO only sensible if the left leader can change right; add this info to HeadwayGtu?
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  }