Class Injections

java.lang.Object
org.opentrafficsim.road.gtu.generator.Injections
All Implemented Interfaces:
Supplier<String>, Generator<org.djunits.value.vdouble.scalar.Duration>, GeneratorPositions, LaneBasedGtuGenerator.RoomChecker

public class Injections extends Object implements Generator<org.djunits.value.vdouble.scalar.Duration>, Supplier<String>, GeneratorPositions, LaneBasedGtuGenerator.RoomChecker
Injections can be used to have a large degree of control over GTU generation. Depending on the information provided in an injections table, this class may be used in conjunction with LaneBasedGtuGenerator as a:
  1. Generator<Duration> for inter-arrival times
  2. LaneBasedGtuCharacteristicsGenerator through asLaneBasedGtuCharacteristicsGenerator
  3. GeneratorPositions
  4. RoomChecker
  5. Supplier<String> for GTU ids
It is assumed that for each next GTU, first an inter-arrival time is requested. Functions 2 and 3 will not check order and simply return information from the current row in the injections table. Function 4 and 5 are tracked independently and asynchronous with the rest, as these occur at later times when GTUs are (attempted to be) placed.

Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Field Details

  • Constructor Details

    • Injections

      public Injections(org.djutils.data.Table table, Network network, org.djutils.immutablecollections.ImmutableMap<String,GtuType> gtuTypes, LaneBasedStrategicalPlannerFactory<?> strategicalPlannerFactory, nl.tudelft.simulation.jstats.streams.StreamInterface stream, org.djunits.value.vdouble.scalar.Duration timeToCollision) throws IllegalArgumentException
      Constructor. Depending on what information is provided in the injections table, some arguments may or should not be null. In particular:
      • "time": always required, allows the Injections to be used as a Generator<Duration>.
      • "id": allows the Injections to be used as a Supplier<String> for GTU ids.
      • "position", "lane", "link": allows the Injections to be used as a GeneratorPositions, requires network.
      • "speed": allows the Injections to be used as a RoomChecker, requires timeToCollision.
      • all other columns: allows the Injections to be used as a LaneBasedGtuCharacteristicsGenerator through asLaneBasedGtuCharacteristicsGenerator(), requires gtuTypes, network, strategicalPlannerFactory and stream.
      Time should be in increasing order. If length is provided, but no front, front will be 75% of the length.
      Parameters:
      table - Table; table with at least a "time" column.
      network - Network; network, may be null.
      gtuTypes - ImmutableMap<String, GtuType>; GTU types, as obtained from Definitions, may be null.
      strategicalPlannerFactory - LaneBasedStrategicalPlannerFactory<?>; strategical planner factory, may be null.
      stream - StreamInterface; random number stream, may be null.
      timeToCollision - Duration; critical time-to-collision to allow GTU generation, may be null.
      Throws:
      IllegalArgumentException - when the right arguments are not provided for the columns in the injection table.
  • Method Details

    • get

      public String get()
      Specified by:
      get in interface Supplier<String>
    • hasColumn

      public boolean hasColumn(String columnId)
      Returns whether the column of given id is present.
      Parameters:
      columnId - String; column id.
      Returns:
      boolean; whether the column of given id is present.
    • draw

      public org.djunits.value.vdouble.scalar.Duration draw() throws ProbabilityException, org.opentrafficsim.base.parameters.ParameterException
      Specified by:
      draw in interface Generator<org.djunits.value.vdouble.scalar.Duration>
      Throws:
      ProbabilityException
      org.opentrafficsim.base.parameters.ParameterException
    • asLaneBasedGtuCharacteristicsGenerator

      public LaneBasedGtuCharacteristicsGenerator asLaneBasedGtuCharacteristicsGenerator()
      Returns a characteristics generator view of the injections, as used by LaneBasedGtuGenerator. This requires at the least that a GTU type column, a strategical planner factory, a network, and a stream of random numbers are provided.
      Returns:
      LaneBasedGtuCharacteristicsGenerator; characteristics generator view of the injections.
    • draw

      Draw a new position to generate a GTU.
      Specified by:
      draw in interface GeneratorPositions
      Parameters:
      gtuType - GtuType; GTU type.
      characteristics - LaneBasedGtuCharacteristics; characteristics of the generated GTU.
      unplaced - Map<CrossSectionLink, Map<Integer, Integer>>; number of unplaced GTUs per lane, counting from the right and starting at 1.
      Returns:
      GeneratorLanePosition; new position to generate a GTU.
      Throws:
      GtuException - when the underlying structure is inconsistent for drawing
    • getAllPositions

      public Set<GeneratorPositions.GeneratorLanePosition> getAllPositions()
      Returns all underlying positions.
      Specified by:
      getAllPositions in interface GeneratorPositions
      Returns:
      all underlying positions.
    • canPlace

      public LaneBasedGtuGenerator.Placement canPlace(SortedSet<HeadwayGtu> leaders, LaneBasedGtuCharacteristics characteristics, org.djunits.value.vdouble.scalar.Duration since, LanePosition initialPosition) throws NetworkException, GtuException
      Returns placement for injected GTUs, as used by LaneBasedGtuGenerator. This needs speed to be provided in the injections, and a minimum time-to-collision value. Besides the time-to-collision value, the minimum headway for a successful placement is t*v + 3m, where t = 1s and v the generation speed.
      Specified by:
      canPlace in interface LaneBasedGtuGenerator.RoomChecker
      Parameters:
      leaders - SortedSet<HeadwayGtu>; leaders, usually 1, possibly more after a branch
      characteristics - LaneBasedGtuCharacteristics; characteristics of the proposed new GTU
      since - Duration; time since the GTU wanted to arrive
      initialPosition - LanePosition; initial position
      Returns:
      Speed; maximum safe speed, or null if a GTU with the specified characteristics cannot be placed at the current time
      Throws:
      NetworkException - this method may throw a NetworkException if it encounters an error in the network structure
      GtuException - on parameter exception