View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
5   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
6   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
7   import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
8   import org.opentrafficsim.core.network.LateralDirectionality;
9   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
10  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
11  import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
12  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
13  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
14  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
15  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
16  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil;
17  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
18  
19  /**
20   * Determines lane change desire for courtesy lane changes, which are performed to supply space for other drivers. In case
21   * drivers in adjacent lanes have desire to change to the current lane, the driver has desire to change to the other adjacent
22   * lane. The level of desire depends on lane change courtesy, as well as the distance of the leading vehicle for which desire
23   * exists. This desire exists for only a single vehicle, i.e. the one giving maximum desire. A negative desire may also result
24   * for leaders in the 2nd adjacent lane desiring to change to the 1st adjacent lane. By not changing to the 1st adjacent lane,
25   * room is reserved for the leader on the 2nd adjacent lane.
26   * <p>
27   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
28   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
29   * <p>
30   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
31   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
32   */
33  public class IncentiveCourtesy implements VoluntaryIncentive, LmrsParameters
34  {
35  
36      /** {@inheritDoc} */
37      @Override
38      public final Desire determineDesire(final BehavioralCharacteristics behavioralCharacteristics,
39              final LanePerception perception, final CarFollowingModel carFollowingModel, final Desire mandatoryDesire,
40              final Desire voluntaryDesire) throws ParameterException, OperationalPlanException
41      {
42          double dLeftYes = 0;
43          double dRightYes = 0;
44          double dLeftNo = 0;
45          double dRightNo = 0;
46          double courtesy = behavioralCharacteristics.getParameter(COURTESY);
47          Length x0 = behavioralCharacteristics.getParameter(ParameterTypes.LOOKAHEAD);
48          NeighborsPerception neighbors = perception.getPerceptionCategory(NeighborsPerception.class);
49          for (LateralDirectionality dir : new LateralDirectionality[] { LateralDirectionality.LEFT,
50                  LateralDirectionality.RIGHT })
51          {
52              for (HeadwayGTU leader : neighbors.getLeaders(new RelativeLane(dir, 1)))
53              {
54                  BehavioralCharacteristics bc = leader.getBehavioralCharacteristics();
55                  double desire = dir.isLeft() ? bc.getParameter(DRIGHT) : bc.getParameter(DLEFT);
56                  if (desire > 0)
57                  {
58                      double d = (1 - leader.getDistance().si / x0.si) * desire;
59                      if (dir.isLeft())
60                      {
61                          dLeftYes = dLeftYes > d ? dLeftYes : d;
62                      }
63                      else
64                      {
65                          dRightYes = dRightYes > d ? dRightYes : d;
66                      }
67                  }
68              }
69              for (HeadwayGTU follower : neighbors.getFollowers(new RelativeLane(dir, 2)))
70              {
71                  if (follower.getDistance().lt0())
72                  {
73                      BehavioralCharacteristics bc = follower.getBehavioralCharacteristics();
74                      double desire = dir.isLeft() ? bc.getParameter(DRIGHT) : bc.getParameter(DLEFT);
75                      if (desire > 0)
76                      {
77                          if (dir.isLeft())
78                          {
79                              dLeftNo = dLeftNo > desire ? dLeftNo : desire;
80                          }
81                          else
82                          {
83                              dRightNo = dRightNo > desire ? dRightNo : desire;
84                          }
85                      }
86                  }
87                  else
88                  {
89                      break;
90                  }
91              }
92              for (HeadwayGTU leader : neighbors.getLeaders(new RelativeLane(dir, 2)))
93              {
94                  BehavioralCharacteristics bc = leader.getBehavioralCharacteristics();
95                  double desire = dir.isLeft() ? bc.getParameter(DRIGHT) : bc.getParameter(DLEFT);
96                  if (desire > 0)
97                  {
98                      double d = (1 - leader.getDistance().si / x0.si) * desire;
99                      if (dir.isLeft())
100                     {
101                         dLeftNo = dLeftNo > d ? dLeftNo : d;
102                     }
103                     else
104                     {
105                         dRightNo = dRightNo > d ? dRightNo : d;
106                     }
107                 }
108             }
109         }
110         dLeftYes *= courtesy;
111         dRightYes *= courtesy;
112         return new Desire(dLeftYes - dLeftNo, dRightYes - dRightNo);
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     public final String toString()
118     {
119         return "IncentiveCourtesy";
120     }
121 
122 }