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.GtuTemplate;
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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
23   */
24  public class LaneBasedGtuTemplate extends GtuTemplate implements LaneBasedGtuCharacteristicsGenerator
25  {
26      /** */
27      private static final long serialVersionUID = 20160101L;
28  
29      /** Factory for the strategical planner. */
30      private final LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory;
31  
32      /** Route Generator. */
33      private final Generator<Route> routeGenerator;
34  
35      /**
36       * @param gtuType GtuType; The GtuType to make it identifiable.
37       * @param lengthGenerator Generator&lt;Length&gt;; Generator&lt;Length&gt; generator for the length of the GTU type
38       *            (parallel with driving direction).
39       * @param widthGenerator Generator&lt;Length&gt;; generator for the width of the GTU type (perpendicular to driving
40       *            direction).
41       * @param maximumSpeedGenerator Generator&lt;Speed&gt;; generator for the maximum speed of the GTU type (in the driving
42       *            direction).
43       * @param strategicalPlannerFactory LaneBasedStrategicalPlannerFactory&lt;?&gt;; Factory for the strategical planner (e.g.,
44       *            route determination)
45       * @param routeGenerator Generator&lt;Route&gt;; route generator
46       * @throws NullPointerException when one or more parameters are null
47       */
48      @SuppressWarnings("checkstyle:parameternumber")
49      public LaneBasedGtuTemplate(final GtuType gtuType, final Generator<Length> lengthGenerator,
50              final Generator<Length> widthGenerator, final Generator<Speed> maximumSpeedGenerator,
51              final LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory, final Generator<Route> routeGenerator)
52              throws NullPointerException
53      {
54          super(gtuType, lengthGenerator, widthGenerator, maximumSpeedGenerator);
55          Throw.whenNull(strategicalPlannerFactory, "strategicalPlannerFactory is null");
56          Throw.whenNull(routeGenerator, "Route generator is null");
57          this.strategicalPlannerFactory = strategicalPlannerFactory;
58          this.routeGenerator = routeGenerator;
59      }
60  
61      /**
62       * Generate the properties of the next GTU.
63       * @return the LaneBasedGtuCharacteristics with a drawn perception, strategical planner, and initial speed.
64       * @throws ProbabilityException when a generator is improperly configured
65       * @throws ParameterException in case of a parameter problem.
66       */
67      @Override
68      public final LaneBasedGtuCharacteristics draw() throws ProbabilityException, ParameterException
69      {
70          return new LaneBasedGtuCharacteristics(super.draw(), this.strategicalPlannerFactory, this.routeGenerator.draw(), null,
71                  null, VehicleModel.MINMAX);
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      @SuppressWarnings("checkstyle:designforextension")
77      public String toString()
78      {
79          return String.format("LaneBasedGtuTemplate [%s, %s]", this.strategicalPlannerFactory,
80                  super.toString());
81      }
82  
83  }