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.ParameterTypes;
8   import org.opentrafficsim.base.parameters.Parameters;
9   import org.opentrafficsim.core.gtu.GTUException;
10  import org.opentrafficsim.core.gtu.perception.EgoPerception;
11  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
12  import org.opentrafficsim.road.gtu.animation.Blockable;
13  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
14  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
15  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
16  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
17  import org.opentrafficsim.road.gtu.lane.perception.categories.IntersectionPerception;
18  import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
19  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayConflict;
20  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
21  import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
22  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
23  import org.opentrafficsim.road.gtu.lane.tactical.util.CarFollowingUtil;
24  import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil;
25  import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil.ConflictPlans;
26  import org.opentrafficsim.road.network.lane.conflict.Conflict;
27  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
28  
29  /**
30   * <p>
31   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
32   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
33   * <p>
34   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 27 jan. 2017 <br>
35   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
36   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
37   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
38   */
39  
40  public class AccelerationConflicts implements AccelerationIncentive, Blockable
41  {
42  
43      /** Set of yield plans at conflicts with priority. Remembering for static model. */
44      private final ConflictPlans yieldPlans = new ConflictPlans();
45  
46      /** {@inheritDoc} */
47      @Override
48      public final void accelerate(final SimpleOperationalPlan simplePlan, final RelativeLane lane, final LaneBasedGTU gtu,
49              final LanePerception perception, final CarFollowingModel carFollowingModel, final Speed speed,
50              final Parameters params, final SpeedLimitInfo speedLimitInfo)
51              throws OperationalPlanException, ParameterException, GTUException
52      {
53          // TODO consider adjacent lanes before and during lane change
54          EgoPerception ego = perception.getPerceptionCategory(EgoPerception.class);
55          Acceleration acceleration = ego.getAcceleration();
56          Length length = ego.getLength();
57          Length width = ego.getWidth();
58          PerceptionCollectable<HeadwayConflict, Conflict> conflicts =
59                  perception.getPerceptionCategory(IntersectionPerception.class).getConflicts(lane);
60          PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders =
61                  perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(lane);
62  
63          Acceleration a;
64          if (lane.isCurrent())
65          {
66              a = ConflictUtil.approachConflicts(params, conflicts, leaders, carFollowingModel, length, width, speed,
67                      acceleration, speedLimitInfo, this.yieldPlans, gtu);
68              simplePlan.minimizeAcceleration(a);
69              if (this.yieldPlans.getIndicatorIntent().isLeft())
70              {
71                  simplePlan.setIndicatorIntentLeft(this.yieldPlans.getIndicatorObjectDistance());
72              }
73              else if (this.yieldPlans.getIndicatorIntent().isRight())
74              {
75                  simplePlan.setIndicatorIntentRight(this.yieldPlans.getIndicatorObjectDistance());
76              }
77          }
78          else if (!conflicts.isEmpty() && conflicts.first().getDistance().gt0())
79          {
80              // TODO this is too simple, needs to be consistent with gap-acceptance or GTU's may not change
81              a = CarFollowingUtil.followSingleLeader(carFollowingModel, params, speed, speedLimitInfo,
82                      conflicts.first().getDistance(), Speed.ZERO);
83              // limit deceleration on adjacent lanes
84              a = Acceleration.max(a, params.getParameter(ParameterTypes.BCRIT).neg());
85              simplePlan.minimizeAcceleration(a);
86          }
87      }
88  
89      /** {@inheritDoc} */
90      @Override
91      public boolean isBlocking()
92      {
93          return this.yieldPlans.isBlocking();
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public final String toString()
99      {
100         return "AccelerationConflicts";
101     }
102 
103 }