View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.LengthUnit;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.base.parameters.ParameterException;
8   import org.opentrafficsim.base.parameters.ParameterSet;
9   import org.opentrafficsim.base.parameters.ParameterTypes;
10  import org.opentrafficsim.base.parameters.Parameters;
11  import org.opentrafficsim.core.gtu.GTUException;
12  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
13  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModelFactory;
14  import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;
15  
16  /**
17   * Factory to create {@code LaneBasedGTUFollowingChange0TacticalPlanner}.
18   * <p>
19   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
21   * <p>
22   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 2, 2016 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
26   */
27  
28  public class LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory
29          implements LaneBasedTacticalPlannerFactory<LaneBasedGTUFollowingDirectedChangeTacticalPlanner>, Serializable
30  {
31  
32      /** */
33      private static final long serialVersionUID = 20160811L;
34  
35      /** The car following model. */
36      private GTUFollowingModelOld carFollowingModel;
37  
38      /** Factory for car-following model. */
39      private CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory;
40  
41      /**
42       * Constructor with car-following model factory.
43       * @param carFollowingModelFactory CarFollowingModelFactory&lt;? extends GTUFollowingModelOld&gt;; car following model
44       *            factory
45       */
46      public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(
47              final CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory)
48      {
49          this.carFollowingModel = null;
50          this.carFollowingModelFactory = carFollowingModelFactory;
51      }
52  
53      /**
54       * Constructor with fixed stateless car-following and lane change model.
55       * @param carFollowingModel GTUFollowingModelOld; car following model
56       */
57      public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(final GTUFollowingModelOld carFollowingModel)
58      {
59          this.carFollowingModel = carFollowingModel;
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public final LaneBasedGTUFollowingDirectedChangeTacticalPlanner create(final LaneBasedGTU gtu) throws GTUException
65      {
66          if (this.carFollowingModel != null)
67          {
68              return new LaneBasedGTUFollowingDirectedChangeTacticalPlanner(this.carFollowingModel, gtu);
69          }
70          return new LaneBasedGTUFollowingDirectedChangeTacticalPlanner(this.carFollowingModelFactory.generateCarFollowingModel(),
71                  gtu);
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public final Parameters getParameters()
77      {
78          Parameters params = new ParameterSet().setDefaultParameters(ParameterTypes.class);
79          try
80          {
81              params.setParameter(ParameterTypes.LOOKAHEAD, new Length(250, LengthUnit.SI));
82          }
83          catch (ParameterException pe)
84          {
85              throw new RuntimeException("Parameter type 'LOOKAHEAD' could not be set.", pe);
86          }
87          return params;
88      }
89  
90      /** {@inheritDoc} */
91      @Override
92      public final String toString()
93      {
94          return "LaneBasedGTUFollowingChange0TacticalPlannerFactory [car-following=" + this.carFollowingModel + "]";
95      }
96  
97  }