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