SteeringLmrs.java

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

  2. import java.util.LinkedHashSet;

  3. import org.djunits.value.vdouble.scalar.Time;
  4. import org.djutils.exceptions.Try;
  5. import org.opentrafficsim.base.parameters.ParameterException;
  6. import org.opentrafficsim.base.parameters.ParameterTypeClassList;
  7. import org.opentrafficsim.base.parameters.ParameterTypes;
  8. import org.opentrafficsim.core.gtu.GTUException;
  9. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
  10. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  11. import org.opentrafficsim.core.network.NetworkException;
  12. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  13. import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
  14. import org.opentrafficsim.road.gtu.lane.plan.operational.LaneChange;
  15. import org.opentrafficsim.road.gtu.lane.plan.operational.LaneOperationalPlanBuilder;
  16. import org.opentrafficsim.road.gtu.lane.plan.operational.SimpleOperationalPlan;
  17. import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlanner;
  18. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  19. import org.opentrafficsim.road.gtu.lane.tactical.util.Steering;
  20. import org.opentrafficsim.road.gtu.lane.tactical.util.Steering.FeedbackTable;
  21. import org.opentrafficsim.road.gtu.lane.tactical.util.Steering.SteeringState;
  22. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Cooperation;
  23. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.GapAcceptance;
  24. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsData;
  25. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil;
  26. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
  27. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Synchronization;
  28. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Tailgating;
  29. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;

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

  31. /**
  32.  * <p>
  33.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  34.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  35.  * <p>
  36.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 jan. 2019 <br>
  37.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  38.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  39.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  40.  */
  41. public class SteeringLmrs extends AbstractLaneBasedTacticalPlanner
  42. {

  43.     /** Parameter type for mandatory lane change incentives. */
  44.     public static final ParameterTypeClassList<MandatoryIncentive> MANDATORY = new ParameterTypeClassList<>("man.incent.",
  45.             "Mandatory lane-change incentives.", ParameterTypeClassList.getValueClass(MandatoryIncentive.class));

  46.     /** Parameter type for voluntary lane change incentives. */
  47.     public static final ParameterTypeClassList<VoluntaryIncentive> VOLUNTARY = new ParameterTypeClassList<>("vol.incent.",
  48.             "Voluntary lane-change incentives.", ParameterTypeClassList.getValueClass(VoluntaryIncentive.class));

  49.     /** Serialization id. */
  50.     private static final long serialVersionUID = 20160300L;

  51.     /** Lane change status. */
  52.     private final LaneChange laneChange;

  53.     /** LMRS data. */
  54.     private final LmrsData lmrsData;

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

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

  59.     /** Steering state. */
  60.     private final SteeringState steeringState = new SteeringState();

  61.     /** Feedback table. */
  62.     private final FeedbackTable feedbackTable;

  63.     /**
  64.      * Constructor setting the car-following model.
  65.      * @param carFollowingModel CarFollowingModel; Car-following model.
  66.      * @param gtu LaneBasedGTU; GTU
  67.      * @param lanePerception LanePerception; perception
  68.      * @param synchronization Synchronization; type of synchronization
  69.      * @param cooperation Cooperation; type of cooperation
  70.      * @param gapAcceptance GapAcceptance; gap-acceptance
  71.      * @param feedbackTable FeedbackTable; feedback table
  72.      */
  73.     public SteeringLmrs(final CarFollowingModel carFollowingModel, final LaneBasedGTU gtu, final LanePerception lanePerception,
  74.             final Synchronization synchronization, final Cooperation cooperation, final GapAcceptance gapAcceptance,
  75.             final FeedbackTable feedbackTable)
  76.     {
  77.         super(carFollowingModel, gtu, lanePerception);
  78.         this.laneChange = Try.assign(() -> new LaneChange(gtu), "Parameter LCDUR is required.", GTUException.class);
  79.         this.lmrsData = new LmrsData(synchronization, cooperation, gapAcceptance, Tailgating.NONE);
  80.         this.feedbackTable = feedbackTable;
  81.     }

  82.     /**
  83.      * Adds a mandatory incentive. Ignores {@code null}.
  84.      * @param incentive MandatoryIncentive; Incentive to add.
  85.      */
  86.     public final void addMandatoryIncentive(final MandatoryIncentive incentive)
  87.     {
  88.         if (incentive != null)
  89.         {
  90.             this.mandatoryIncentives.add(incentive);
  91.         }
  92.     }

  93.     /**
  94.      * Adds a voluntary incentive. Ignores {@code null}.
  95.      * @param incentive VoluntaryIncentive; Incentive to add.
  96.      */
  97.     public final void addVoluntaryIncentive(final VoluntaryIncentive incentive)
  98.     {
  99.         if (incentive != null)
  100.         {
  101.             this.voluntaryIncentives.add(incentive);
  102.         }
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public final OperationalPlan generateOperationalPlan(final Time startTime, final DirectedPoint locationAtStartTime)
  107.             throws OperationalPlanException, GTUException, NetworkException, ParameterException
  108.     {
  109.         // LMRS
  110.         SimpleOperationalPlan simplePlan = LmrsUtil.determinePlan(getGtu(), startTime, getCarFollowingModel(), this.laneChange,
  111.                 this.lmrsData, getPerception(), this.mandatoryIncentives, this.voluntaryIncentives);

  112.         if (simplePlan.isLaneChange())
  113.         {
  114.             this.laneChange.setDesiredLaneChangeDuration(getGtu().getParameters().getParameter(ParameterTypes.LCDUR));
  115.         }

  116.         // set turn indicator
  117.         simplePlan.setTurnIndicator(getGtu());

  118.         // create plan
  119.         OperationalPlan referencePlan =
  120.                 LaneOperationalPlanBuilder.buildPlanFromSimplePlan(getGtu(), startTime, simplePlan, this.laneChange);

  121.         return Steering.fromReferencePlan(getGtu(), getGtu().getParameters(), this.steeringState, referencePlan,
  122.                 this.feedbackTable);
  123.     }

  124. }