LMRS.java

  1. package org.opentrafficsim.road.gtu.lane.tactical.lmrs;

  2. import java.util.LinkedHashSet;

  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.djunits.value.vdouble.scalar.Time;
  7. import org.opentrafficsim.core.gtu.GTUException;
  8. import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
  9. import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
  10. import org.opentrafficsim.core.gtu.perception.EgoPerception;
  11. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
  12. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  13. import org.opentrafficsim.core.network.NetworkException;
  14. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  15. import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
  16. import org.opentrafficsim.road.gtu.lane.perception.categories.DefaultSimplePerception;
  17. import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
  18. import org.opentrafficsim.road.gtu.lane.perception.categories.IntersectionPerception;
  19. import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
  20. import org.opentrafficsim.road.gtu.lane.plan.operational.LaneOperationalPlanBuilder.LaneChange;
  21. import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
  22. import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlanner;
  23. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  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.gtu.lane.tactical.util.SpeedLimitUtil;
  27. import org.opentrafficsim.road.gtu.lane.tactical.util.TrafficLightUtil;
  28. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil;
  29. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil.LmrsData;
  30. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
  31. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
  32. import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
  33. import org.opentrafficsim.road.network.speed.SpeedLimitProspect;

  34. import nl.tudelft.simulation.language.d3.DirectedPoint;

  35. /**
  36.  * Implementation of the LMRS (Lane change Model with Relaxation and Synchronization). See Schakel, W.J., Knoop, V.L., and Van
  37.  * Arem, B. (2012), <a href="http://victorknoop.eu/research/papers/TRB2012_LMRS_reviewed.pdf">LMRS: Integrated Lane Change Model
  38.  * with Relaxation and Synchronization</a>, Transportation Research Records: Journal of the Transportation Research Board, No.
  39.  * 2316, pp. 47-57. Note in the official versions of TRB and TRR some errors appeared due to the typesetting of the papers (not
  40.  * in the preprint provided here). A list of errata for the official versions is found
  41.  * <a href="http://victorknoop.eu/research/papers/Erratum_LMRS.pdf">here</a>.
  42.  * <p>
  43.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  44.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  45.  * <p>
  46.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
  47.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  48.  */
  49. public class LMRS extends AbstractLaneBasedTacticalPlanner
  50. {

  51.     /** Serialization id. */
  52.     private static final long serialVersionUID = 20160300L;

  53.     /** Set of yield plans at conflicts with priority. Remembering for static model. */
  54.     private final ConflictPlans yieldPlans = new ConflictPlans();

  55.     /** Lane change status. */
  56.     private final LaneChange laneChange = new LaneChange();

  57.     /** LMRS data. */
  58.     private final LmrsData lmrsData = new LmrsData();

  59.     /** Set of mandatory lane change incentives. */
  60.     private final LinkedHashSet<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();

  61.     /** Set of voluntary lane change incentives. */
  62.     private final LinkedHashSet<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();

  63.     /**
  64.      * Constructor setting the car-following model.
  65.      * @param carFollowingModel Car-following model.
  66.      * @param gtu GTU
  67.      */
  68.     public LMRS(final CarFollowingModel carFollowingModel, final LaneBasedGTU gtu)
  69.     {
  70.         super(carFollowingModel, gtu);
  71.         getPerception().addPerceptionCategory(new DefaultSimplePerception(getPerception()));
  72.         getPerception().addPerceptionCategory(new InfrastructurePerception(getPerception()));
  73.         getPerception().addPerceptionCategory(new NeighborsPerception(getPerception()));
  74.         getPerception().addPerceptionCategory(new IntersectionPerception(getPerception()));
  75.         getPerception().addPerceptionCategory(new EgoPerception(getPerception()));
  76.     }

  77.     /**
  78.      * Adds a mandatory incentive. Ignores <tt>null</tt>.
  79.      * @param incentive Incentive to add.
  80.      */
  81.     public final void addMandatoryIncentive(final MandatoryIncentive incentive)
  82.     {
  83.         if (incentive != null)
  84.         {
  85.             this.mandatoryIncentives.add(incentive);
  86.         }
  87.     }

  88.     /**
  89.      * Adds a voluntary incentive. Ignores <tt>null</tt>.
  90.      * @param incentive Incentive to add.
  91.      */
  92.     public final void addVoluntaryIncentive(final VoluntaryIncentive incentive)
  93.     {
  94.         if (incentive != null)
  95.         {
  96.             this.voluntaryIncentives.add(incentive);
  97.         }
  98.     }

  99.     /**
  100.      * Sets the default lane change incentives.
  101.      */
  102.     public final void setDefaultIncentives()
  103.     {
  104.         this.mandatoryIncentives.clear();
  105.         this.voluntaryIncentives.clear();
  106.         this.mandatoryIncentives.add(new IncentiveRoute());
  107.         this.voluntaryIncentives.add(new IncentiveSpeedWithCourtesy());
  108.         this.voluntaryIncentives.add(new IncentiveKeep());
  109.     }

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     public final OperationalPlan generateOperationalPlan(final Time startTime, final DirectedPoint locationAtStartTime)
  113.             throws OperationalPlanException, GTUException, NetworkException, ParameterException
  114.     {

  115.         if (getGtu().getId().equals("WWP.LANE:2") && startTime.si > 0)
  116.         {
  117.             double q = 8;
  118.         }
  119.        
  120.         // obtain objects to get info
  121.         getPerception().perceive();
  122.         SpeedLimitProspect slp = getPerception().getPerceptionCategory(InfrastructurePerception.class)
  123.                 .getSpeedLimitProspect(RelativeLane.CURRENT);
  124.         SpeedLimitInfo sli = slp.getSpeedLimitInfo(Length.ZERO);
  125.         BehavioralCharacteristics bc = getGtu().getBehavioralCharacteristics();

  126.         // LMRS
  127.         SimpleOperationalPlan simplePlan = LmrsUtil.determinePlan(getGtu(), startTime, getCarFollowingModel(), this.laneChange,
  128.                 this.lmrsData, getPerception(), this.mandatoryIncentives, this.voluntaryIncentives);

  129.         // speed limits
  130.         Speed speed = getPerception().getPerceptionCategory(EgoPerception.class).getSpeed();
  131.         simplePlan.minimumAcceleration(SpeedLimitUtil.considerSpeedLimitTransitions(bc, speed, slp, getCarFollowingModel()));

  132.         // traffic lights
  133.         // TODO traffic lights on route, possible on different lane (and possibly close)
  134.         simplePlan.minimumAcceleration(TrafficLightUtil.respondToTrafficLights(bc,
  135.                 getPerception().getPerceptionCategory(IntersectionPerception.class).getTrafficLights(RelativeLane.CURRENT),
  136.                 getCarFollowingModel(), speed, sli));

  137.         // conflicts
  138.         Acceleration acceleration = getPerception().getPerceptionCategory(EgoPerception.class).getAcceleration();
  139.         simplePlan.minimumAcceleration(ConflictUtil.approachConflicts(bc,
  140.                 getPerception().getPerceptionCategory(IntersectionPerception.class).getConflicts(RelativeLane.CURRENT),
  141.                 getPerception().getPerceptionCategory(NeighborsPerception.class).getLeaders(RelativeLane.CURRENT),
  142.                 getCarFollowingModel(), getGtu().getLength(), speed, acceleration, sli, this.yieldPlans));

  143.         // create plan
  144.         return buildPlanFromSimplePlan(getGtu(), startTime, bc, simplePlan, this.laneChange);

  145.     }

  146.     /** {@inheritDoc} */
  147.     @Override
  148.     public final String toString()
  149.     {
  150.         String mandatory;
  151.         mandatory = "mandatoryIncentives=" + this.mandatoryIncentives + ", ";
  152.         String voluntary;
  153.         if (!this.voluntaryIncentives.isEmpty())
  154.         {
  155.             voluntary = "voluntaryIncentives=" + this.voluntaryIncentives;
  156.         }
  157.         else
  158.         {
  159.             voluntary = "voluntaryIncentives=[]";
  160.         }
  161.         return "LMRS [" + mandatory + voluntary + "]";
  162.     }

  163. }