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