View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import java.util.function.Predicate;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djunits.value.vdouble.scalar.Speed;
7   import org.opentrafficsim.base.parameters.ParameterException;
8   import org.opentrafficsim.base.parameters.Parameters;
9   import org.opentrafficsim.core.gtu.GtuException;
10  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
11  import org.opentrafficsim.core.network.Link;
12  import org.opentrafficsim.core.network.route.Route;
13  import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
14  import org.opentrafficsim.road.gtu.lane.perception.FilteredIterable;
15  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
16  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
17  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayLaneBasedObject;
18  import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
19  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
20  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
21  
22  /**
23   * <p>
24   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * </p>
27   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
28   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
29   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
30   */
31  public interface AccelerationIncentive
32  {
33  
34      /**
35       * Determine acceleration.
36       * @param simplePlan SimpleOperationalPlan; simple plan to set the acceleration
37       * @param lane RelativeLane; lane on which to consider the acceleration
38       * @param mergeDistance Length; distance over which a lane change is impossible
39       * @param gtu LaneBasedGtu; gtu
40       * @param perception LanePerception; perception
41       * @param carFollowingModel CarFollowingModel; car-following model
42       * @param speed Speed; current speed
43       * @param params Parameters; parameters
44       * @param speedLimitInfo SpeedLimitInfo; speed limit info
45       * @throws OperationalPlanException in case of an error
46       * @throws ParameterException on missing parameter
47       * @throws GtuException when there is a problem with the state of the GTU when planning a path
48       */
49      void accelerate(SimpleOperationalPlan simplePlan, RelativeLane lane, Length mergeDistance, LaneBasedGtu gtu,
50              LanePerception perception, CarFollowingModel carFollowingModel, Speed speed, Parameters params,
51              SpeedLimitInfo speedLimitInfo) throws OperationalPlanException, ParameterException, GtuException;
52  
53      /**
54       * Returns an iterable with only those lane-based objects that are on the route, accounting for longitudinal direction of
55       * the GTU type.
56       * @param iterable Iterable&lt;T&gt;; iterable
57       * @param gtu LaneBasedGtu; gtu
58       * @param <T> type of lane-based object
59       * @return Iterable&lt;T&gt;; iterable with only those lane-based objects that are on the route
60       */
61      default <T extends HeadwayLaneBasedObject> Iterable<T> onRoute(final Iterable<T> iterable, final LaneBasedGtu gtu)
62      {
63          Route route = gtu.getStrategicalPlanner().getRoute();
64          return new FilteredIterable<>(iterable, new Predicate<T>()
65          {
66              /** {@inheritDoc} */
67              @Override
68              public boolean test(final T t)
69              {
70                  if (route == null)
71                  {
72                      return true; // when there is no route, we are always on it...
73                  }
74                  Link link = t.getLane().getLink();
75                  if (route.contains(link.getStartNode()) && route.contains(link.getEndNode()))
76                  {
77                      return route.indexOf(link.getEndNode()) - route.indexOf(link.getStartNode()) == 1;
78                  }
79                  return false;
80              }
81          });
82      }
83  
84  }