View Javadoc
1   package org.opentrafficsim.road.gtu.generator.od;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.opentrafficsim.base.parameters.ParameterTypes;
5   import org.opentrafficsim.core.gtu.GTUException;
6   import org.opentrafficsim.core.gtu.GTUType.DEFAULTS;
7   import org.opentrafficsim.core.network.Node;
8   import org.opentrafficsim.core.parameters.ParameterFactoryByType;
9   import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlanner;
10  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlannerFactory;
11  import org.opentrafficsim.road.gtu.lane.tactical.following.IDMPlusFactory;
12  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.DefaultLMRSPerceptionFactory;
13  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.LMRSFactory;
14  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
15  import org.opentrafficsim.road.gtu.strategical.od.Category;
16  import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlannerFactory;
17  import org.opentrafficsim.road.gtu.strategical.route.RouteGeneratorOD;
18  
19  import nl.tudelft.simulation.jstats.streams.StreamInterface;
20  
21  /**
22   * Supplies a strategical planner factory within DefaultGTUCharacteristicsGeneratorOD.
23   * <p>
24   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
26   * <p>
27   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 26 mrt. 2018 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
31   */
32  public interface StrategicalPlannerFactorySupplierOD
33  {
34  
35      /**
36       * Supplies a strategical factory.
37       * @param origin Node; origin
38       * @param destination Node; destination
39       * @param category Category; category (GTU type, route, or more)
40       * @param randomStream StreamInterface; stream for random numbers
41       * @return LaneBasedGTUCharacteristics
42       * @throws GTUException if characteristics could not be generated for the GTUException
43       */
44      LaneBasedStrategicalPlannerFactory<?> getFactory(Node origin, Node destination, Category category,
45              StreamInterface randomStream) throws GTUException;
46  
47      /**
48       * Returns a standard implementation for LMRS.
49       * @return standard implementation for LMRS
50       */
51      static StrategicalPlannerFactorySupplierOD lmrs()
52      {
53          return new StrategicalPlannerFactorySupplierOD()
54          {
55              /** {@inheritDoc} */
56              @Override
57              public LaneBasedStrategicalPlannerFactory<?> getFactory(final Node origin, final Node destination,
58                      final Category category, final StreamInterface randomStream) throws GTUException
59              {
60                  ParameterFactoryByType params = new ParameterFactoryByType();
61                  params.addParameter(origin.getNetwork().getGtuType(DEFAULTS.TRUCK), ParameterTypes.A,
62                          Acceleration.createSI(0.4));
63                  return new LaneBasedStrategicalRoutePlannerFactory(
64                          new LMRSFactory(new IDMPlusFactory(randomStream), new DefaultLMRSPerceptionFactory()), params,
65                          RouteGeneratorOD.getDefaultRouteSupplier(randomStream));
66              }
67          };
68      }
69  
70      /**
71       * Returns a {@code StrategicalPlannerFactorySupplierOD} using a {@code LaneBasedStrategicalRoutePlannerFactory} with a
72       * tactical planner factory based on the given supplier. Simulations using this strategical level can be more easily
73       * specified in this manner.
74       * @param tacticalPlannerFactorySupplierOD TacticalPlannerFactorySupplierOD; tactical planner factory based on OD
75       *            information
76       * @return strategical factory with default strategical layer and specified tactical layer
77       */
78      static StrategicalPlannerFactorySupplierOD route(final TacticalPlannerFactorySupplierOD tacticalPlannerFactorySupplierOD)
79      {
80          return new StrategicalPlannerFactorySupplierOD()
81          {
82              /** {@inheritDoc} */
83              @Override
84              public LaneBasedStrategicalPlannerFactory<?> getFactory(final Node origin, final Node destination,
85                      final Category category, final StreamInterface randomStream) throws GTUException
86              {
87                  return new LaneBasedStrategicalRoutePlannerFactory(
88                          tacticalPlannerFactorySupplierOD.getFactory(origin, destination, category, randomStream));
89              }
90          };
91      }
92  
93      /**
94       * Interface for tactical factory supplier based on OD information. This class is used by strategical factories where only
95       * the strategical level is specified but where the lower levels can be specified.
96       * <p>
97       * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
98       * <br>
99       * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
100      * <p>
101      * @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 jan. 2019 <br>
102      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
103      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
104      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
105      */
106     public interface TacticalPlannerFactorySupplierOD
107     {
108         /**
109          * Returns a tactical planner factory based on OD information.
110          * @param origin Node; origin
111          * @param destination Node; destination
112          * @param category Category; OD category
113          * @param randomStream StreamInterface; random stream
114          * @return tactical planner factory based on OD information
115          */
116         LaneBasedTacticalPlannerFactory<? extends LaneBasedTacticalPlanner> getFactory(Node origin, Node destination,
117                 Category category, StreamInterface randomStream);
118     }
119 
120 }