View Javadoc
1   package org.opentrafficsim.road.gtu.strategical.route;
2   
3   import java.io.Serializable;
4   
5   import org.opentrafficsim.core.gtu.GTUException;
6   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
7   import org.opentrafficsim.core.network.route.Route;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlanner;
10  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlannerFactory;
11  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
12  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
13  
14  /**
15   * Factory for creating {@code LaneBasedStrategicalRoutePlanner} using any {@code LaneBasedTacticalPlannerFactory}.
16   * <p>
17   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
19   * <p>
20   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 2, 2016 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
23   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
24   */
25  
26  public class LaneBasedStrategicalRoutePlannerFactory implements
27      LaneBasedStrategicalPlannerFactory<LaneBasedStrategicalPlanner>, Serializable
28  {
29  
30      /** */
31      private static final long serialVersionUID = 20160811L;
32  
33      /** Route for the next strategical planner. */
34      private Route route;
35  
36      /** Behavioral characteristics for the next strategical planner. */
37      private BehavioralCharacteristics behavioralCharacteristics;
38  
39      /** Factory for tactical planners. */
40      private final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory;
41  
42      /**
43       * Constructor with factory for tactical planners.
44       * @param tacticalPlannerFactory factory for tactical planners
45       */
46      public LaneBasedStrategicalRoutePlannerFactory(
47          final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory)
48      {
49          this.tacticalPlannerFactory = tacticalPlannerFactory;
50      }
51  
52      /**
53       * Sets the route for the next strategical planner. If none is given, none will be forwarded.
54       * @param route route for the next strategical planner
55       */
56      public final void setRoute(final Route route)
57      {
58          this.route = route;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public final BehavioralCharacteristics getDefaultBehavioralCharacteristics()
64      {
65          return this.tacticalPlannerFactory.getDefaultBehavioralCharacteristics();
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public final void setBehavioralCharacteristics(final BehavioralCharacteristics behavioralCharacteristics)
71      {
72          this.behavioralCharacteristics = behavioralCharacteristics;
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public final LaneBasedStrategicalPlanner create(final LaneBasedGTU gtu) throws GTUException
78      {
79          if (this.behavioralCharacteristics == null)
80          {
81              this.behavioralCharacteristics = getDefaultBehavioralCharacteristics();
82          }
83          LaneBasedStrategicalRoutePlanner strategicalPlanner =
84              new LaneBasedStrategicalRoutePlanner(this.behavioralCharacteristics, this.tacticalPlannerFactory.create(gtu),
85                  this.route, gtu);
86          this.route = null;
87          this.behavioralCharacteristics = null;
88          return strategicalPlanner;
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public final String toString()
94      {
95          return "LaneBasedStrategicalRoutePlannerFactory [tacticalPlannerFactory=" + this.tacticalPlannerFactory + "]";
96      }
97      
98  }