LaneBasedGtuTemplate.java

  1. package org.opentrafficsim.road.gtu.generator.characteristics;

  2. import org.djunits.value.vdouble.scalar.Length;
  3. import org.djunits.value.vdouble.scalar.Speed;
  4. import org.djutils.exceptions.Throw;
  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.GtuTemplate;
  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.  * 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://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  21.  */
  22. public class LaneBasedGtuTemplate extends GtuTemplate implements LaneBasedGtuCharacteristicsGenerator
  23. {
  24.     /** */
  25.     private static final long serialVersionUID = 20160101L;

  26.     /** Factory for the strategical planner. */
  27.     private final LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory;

  28.     /** Route Generator. */
  29.     private final Generator<Route> routeGenerator;

  30.     /**
  31.      * @param gtuType GtuType; The GtuType to make it identifiable.
  32.      * @param lengthGenerator Generator&lt;Length&gt;; Generator&lt;Length&gt; generator for the length of the GTU type
  33.      *            (parallel with driving direction).
  34.      * @param widthGenerator Generator&lt;Length&gt;; generator for the width of the GTU type (perpendicular to driving
  35.      *            direction).
  36.      * @param maximumSpeedGenerator Generator&lt;Speed&gt;; generator for the maximum speed of the GTU type (in the driving
  37.      *            direction).
  38.      * @param strategicalPlannerFactory LaneBasedStrategicalPlannerFactory&lt;?&gt;; Factory for the strategical planner (e.g.,
  39.      *            route determination)
  40.      * @param routeGenerator Generator&lt;Route&gt;; 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.      * Generate the properties of the next GTU.
  57.      * @return the LaneBasedGtuCharacteristics with a drawn perception, strategical planner, and initial speed.
  58.      * @throws ProbabilityException when a generator is improperly configured
  59.      * @throws ParameterException in case of a parameter problem.
  60.      */
  61.     @Override
  62.     public final LaneBasedGtuCharacteristics draw() throws ProbabilityException, ParameterException
  63.     {
  64.         return new LaneBasedGtuCharacteristics(super.draw(), this.strategicalPlannerFactory, this.routeGenerator.draw(), null,
  65.                 null, VehicleModel.MINMAX);
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     @SuppressWarnings("checkstyle:designforextension")
  70.     public String toString()
  71.     {
  72.         return String.format("LaneBasedGtuTemplate [%s, %s]", this.strategicalPlannerFactory,
  73.                 super.toString());
  74.     }

  75. }