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.LongitudinalDirectionality;
12  import org.opentrafficsim.core.network.OTSLink;
13  import org.opentrafficsim.core.network.route.Route;
14  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
15  import org.opentrafficsim.road.gtu.lane.perception.FilteredIterable;
16  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
17  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
18  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayLaneBasedObject;
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.network.speed.SpeedLimitInfo;
22  
23  /**
24   * <p>
25   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
26   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
27   * <p>
28   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 27 jan. 2017 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
32   */
33  public interface AccelerationIncentive
34  {
35  
36      /**
37       * Determine acceleration.
38       * @param simplePlan SimpleOperationalPlan; simple plan to set the acceleration
39       * @param lane RelativeLane; lane on which to consider the acceleration
40       * @param mergeDistance Length; distance over which a lane change is impossible
41       * @param gtu LaneBasedGTU; gtu
42       * @param perception LanePerception; perception
43       * @param carFollowingModel CarFollowingModel; car-following model
44       * @param speed Speed; current speed
45       * @param params Parameters; parameters
46       * @param speedLimitInfo SpeedLimitInfo; speed limit info
47       * @throws OperationalPlanException in case of an error
48       * @throws ParameterException on missing parameter
49       * @throws GTUException when there is a problem with the state of the GTU when planning a path
50       */
51      void accelerate(SimpleOperationalPlan simplePlan, RelativeLane lane, Length mergeDistance, LaneBasedGTU gtu,
52              LanePerception perception, CarFollowingModel carFollowingModel, Speed speed, Parameters params,
53              SpeedLimitInfo speedLimitInfo) throws OperationalPlanException, ParameterException, GTUException;
54  
55      /**
56       * Returns an iterable with only those lane-based objects that are on the route, accounting for longitudinal direction of
57       * the GTU type.
58       * @param iterable Iterable&lt;T&gt;; iterable
59       * @param gtu LaneBasedGTU; gtu
60       * @param <T> type of lane-based object
61       * @return Iterable&lt;T&gt;; iterable with only those lane-based objects that are on the route
62       */
63      default <T extends HeadwayLaneBasedObject> Iterable<T> onRoute(final Iterable<T> iterable, final LaneBasedGTU gtu)
64      {
65          Route route = gtu.getStrategicalPlanner().getRoute();
66          return new FilteredIterable<>(iterable, new Predicate<T>()
67          {
68              /** {@inheritDoc} */
69              @Override
70              public boolean test(final T t)
71              {
72                  if (route == null)
73                  {
74                      return true; // when there is no route, we are always on it...
75                  }
76                  OTSLink link = t.getLane().getParentLink();
77                  if (route.contains(link.getStartNode()) && route.contains(link.getEndNode()))
78                  {
79                      LongitudinalDirectionality dir = link.getDirectionality(gtu.getGTUType());
80                      if (dir.isNone())
81                      {
82                          return false;
83                      }
84                      if (dir.isBoth())
85                      {
86                          return Math.abs(route.indexOf(link.getStartNode()) - route.indexOf(link.getEndNode())) == 1;
87                      }
88                      if (dir.isForward())
89                      {
90                          return route.indexOf(link.getEndNode()) - route.indexOf(link.getStartNode()) == 1;
91                      }
92                      return route.indexOf(link.getStartNode()) - route.indexOf(link.getEndNode()) == 1;
93                  }
94                  return false;
95              }
96          });
97      }
98  
99  }