FixedLaneChangeModel.java

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

  2. import java.io.Serializable;
  3. import java.util.Collection;

  4. import org.djunits.value.vdouble.scalar.Acceleration;
  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.djunits.value.vdouble.scalar.Speed;
  7. import org.opentrafficsim.core.gtu.GTUException;
  8. import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
  9. import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
  10. import org.opentrafficsim.core.network.LateralDirectionality;
  11. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  12. import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
  13. import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlanner;
  14. import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;

  15. /**
  16.  * Dummy lane change model with totally predictable results (used for testing).
  17.  * <p>
  18.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  19.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  20.  * <p>
  21.  * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
  22.  *          initial version 11 feb. 2015 <br>
  23.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  24.  */
  25. public class FixedLaneChangeModel implements LaneChangeModel, Serializable
  26. {
  27.     /** */
  28.     private static final long serialVersionUID = 20150211L;

  29.     /** Lane change that will always be returned by this FixedLaneChangeModel. */
  30.     private final LateralDirectionality laneChange;

  31.     /**
  32.      * Construct a FixedLaneChangeModel.
  33.      * @param laneChange LateralDirectionality; the lane change that (always) be returned by this FixedLaneChangeModel.
  34.      */
  35.     public FixedLaneChangeModel(final LateralDirectionality laneChange)
  36.     {
  37.         this.laneChange = laneChange;
  38.     }

  39.     /** {@inheritDoc} */
  40.     @SuppressWarnings("checkstyle:parameternumber")
  41.     @Override
  42.     public final LaneMovementStep computeLaneChangeAndAcceleration(final LaneBasedGTU gtu,
  43.             final Collection<Headway> sameLaneTraffic, final Collection<Headway> rightLaneTraffic,
  44.             final Collection<Headway> leftLaneTraffic, final Speed speedLimit, final Acceleration preferredLaneRouteIncentive,
  45.             final Acceleration laneChangeThreshold, final Acceleration nonPreferredLaneRouteIncentive) throws GTUException,
  46.             ParameterException
  47.     {
  48.         Length headway = gtu.getBehavioralCharacteristics().getParameter(ParameterTypes.LOOKAHEAD);
  49.         GTUFollowingModelOld gtuFollowingModel =
  50.                 (GTUFollowingModelOld) ((AbstractLaneBasedTacticalPlanner) gtu.getTacticalPlanner()).getCarFollowingModel();
  51.         if (null == this.laneChange)
  52.         {
  53.             return new LaneMovementStep(gtuFollowingModel
  54.                     .computeDualAccelerationStep(gtu, sameLaneTraffic, headway, speedLimit).getLeaderAccelerationStep(), null);
  55.         }
  56.         else if (LateralDirectionality.LEFT == this.laneChange)
  57.         {
  58.             return new LaneMovementStep(gtuFollowingModel
  59.                     .computeDualAccelerationStep(gtu, leftLaneTraffic, headway, speedLimit).getLeaderAccelerationStep(),
  60.                     this.laneChange);
  61.         }
  62.         else if (LateralDirectionality.RIGHT == this.laneChange)
  63.         {
  64.             return new LaneMovementStep(gtuFollowingModel.computeDualAccelerationStep(gtu, rightLaneTraffic, headway,
  65.                     speedLimit).getLeaderAccelerationStep(), this.laneChange);
  66.         }
  67.         throw new Error("Program Error - unhandled LateralDirectionality");
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public final String getName()
  72.     {
  73.         return "Fixed lane change model";
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public final String getLongName()
  78.     {
  79.         return "Fixed lane change model. This model returns a lane change decision that is independent of the actual "
  80.                 + "traffic. It is used mostly for testing.";
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     public final String toString()
  85.     {
  86.         return "FixedLaneChangeModel [laneChange=" + this.laneChange + "]";
  87.     }

  88. }