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 each lane
41          double dLeft = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.LEFT);
42          double dCurr = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.CURRENT);
43          double dRigh = getDesireToLeave(behavioralCharacteristics, perception, RelativeLane.RIGHT);
44          // change to desire to change left and right
45          dLeft = dLeft < dCurr ? dCurr : dLeft > dCurr ? -dLeft : 0;
46          dRigh = dRigh < dCurr ? dCurr : dRigh > dCurr ? -dRigh : 0;
47          return new Desire(dLeft, dRigh);
48      }
49  
50      /**
51       * Calculates desire to leave a lane.
52       * @param bc behavioral characteristics
53       * @param perception perception
54       * @param lane relative lane to evaluate
55       * @return desire to leave a lane
56       * @throws ParameterException in case of a parameter exception
57       * @throws OperationalPlanException in case of perception exceptions
58       */
59      private double getDesireToLeave(final BehavioralCharacteristics bc, final LanePerception perception,
60          final RelativeLane lane) throws ParameterException, OperationalPlanException
61      {
62          Speed v = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
63          double dOut = Double.NEGATIVE_INFINITY;
64          if (perception.getPerceptionCategory(InfrastructurePerception.class).getCrossSection().contains(lane))
65          {
66              for (InfrastructureLaneChangeInfo info : perception.getPerceptionCategory(InfrastructurePerception.class)
67                  .getInfrastructureLaneChangeInfo(lane))
68              {
69                  double d = getDesireToLeave(bc, info.getRemainingDistance(), info.getRequiredNumberOfLaneChanges(), v);
70                  dOut = d > dOut ? d : dOut;
71              }
72          }
73          return dOut;
74      }
75  
76      /**
77       * Calculates desire to leave a lane for a single infrastructure info.
78       * @param bc behavioral characteristics
79       * @param x remaining distance for lane changes
80       * @param n number of required lane changes
81       * @param v current speed
82       * @return desire to leave a lane for a single infrastructure info
83       * @throws ParameterException in case of a parameter exception
84       */
85      private double getDesireToLeave(final BehavioralCharacteristics bc, final Length x, final int n, final Speed v)
86          throws ParameterException
87      {
88          double d1 = 1 - x.si / (n * bc.getParameter(ParameterTypes.LOOKAHEAD).si);
89          double d2 = 1 - (x.si / v.si) / (n * bc.getParameter(ParameterTypes.T0).si);
90          d1 = d2 > d1 ? d2 : d1;
91          return d1 < 0 ? 0 : d1;
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public final String toString()
97      {
98          return "IncentiveRoute";
99      }
100 
101 }