LaneBasedTemplateGTUType.java

  1. package org.opentrafficsim.road.gtu.lane;

  2. import java.util.Set;

  3. import org.djunits.value.vdouble.scalar.Length;
  4. import org.djunits.value.vdouble.scalar.Speed;
  5. import org.opentrafficsim.core.Throw;
  6. import org.opentrafficsim.core.distributions.Generator;
  7. import org.opentrafficsim.core.distributions.ProbabilityException;
  8. import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
  9. import org.opentrafficsim.core.gtu.GTUType;
  10. import org.opentrafficsim.core.gtu.TemplateGTUType;
  11. import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
  12. import org.opentrafficsim.core.idgenerator.IdGenerator;
  13. import org.opentrafficsim.core.network.OTSNetwork;
  14. import org.opentrafficsim.road.gtu.lane.perception.LanePerceptionFull;
  15. import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
  16. import org.opentrafficsim.road.network.lane.DirectedLanePosition;

  17. /**
  18.  * Generate lane based GTUs using a template.
  19.  * <p>
  20.  * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  21.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  22.  * </p>
  23.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  24.  * initial version Nov 29, 2015 <br>
  25.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  26.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  27.  */
  28. public class LaneBasedTemplateGTUType extends TemplateGTUType implements LaneBasedGTUCharacteristicsGenerator
  29. {
  30.     /** */
  31.     private static final long serialVersionUID = 20160101L;

  32.     /** Generator for lane perception. */
  33.     private final Generator<LanePerceptionFull> perceptionGenerator;

  34.     /** Generator for the strategical planner. */
  35.     private final Generator<LaneBasedStrategicalPlanner> strategicalPlannerGenerator;

  36.     /** Generator for the initial speed of the next GTU. */
  37.     private Generator<Speed> initialSpeedGenerator;

  38.     /** Initial longitudinal positions of all generated GTUs. */
  39.     private Set<DirectedLanePosition> initialLongitudinalPositions;

  40.     /**
  41.      * @param gtuType The GTUType to make it identifiable.
  42.      * @param idGenerator IdGenerator; the id generator used to generate names for GTUs constructed using this TemplateGTUType.
  43.      *            Provide null to use the default id generator of AbstractGTU.
  44.      * @param lengthGenerator Generator&lt;Length&gt; generator for the length of the GTU type (parallel with driving
  45.      *            direction).
  46.      * @param widthGenerator Generator&lt;Length&gt;; generator for the width of the GTU type (perpendicular to driving
  47.      *            direction).
  48.      * @param maximumSpeedGenerator Generator&lt;Speed&gt;; generator for the maximum speed of the GTU type (in the driving
  49.      *            direction).
  50.      * @param simulator the simulator.
  51.      * @param strategicalPlannerGenerator Generator&lt;LaneBasedStrategicalPlanner&gt;; generator for the strategical planner
  52.      *            (e.g., route determination)
  53.      * @param perceptionGenerator Generator&lt;LanePerceptionFull&gt;; generator for the lane-based perception model of
  54.      *            generated GTUs
  55.      * @param initialLongitudinalPositions Set&lt;DirectedLanePosition&gt;; the initial lanes, directions and positions of
  56.      *            generated GTUs
  57.      * @param initialSpeedGenerator Generator&lt;Speed&gt;; the generator for the initial speed of generated GTUs
  58.      * @param network OTSNetwork; the network that all generated GTUs are registered in
  59.      * @throws NullPointerException when one or more parameters are null
  60.      */
  61.     @SuppressWarnings("checkstyle:parameternumber")
  62.     public LaneBasedTemplateGTUType(final GTUType gtuType, final IdGenerator idGenerator,
  63.             final Generator<Length> lengthGenerator, final Generator<Length> widthGenerator,
  64.             final Generator<Speed> maximumSpeedGenerator, final OTSDEVSSimulatorInterface simulator,
  65.             final Generator<LaneBasedStrategicalPlanner> strategicalPlannerGenerator,
  66.             final Generator<LanePerceptionFull> perceptionGenerator,
  67.             final Set<DirectedLanePosition> initialLongitudinalPositions, final Generator<Speed> initialSpeedGenerator,
  68.             final OTSNetwork network) throws NullPointerException
  69.     {
  70.         super(gtuType, idGenerator, lengthGenerator, widthGenerator, maximumSpeedGenerator, simulator, network);
  71.         Throw.whenNull(strategicalPlannerGenerator, "strategicalPlannerGenerator is null");
  72.         Throw.whenNull(perceptionGenerator, "perceptionGenerator is null");
  73.         Throw.whenNull(initialLongitudinalPositions, "initialLongitudinalPositions is null");
  74.         Throw.whenNull(initialSpeedGenerator, "initialSpeedGenerator is null");
  75.         this.strategicalPlannerGenerator = strategicalPlannerGenerator;
  76.         this.perceptionGenerator = perceptionGenerator;
  77.         this.initialLongitudinalPositions = initialLongitudinalPositions;
  78.         this.initialSpeedGenerator = initialSpeedGenerator;
  79.     }

  80.     /**
  81.      * Generate the properties of the next GTU.
  82.      * @return the LaneBasedGTUCharacteristics with a drawn perception, strategical planner, and initial speed.
  83.      * @throws ProbabilityException when a generator is improperly configured
  84.      * @throws ParameterException in case of a parameter problem.
  85.      */
  86.     public final LaneBasedGTUCharacteristics draw() throws ProbabilityException, ParameterException
  87.     {
  88.         return new LaneBasedGTUCharacteristics(super.draw(), this.perceptionGenerator.draw(),
  89.                 this.strategicalPlannerGenerator.draw(), this.initialSpeedGenerator.draw(), this.initialLongitudinalPositions);
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     @SuppressWarnings("checkstyle:designforextension")
  94.     public String toString()
  95.     {
  96.         return String.format("LaneBasedGTUTemplate [%s, %s, %s, %s, %s]", this.initialLongitudinalPositions,
  97.                 this.perceptionGenerator, this.strategicalPlannerGenerator, this.initialSpeedGenerator, super.toString());
  98.     }

  99. }