View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import java.util.Optional;
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.object.PerceivedLaneBasedObject;
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   * Interface for acceleration incentives.
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://github.com/peter-knoppers">Peter Knoppers</a>
29   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
30   */
31  @FunctionalInterface
32  public interface AccelerationIncentive
33  {
34  
35      /**
36       * Determine acceleration.
37       * @param simplePlan simple plan to set the acceleration
38       * @param lane lane on which to consider the acceleration
39       * @param mergeDistance distance over which a lane change is impossible
40       * @param gtu gtu
41       * @param perception perception
42       * @param carFollowingModel car-following model
43       * @param speed current speed
44       * @param params parameters
45       * @param speedLimitInfo speed limit info
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 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
57       * @param gtu gtu
58       * @param <T> type of lane-based object
59       * @return iterable with only those lane-based objects that are on the route
60       */
61      default <T extends PerceivedLaneBasedObject> Iterable<T> onRoute(final Iterable<T> iterable, final LaneBasedGtu gtu)
62      {
63          Optional<Route> route = gtu.getStrategicalPlanner().getRoute();
64          return new FilteredIterable<>(iterable, (t) ->
65          {
66              if (route.isEmpty())
67              {
68                  return true; // when there is no route, we are always on it...
69              }
70              Link link = t.getLane().getLink();
71              if (route.get().contains(link.getStartNode()) && route.get().contains(link.getEndNode()))
72              {
73                  return route.get().indexOf(link.getEndNode()) - route.get().indexOf(link.getStartNode()) == 1;
74              }
75              return false;
76          });
77      }
78  
79  }