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.Speed;
5   import org.opentrafficsim.base.parameters.ParameterException;
6   import org.opentrafficsim.base.parameters.ParameterTypeAcceleration;
7   import org.opentrafficsim.base.parameters.ParameterTypeSpeed;
8   import org.opentrafficsim.base.parameters.ParameterTypes;
9   import org.opentrafficsim.base.parameters.Parameters;
10  import org.opentrafficsim.core.gtu.GTUException;
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.TrafficPerception;
17  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
18  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
19  import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
20  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
21  import org.opentrafficsim.road.gtu.lane.tactical.util.CarFollowingUtil;
22  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
23  
24  /**
25   * <p>
26   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
28   * <p>
29   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 mrt. 2018 <br>
30   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
31   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
32   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
33   */
34  public class AccelerationNoRightOvertake implements AccelerationIncentive
35  {
36  
37      /** Speed threshold below which traffic is considered congested. */
38      public static final ParameterTypeSpeed VCONG = ParameterTypes.VCONG;
39  
40      /** Maximum adjustment deceleration, e.g. when speed limit drops. */
41      public static final ParameterTypeAcceleration B0 = ParameterTypes.B0;
42  
43      /** {@inheritDoc} */
44      @Override
45      public void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final LaneBasedGTU gtu,
46              final LanePerception perception, final CarFollowingModel carFollowingModel, final Speed speed,
47              final Parameters params, final SpeedLimitInfo speedLimitInfo)
48              throws OperationalPlanException, ParameterException, GTUException
49      {
50          // TODO ignore incentive if we need to change lane for the route
51          if (lane.isCurrent() && perception.getLaneStructure().getExtendedCrossSection().contains(RelativeLane.LEFT))
52          {
53              Speed vCong = params.getParameter(VCONG);
54              if (perception.getPerceptionCategory(TrafficPerception.class).getSpeed(RelativeLane.CURRENT).si > vCong.si)
55              {
56                  PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders =
57                          perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(RelativeLane.LEFT);
58                  if (!leaders.isEmpty())
59                  {
60                      HeadwayGTU leader = leaders.first();
61                      Speed desiredSpeed = perception.getGtu().getDesiredSpeed();
62                      if (desiredSpeed.si > leader.getSpeed().si)
63                      {
64                          Acceleration b0 = params.getParameter(B0);
65                          // TODO only sensible if the left leader can change right; add this info to HeadwayGTU?
66                          Acceleration a =
67                                  CarFollowingUtil.followSingleLeader(carFollowingModel, params, speed, speedLimitInfo, leader);
68                          simplePlan.minimizeAcceleration(a.si < -b0.si ? b0.neg() : a);
69                      }
70                  }
71              }
72          }
73      }
74  
75  }