View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.djunits.value.vdouble.scalar.Length;
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.opentrafficsim.base.parameters.ParameterException;
7   import org.opentrafficsim.base.parameters.Parameters;
8   import org.opentrafficsim.core.gtu.GtuException;
9   import org.opentrafficsim.core.gtu.perception.EgoPerception;
10  import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
11  import org.opentrafficsim.road.gtu.lane.perception.FilteredIterable;
12  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
13  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
14  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
15  import org.opentrafficsim.road.gtu.lane.perception.categories.IntersectionPerception;
16  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
17  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayConflict;
18  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGtu;
19  import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
20  import org.opentrafficsim.road.gtu.lane.tactical.Blockable;
21  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
22  import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil;
23  import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil.ConflictPlans;
24  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
25  
26  /**
27   * <p>
28   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
30   * </p>
31   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
33   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
34   */
35  
36  public class AccelerationConflicts implements AccelerationIncentive, Blockable
37  {
38  
39      /** Set of yield plans at conflicts with priority. Remembering for static model. */
40      // @docs/06-behavior/tactical-planner/#modular-utilities
41      private final ConflictPlans yieldPlans = new ConflictPlans();
42  
43      @Override
44      public final void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final Length mergeDistance,
45              final LaneBasedGtu gtu, final LanePerception perception, final CarFollowingModel carFollowingModel,
46              final Speed speed, final Parameters params, final SpeedLimitInfo speedLimitInfo)
47              throws ParameterException, GtuException
48      {
49          EgoPerception<?, ?> ego = perception.getPerceptionCategory(EgoPerception.class);
50          Acceleration acceleration = ego.getAcceleration();
51          Length length = ego.getLength();
52          Length width = ego.getWidth();
53          Iterable<HeadwayConflict> conflicts = perception.getPerceptionCategory(IntersectionPerception.class).getConflicts(lane);
54          PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders =
55                  perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(lane);
56          if (!lane.isCurrent())
57          {
58              conflicts = new FilteredIterable<>(conflicts, (conflict) ->
59              {
60                  return conflict.getDistance().gt(mergeDistance);
61              });
62          }
63          conflicts = onRoute(conflicts, gtu);
64          Acceleration a = ConflictUtil.approachConflicts(params, conflicts, leaders, carFollowingModel, length, width, speed,
65                  acceleration, speedLimitInfo, this.yieldPlans, gtu, lane);
66          simplePlan.minimizeAcceleration(a);
67          if (this.yieldPlans.getIndicatorIntent().isLeft())
68          {
69              simplePlan.setIndicatorIntentLeft(this.yieldPlans.getIndicatorObjectDistance());
70          }
71          else if (this.yieldPlans.getIndicatorIntent().isRight())
72          {
73              simplePlan.setIndicatorIntentRight(this.yieldPlans.getIndicatorObjectDistance());
74          }
75      }
76  
77      @Override
78      public boolean isBlocking()
79      {
80          return this.yieldPlans.isBlocking();
81      }
82  
83      @Override
84      public final String toString()
85      {
86          return "AccelerationConflicts";
87      }
88  
89  }