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.opentrafficsim.base.parameters.ParameterException;
6   import org.opentrafficsim.core.distributions.Generator;
7   import org.opentrafficsim.core.distributions.ProbabilityException;
8   import org.opentrafficsim.core.gtu.GTUType;
9   import org.opentrafficsim.core.gtu.TemplateGTUType;
10  import org.opentrafficsim.core.network.route.RouteGenerator;
11  import org.opentrafficsim.road.gtu.lane.VehicleModel;
12  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
13  
14  import nl.tudelft.simulation.language.Throw;
15  
16  /**
17   * Generate lane based GTUs using a template.
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/license.html">OpenTrafficSim License</a>.
21   * </p>
22   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
23   * initial version Nov 29, 2015 <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   */
27  public class LaneBasedTemplateGTUType extends TemplateGTUType implements LaneBasedGTUCharacteristicsGenerator
28  {
29      /** */
30      private static final long serialVersionUID = 20160101L;
31  
32      /** Factory for the strategical planner. */
33      private final LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory;
34  
35      /** Route Generator. */
36      private final RouteGenerator routeGenerator;
37  
38      /** Generator for the initial speed of the next GTU. */
39      private Generator<Speed> initialSpeedGenerator;
40  
41      /**
42       * @param gtuType The GTUType to make it identifiable.
43       * @param lengthGenerator Generator&lt;Length&gt; generator for the length of the GTU type (parallel with driving
44       *            direction).
45       * @param widthGenerator Generator&lt;Length&gt;; generator for the width of the GTU type (perpendicular to driving
46       *            direction).
47       * @param maximumSpeedGenerator Generator&lt;Speed&gt;; generator for the maximum speed of the GTU type (in the driving
48       *            direction).
49       * @param strategicalPlannerFactory Factory for the strategical planner (e.g., route determination)
50       * @param routeGenerator 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 RouteGenerator 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  }