View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djunits.value.vdouble.scalar.Speed;
5   import org.opentrafficsim.base.parameters.ParameterException;
6   import org.opentrafficsim.base.parameters.Parameters;
7   import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
9   import org.opentrafficsim.road.gtu.lane.perception.FilteredIterable;
10  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
11  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
12  import org.opentrafficsim.road.gtu.lane.perception.categories.IntersectionPerception;
13  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayTrafficLight;
14  import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
15  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
16  import org.opentrafficsim.road.gtu.lane.tactical.util.TrafficLightUtil;
17  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
18  
19  /**
20   * <p>
21   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
23   * </p>
24   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
26   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
27   */
28  public class AccelerationTrafficLights implements AccelerationIncentive
29  {
30  
31      /** {@inheritDoc} */
32      @Override
33      public final void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final Length mergeDistance,
34              final LaneBasedGtu gtu, final LanePerception perception, final CarFollowingModel carFollowingModel,
35              final Speed speed, final Parameters params, final SpeedLimitInfo speedLimitInfo)
36              throws ParameterException, OperationalPlanException
37      {
38          Iterable<HeadwayTrafficLight> it =
39                  perception.getPerceptionCategory(IntersectionPerception.class).getTrafficLights(lane);
40          if (!lane.isCurrent() && mergeDistance.gt0())
41          {
42              it = new FilteredIterable<>(it, (
43                      trafficLight
44              ) ->
45              { return trafficLight.getDistance().gt(mergeDistance); });
46          }
47          it = onRoute(it, gtu);
48          simplePlan.minimizeAcceleration(
49                  TrafficLightUtil.respondToTrafficLights(params, it, carFollowingModel, speed, speedLimitInfo));
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public final String toString()
55      {
56          return "AccelerationTrafficLights";
57      }
58  
59  }