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.gtu.behavioralcharacteristics.ParameterFactory;
8   import org.opentrafficsim.core.network.Node;
9   import org.opentrafficsim.core.network.route.Route;
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-2018 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 RouteSupplier routeSupplier;
36  
37      /**
38       * Constructor with factory for tactical planners.
39       * @param tacticalPlannerFactory factory for tactical planners
40       */
41      public LaneBasedStrategicalRoutePlannerFactory(
42              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory)
43      {
44          super(tacticalPlannerFactory);
45          this.routeSupplier = null;
46      }
47  
48      /**
49       * Constructor with factory for tactical planners.
50       * @param tacticalPlannerFactory factory for tactical planners
51       * @param routeSupplier route supplier
52       */
53      public LaneBasedStrategicalRoutePlannerFactory(
54              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
55              final RouteSupplier routeSupplier)
56      {
57          super(tacticalPlannerFactory);
58          this.routeSupplier = routeSupplier;
59      }
60  
61      /**
62       * Constructor with factory for tactical planners.
63       * @param tacticalPlannerFactory factory for tactical planners
64       * @param parametersFactory factory for parameters
65       */
66      public LaneBasedStrategicalRoutePlannerFactory(
67              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
68              final ParameterFactory parametersFactory)
69      {
70          super(tacticalPlannerFactory, parametersFactory);
71          this.routeSupplier = null;
72      }
73  
74      /**
75       * Constructor with factory for tactical planners.
76       * @param tacticalPlannerFactory factory for tactical planners
77       * @param parametersFactory factory for parameters
78       * @param routeSupplier route supplier
79       */
80      public LaneBasedStrategicalRoutePlannerFactory(
81              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
82              final ParameterFactory parametersFactory, final RouteSupplier routeSupplier)
83      {
84          super(tacticalPlannerFactory, parametersFactory);
85          this.routeSupplier = routeSupplier;
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public final LaneBasedStrategicalPlanner create(final LaneBasedGTU gtu, final Route route, final Node origin,
91              final Node destination) throws GTUException
92      {
93          LaneBasedStrategicalRoutePlanner strategicalPlanner;
94          if (this.routeSupplier == null)
95          {
96              strategicalPlanner =
97                      new LaneBasedStrategicalRoutePlanner(nextTacticalPlanner(gtu), route, gtu, origin, destination);
98          }
99          else
100         {
101             strategicalPlanner = new LaneBasedStrategicalRoutePlanner(nextTacticalPlanner(gtu), route, gtu, origin, destination,
102                     this.routeSupplier);
103         }
104         gtu.setParameters(nextParameters(gtu.getGTUType()));
105         return strategicalPlanner;
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     protected Parameters getParameters()
111     {
112         // no specific parameters required for a LaneBasedStrategicalRoutePlanner
113         return null;
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     public final String toString()
119     {
120         return "LaneBasedStrategicalRoutePlannerFactory [tacticalPlannerFactory=" + getTacticalPlannerFactory() + "]";
121     }
122 
123 }