View Javadoc
1   package org.opentrafficsim.road.gtu.strategical.route;
2   
3   import java.io.Serializable;
4   
5   import org.opentrafficsim.base.parameters.Parameters;
6   import org.opentrafficsim.core.gtu.GTUException;
7   import org.opentrafficsim.core.network.Node;
8   import org.opentrafficsim.core.network.route.Route;
9   import org.opentrafficsim.core.parameters.ParameterFactory;
10  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
11  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlanner;
12  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlannerFactory;
13  import org.opentrafficsim.road.gtu.strategical.AbstractLaneBasedStrategicalPlannerFactory;
14  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
15  
16  /**
17   * Factory for creating {@code LaneBasedStrategicalRoutePlanner} using any {@code LaneBasedTacticalPlannerFactory}.
18   * <p>
19   * Copyright (c) 2013-2019 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  public class LaneBasedStrategicalRoutePlannerFactory
28          extends AbstractLaneBasedStrategicalPlannerFactory<LaneBasedStrategicalPlanner> implements Serializable
29  {
30  
31      /** */
32      private static final long serialVersionUID = 20160811L;
33  
34      /** Route supplier. */
35      private final RouteGeneratorOD routeGenerator;
36  
37      /**
38       * Constructor with factory for tactical planners.
39       * @param tacticalPlannerFactory LaneBasedTacticalPlannerFactory&lt;? extends LaneBasedTacticalPlanner&gt;; factory for
40       *            tactical planners
41       */
42      public LaneBasedStrategicalRoutePlannerFactory(
43              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory)
44      {
45          super(tacticalPlannerFactory);
46          this.routeGenerator = null;
47      }
48  
49      /**
50       * Constructor with factory for tactical planners.
51       * @param tacticalPlannerFactory LaneBasedTacticalPlannerFactory&lt;? extends LaneBasedTacticalPlanner&gt;; factory for
52       *            tactical planners
53       * @param routeGenerator RouteGeneratorOD; route generator
54       */
55      public LaneBasedStrategicalRoutePlannerFactory(
56              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
57              final RouteGeneratorOD routeGenerator)
58      {
59          super(tacticalPlannerFactory);
60          this.routeGenerator = routeGenerator;
61      }
62  
63      /**
64       * Constructor with factory for tactical planners.
65       * @param tacticalPlannerFactory LaneBasedTacticalPlannerFactory&lt;? extends LaneBasedTacticalPlanner&gt;; factory for
66       *            tactical planners
67       * @param parametersFactory ParameterFactory; factory for parameters
68       */
69      public LaneBasedStrategicalRoutePlannerFactory(
70              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
71              final ParameterFactory parametersFactory)
72      {
73          super(tacticalPlannerFactory, parametersFactory);
74          this.routeGenerator = null;
75      }
76  
77      /**
78       * Constructor with factory for tactical planners.
79       * @param tacticalPlannerFactory LaneBasedTacticalPlannerFactory&lt;? extends LaneBasedTacticalPlanner&gt;; factory for
80       *            tactical planners
81       * @param parametersFactory ParameterFactory; factory for parameters
82       * @param routeGenerator RouteGeneratorOD; route supplier
83       */
84      public LaneBasedStrategicalRoutePlannerFactory(
85              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
86              final ParameterFactory parametersFactory, final RouteGeneratorOD routeGenerator)
87      {
88          super(tacticalPlannerFactory, parametersFactory);
89          this.routeGenerator = routeGenerator;
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public final LaneBasedStrategicalPlanner create(final LaneBasedGTU gtu, final Route route, final Node origin,
95              final Node destination) throws GTUException
96      {
97          LaneBasedStrategicalRoutePlanner strategicalPlanner;
98          if (this.routeGenerator == null)
99          {
100             strategicalPlanner =
101                     new LaneBasedStrategicalRoutePlanner(nextTacticalPlanner(gtu), route, gtu, origin, destination);
102         }
103         else
104         {
105             strategicalPlanner = new LaneBasedStrategicalRoutePlanner(nextTacticalPlanner(gtu), route, gtu, origin, destination,
106                     this.routeGenerator);
107         }
108         gtu.setParameters(nextParameters(gtu.getGTUType()));
109         return strategicalPlanner;
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     protected Parameters getParameters()
115     {
116         // no specific parameters required for a LaneBasedStrategicalRoutePlanner
117         return null;
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     public final String toString()
123     {
124         return "LaneBasedStrategicalRoutePlannerFactory [tacticalPlannerFactory=" + getTacticalPlannerFactory() + "]";
125     }
126 
127 }