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.gtu.behavioralcharacteristics.BehavioralCharacteristicsFactory;
8   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristicsFactoryDefault;
9   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
10  import org.opentrafficsim.core.network.route.Route;
11  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlanner;
13  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlannerFactory;
14  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
15  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
16  
17  /**
18   * Factory for creating {@code LaneBasedStrategicalRoutePlanner} using any {@code LaneBasedTacticalPlannerFactory}.
19   * <p>
20   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
22   * <p>
23   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 2, 2016 <br>
24   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
26   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
27   */
28  
29  public class LaneBasedStrategicalRoutePlannerFactory
30          implements LaneBasedStrategicalPlannerFactory<LaneBasedStrategicalPlanner>, Serializable
31  {
32  
33      /** */
34      private static final long serialVersionUID = 20160811L;
35  
36      /** Factory for tactical planners. */
37      private final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory;
38  
39      /** Characteristics factory. */
40      private final BehavioralCharacteristicsFactory behavioralCharacteristicsFactory;
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          this.behavioralCharacteristicsFactory = new BehavioralCharacteristicsFactoryDefault();
51      }
52  
53      /**
54       * Constructor with factory for tactical planners.
55       * @param tacticalPlannerFactory factory for tactical planners
56       * @param behavioralCharacteristicsFactory factory for behavioral characteristics
57       */
58      public LaneBasedStrategicalRoutePlannerFactory(
59              final LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> tacticalPlannerFactory,
60              final BehavioralCharacteristicsFactory behavioralCharacteristicsFactory)
61      {
62          this.tacticalPlannerFactory = tacticalPlannerFactory;
63          this.behavioralCharacteristicsFactory = behavioralCharacteristicsFactory;
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public final LaneBasedStrategicalPlanner create(final LaneBasedGTU gtu, final Route route) throws GTUException
69      {
70          BehavioralCharacteristics behavioralCharacteristics = this.tacticalPlannerFactory.getDefaultBehavioralCharacteristics();
71          try
72          {
73              this.behavioralCharacteristicsFactory.setValues(behavioralCharacteristics, gtu.getGTUType());
74          }
75          catch (ParameterException exception)
76          {
77              throw new GTUException("Parameter was set to illegal value.", exception);
78          }
79          LaneBasedStrategicalRoutePlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(behavioralCharacteristics,
80                  this.tacticalPlannerFactory.create(gtu), route, gtu);
81          return strategicalPlanner;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final String toString()
87      {
88          return "LaneBasedStrategicalRoutePlannerFactory [tacticalPlannerFactory=" + this.tacticalPlannerFactory + "]";
89      }
90  
91  }