View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import java.util.SortedSet;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djunits.value.vdouble.scalar.Speed;
7   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
8   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
9   import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
10  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
11  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
12  import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
13  import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
14  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
15  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
16  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
17  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
18  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
19  
20  /**
21   * Determines desire out of hierarchal courtesy. For right-hand driving this is towards the right if the follower has a higher
22   * desired speed. If the left follower has a higher desired speed, a negative desire towards the left exists. For left-hand
23   * driving it is the other way around. Hierarchal desire depends on the level of hierarchal courtesy.
24   * <p>
25   * Copyright (c) 2013-2016 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/docs/current/license.html">OpenTrafficSim License</a>.
27   * <p>
28   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
29   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
30   */
31  // TODO keep left or right rules
32  public class IncentiveHierarchal implements VoluntaryIncentive
33  {
34  
35      /** {@inheritDoc} */
36      @Override
37      public final Desire determineDesire(final BehavioralCharacteristics behavioralCharacteristics,
38              final LanePerception perception, final CarFollowingModel carFollowingModel, final Desire mandatoryDesire,
39              final Desire voluntaryDesire) throws ParameterException, OperationalPlanException
40      {
41          double dLeft = 0;
42          double dRight = 0;
43          double hierarchy = behavioralCharacteristics.getParameter(LmrsParameters.HIERARCHY);
44          NeighborsPerception neighbors = perception.getPerceptionCategory(NeighborsPerception.class);
45          Speed vDes = carFollowingModel.desiredSpeed(behavioralCharacteristics,
46                  perception.getPerceptionCategory(InfrastructurePerception.class).getSpeedLimitProspect(RelativeLane.CURRENT)
47                          .getSpeedLimitInfo(Length.ZERO));
48          // change right to get out of the way
49          if (mandatoryDesire.getRight() >= 0.0)
50          {
51              SortedSet<HeadwayGTU> followers = neighbors.getFollowers(RelativeLane.CURRENT);
52              if (!followers.isEmpty())
53              {
54                  HeadwayGTU follower = followers.first();
55                  Speed vDesFollower = follower.getCarFollowingModel().desiredSpeed(follower.getBehavioralCharacteristics(),
56                          follower.getSpeedLimitInfo());
57                  if (vDes.lt(vDesFollower))
58                  {
59                      dRight = hierarchy;
60                  }
61              }
62          }
63          // stay right to keep out of the way
64          if (mandatoryDesire.getLeft() <= 0.0)
65          {
66              SortedSet<HeadwayGTU> followers = neighbors.getFollowers(RelativeLane.LEFT);
67              if (!followers.isEmpty())
68              {
69                  HeadwayGTU follower = followers.first();
70                  Speed vDesFollower = follower.getCarFollowingModel().desiredSpeed(follower.getBehavioralCharacteristics(),
71                          follower.getSpeedLimitInfo());
72                  if (vDes.lt(vDesFollower))
73                  {
74                      dLeft = -hierarchy;
75                  }
76              }
77          }
78          return new Desire(dLeft, dRight); // XXXXX STUB
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public final String toString()
84      {
85          return "IncentiveHierarchal";
86      }
87  
88  }