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