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
23
24
25
26
27
28
29
30
31 @FunctionalInterface
32 public interface AccelerationIncentive
33 {
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
55
56
57
58
59
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;
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 }