LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory.java

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

  2. import java.io.Serializable;

  3. import org.djunits.unit.LengthUnit;
  4. import org.djunits.value.vdouble.scalar.Length;
  5. import org.opentrafficsim.base.parameters.ParameterException;
  6. import org.opentrafficsim.base.parameters.ParameterSet;
  7. import org.opentrafficsim.base.parameters.ParameterTypes;
  8. import org.opentrafficsim.base.parameters.Parameters;
  9. import org.opentrafficsim.core.gtu.GTUException;
  10. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  11. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModelFactory;
  12. import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;

  13. /**
  14.  * Factory to create {@code LaneBasedGTUFollowingChange0TacticalPlanner}.
  15.  * <p>
  16.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  17.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  18.  * <p>
  19.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 2, 2016 <br>
  20.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  21.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  22.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  23.  */

  24. public class LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory
  25.         implements LaneBasedTacticalPlannerFactory<LaneBasedGTUFollowingDirectedChangeTacticalPlanner>, Serializable
  26. {

  27.     /** */
  28.     private static final long serialVersionUID = 20160811L;

  29.     /** The car following model. */
  30.     private GTUFollowingModelOld carFollowingModel;

  31.     /** Factory for car-following model. */
  32.     private CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory;

  33.     /**
  34.      * Constructor with car-following model factory.
  35.      * @param carFollowingModelFactory CarFollowingModelFactory&lt;? extends GTUFollowingModelOld&gt;; car following model
  36.      *            factory
  37.      */
  38.     public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(
  39.             final CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory)
  40.     {
  41.         this.carFollowingModel = null;
  42.         this.carFollowingModelFactory = carFollowingModelFactory;
  43.     }

  44.     /**
  45.      * Constructor with fixed stateless car-following and lane change model.
  46.      * @param carFollowingModel GTUFollowingModelOld; car following model
  47.      */
  48.     public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(final GTUFollowingModelOld carFollowingModel)
  49.     {
  50.         this.carFollowingModel = carFollowingModel;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public final LaneBasedGTUFollowingDirectedChangeTacticalPlanner create(final LaneBasedGTU gtu) throws GTUException
  55.     {
  56.         if (this.carFollowingModel != null)
  57.         {
  58.             return new LaneBasedGTUFollowingDirectedChangeTacticalPlanner(this.carFollowingModel, gtu);
  59.         }
  60.         return new LaneBasedGTUFollowingDirectedChangeTacticalPlanner(this.carFollowingModelFactory.generateCarFollowingModel(),
  61.                 gtu);
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     public final Parameters getParameters()
  66.     {
  67.         Parameters params = new ParameterSet().setDefaultParameters(ParameterTypes.class);
  68.         try
  69.         {
  70.             params.setParameter(ParameterTypes.LOOKAHEAD, new Length(250, LengthUnit.SI));
  71.         }
  72.         catch (ParameterException pe)
  73.         {
  74.             throw new RuntimeException("Parameter type 'LOOKAHEAD' could not be set.", pe);
  75.         }
  76.         return params;
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public final String toString()
  81.     {
  82.         return "LaneBasedGTUFollowingChange0TacticalPlannerFactory [car-following=" + this.carFollowingModel + "]";
  83.     }

  84. }