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-2018 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 car following model factory
  36.      */
  37.     public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(
  38.             final CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory)
  39.     {
  40.         this.carFollowingModel = null;
  41.         this.carFollowingModelFactory = carFollowingModelFactory;
  42.     }

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

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

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

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

  83. }