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.object.PerceivedConflict;
18  import org.opentrafficsim.road.gtu.lane.perception.object.PerceivedGtu;
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   * Conflicts acceleration incentive.
28   * <p>
29   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
31   * </p>
32   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
33   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
34   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
35   */
36  
37  public class AccelerationConflicts implements AccelerationIncentive, Blockable
38  {
39  
40      /** Set of yield plans at conflicts with priority. Remembering for static model. */
41      // @docs/06-behavior/tactical-planner/#modular-utilities
42      private final ConflictPlans conflictPlans = new ConflictPlans();
43  
44      /**
45       * Constructor.
46       */
47      public AccelerationConflicts()
48      {
49          //
50      }
51  
52      @Override
53      public final void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final Length mergeDistance,
54              final LaneBasedGtu gtu, final LanePerception perception, final CarFollowingModel carFollowingModel,
55              final Speed speed, final Parameters params, final SpeedLimitInfo speedLimitInfo)
56              throws ParameterException, GtuException
57      {
58          EgoPerception<?, ?> ego = perception.getPerceptionCategory(EgoPerception.class);
59          Acceleration acceleration = ego.getAcceleration();
60          Length length = ego.getLength();
61          Length width = ego.getWidth();
62          Iterable<PerceivedConflict> conflicts =
63                  perception.getPerceptionCategory(IntersectionPerception.class).getConflicts(lane);
64          PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders =
65                  perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(lane);
66          if (!lane.isCurrent())
67          {
68              conflicts = new FilteredIterable<>(conflicts, (conflict) ->
69              {
70                  return conflict.getDistance().gt(mergeDistance);
71              });
72          }
73          conflicts = onRoute(conflicts, gtu);
74          Acceleration a = ConflictUtil.approachConflicts(params, conflicts, leaders, carFollowingModel, length, width, speed,
75                  acceleration, speedLimitInfo, this.conflictPlans, gtu, lane);
76          simplePlan.minimizeAcceleration(a);
77          if (this.conflictPlans.getIndicatorIntent().isLeft())
78          {
79              simplePlan.setIndicatorIntentLeft(this.conflictPlans.getIndicatorObjectDistance());
80          }
81          else if (this.conflictPlans.getIndicatorIntent().isRight())
82          {
83              simplePlan.setIndicatorIntentRight(this.conflictPlans.getIndicatorObjectDistance());
84          }
85      }
86  
87      @Override
88      public boolean isBlocking()
89      {
90          return this.conflictPlans.isBlocking();
91      }
92  
93      @Override
94      public final String toString()
95      {
96          return "AccelerationConflicts";
97      }
98  
99  }