View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djunits.value.vdouble.scalar.Speed;
5   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
6   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
7   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
8   import org.opentrafficsim.core.gtu.perception.EgoPerception;
9   import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
10  import org.opentrafficsim.road.gtu.lane.perception.InfrastructureLaneChangeInfo;
11  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
12  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
13  import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
14  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
15  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
16  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
17  
18  /**
19   * Determines desire by assessing the number of required lane change to be performed and the distance within which these have to
20   * be performed. Desire starts to increase from 0 linearly over a distance of x0 per required lane change, or per v*t0 per
21   * required lane change. For v>x0/t0 this gives that remaining time is critical, while for v<x0/t0 remaining space is
22   * critical. The desire is set towards the adjacent lane with a better situation. Negative desire towards the other lane, the
23   * extent of which pertains to the other adjacent lane, is also set.
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  public class IncentiveRoute implements MandatoryIncentive
32  {
33  
34      /** {@inheritDoc} */
35      @Override
36      public final Desire determineDesire(final BehavioralCharacteristics behavioralCharacteristics,
37              final LanePerception perception, final CarFollowingModel carFollowingModel, final Desire mandatoryDesire)
38              throws ParameterException, OperationalPlanException
39      {
40          // desire to leave current lane
41          double dCurr = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.CURRENT);
42          double dLeft;
43          if (perception.getLaneStructure().getCrossSection().contains(RelativeLane.LEFT))
44          {
45              // desire to leave left lane
46              dLeft = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.LEFT);
47              // desire to leave from current to left lane
48              dLeft = dLeft < dCurr ? dCurr : dLeft > dCurr ? -dLeft : 0;
49          }
50          else
51          {
52              dLeft = 0;
53          }
54          double dRigh;
55          if (perception.getLaneStructure().getCrossSection().contains(RelativeLane.RIGHT))
56          {
57              // desire to leave right lane
58              dRigh = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.RIGHT);
59              // desire to leave from current to right lane
60              dRigh = dRigh < dCurr ? dCurr : dRigh > dCurr ? -dRigh : 0;
61          }
62          else
63          {
64              dRigh = 0;
65          }
66          return new Desire(dLeft, dRigh);
67      }
68  
69      /**
70       * Calculates desire to leave a lane.
71       * @param bc behavioral characteristics
72       * @param perception perception
73       * @param lane relative lane to evaluate
74       * @return desire to leave a lane
75       * @throws ParameterException in case of a parameter exception
76       * @throws OperationalPlanException in case of perception exceptions
77       */
78      private double getDesireToLeave(final BehavioralCharacteristics bc, final LanePerception perception,
79              final RelativeLane lane) throws ParameterException, OperationalPlanException
80      {
81          Speed v = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
82          double dOut = 0.0;
83          if (perception.getPerceptionCategory(InfrastructurePerception.class).getCrossSection().contains(lane))
84          {
85              for (InfrastructureLaneChangeInfo info : perception.getPerceptionCategory(InfrastructurePerception.class)
86                      .getInfrastructureLaneChangeInfo(lane))
87              {
88                  double d = getDesireToLeave(bc, info.getRemainingDistance(), info.getRequiredNumberOfLaneChanges(), v);
89                  dOut = d > dOut ? d : dOut;
90              }
91          }
92          return dOut;
93      }
94  
95      /**
96       * Calculates desire to leave a lane for a single infrastructure info.
97       * @param bc behavioral characteristics
98       * @param x remaining distance for lane changes
99       * @param n number of required lane changes
100      * @param v current speed
101      * @return desire to leave a lane for a single infrastructure info
102      * @throws ParameterException in case of a parameter exception
103      */
104     private double getDesireToLeave(final BehavioralCharacteristics bc, final Length x, final int n, final Speed v)
105             throws ParameterException
106     {
107         double d1 = 1 - x.si / (n * bc.getParameter(ParameterTypes.LOOKAHEAD).si);
108         double d2 = 1 - (x.si / v.si) / (n * bc.getParameter(ParameterTypes.T0).si);
109         d1 = d2 > d1 ? d2 : d1;
110         return d1 < 0 ? 0 : d1;
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public final String toString()
116     {
117         return "IncentiveRoute";
118     }
119 
120 }