View Javadoc
1   package org.opentrafficsim.road.gtu.generator.characteristics;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djunits.value.vdouble.scalar.Speed;
5   import org.djutils.exceptions.Throw;
6   import org.opentrafficsim.base.parameters.ParameterException;
7   import org.opentrafficsim.core.distributions.Generator;
8   import org.opentrafficsim.core.distributions.ProbabilityException;
9   import org.opentrafficsim.core.gtu.GTUType;
10  import org.opentrafficsim.core.gtu.TemplateGTUType;
11  import org.opentrafficsim.core.network.route.Route;
12  import org.opentrafficsim.road.gtu.lane.VehicleModel;
13  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
14  
15  /**
16   * Generate lane based GTUs using a template.
17   * <p>
18   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
22   * initial version Nov 29, 2015 <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   */
26  public class LaneBasedTemplateGTUType extends TemplateGTUType implements LaneBasedGTUCharacteristicsGenerator
27  {
28      /** */
29      private static final long serialVersionUID = 20160101L;
30  
31      /** Factory for the strategical planner. */
32      private final LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory;
33  
34      /** Route Generator. */
35      private final Generator<Route> routeGenerator;
36  
37      /** Generator for the initial speed of the next GTU. */
38      private Generator<Speed> initialSpeedGenerator;
39  
40      /**
41       * @param gtuType GTUType; The GTUType to make it identifiable.
42       * @param lengthGenerator Generator&lt;Length&gt;; Generator&lt;Length&gt; generator for the length of the GTU type
43       *            (parallel with driving direction).
44       * @param widthGenerator Generator&lt;Length&gt;; generator for the width of the GTU type (perpendicular to driving
45       *            direction).
46       * @param maximumSpeedGenerator Generator&lt;Speed&gt;; generator for the maximum speed of the GTU type (in the driving
47       *            direction).
48       * @param strategicalPlannerFactory LaneBasedStrategicalPlannerFactory&lt;?&gt;; Factory for the strategical planner (e.g.,
49       *            route determination)
50       * @param routeGenerator Generator&lt;Route&gt;; route generator
51       * @throws NullPointerException when one or more parameters are null
52       */
53      @SuppressWarnings("checkstyle:parameternumber")
54      public LaneBasedTemplateGTUType(final GTUType gtuType, final Generator<Length> lengthGenerator,
55              final Generator<Length> widthGenerator, final Generator<Speed> maximumSpeedGenerator,
56              final LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory, final Generator<Route> routeGenerator)
57              throws NullPointerException
58      {
59          super(gtuType, lengthGenerator, widthGenerator, maximumSpeedGenerator);
60          Throw.whenNull(strategicalPlannerFactory, "strategicalPlannerFactory is null");
61          Throw.whenNull(routeGenerator, "Route generator is null");
62          this.strategicalPlannerFactory = strategicalPlannerFactory;
63          this.routeGenerator = routeGenerator;
64      }
65  
66      /**
67       * Generate the properties of the next GTU.
68       * @return the LaneBasedGTUCharacteristics with a drawn perception, strategical planner, and initial speed.
69       * @throws ProbabilityException when a generator is improperly configured
70       * @throws ParameterException in case of a parameter problem.
71       */
72      @Override
73      public final LaneBasedGTUCharacteristics draw() throws ProbabilityException, ParameterException
74      {
75          return new LaneBasedGTUCharacteristics(super.draw(), this.strategicalPlannerFactory, this.routeGenerator.draw(), null,
76                  null, VehicleModel.MINMAX);
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      @SuppressWarnings("checkstyle:designforextension")
82      public String toString()
83      {
84          return String.format("LaneBasedGTUTemplate [%s, %s, %s]", this.strategicalPlannerFactory, this.initialSpeedGenerator,
85                  super.toString());
86      }
87  
88  }