Class LaneBasedGtuGenerator

java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.road.gtu.generator.LaneBasedGtuGenerator
All Implemented Interfaces:
Identifiable, EventProducer, GtuGenerator, NonLocatedObject

public class LaneBasedGtuGenerator extends LocalEventProducer implements GtuGenerator
Lane based GTU generator. This generator generates lane based GTUs using a LaneBasedTemplateGTUType. The template is used to generate a set of GTU characteristics at the times implied by the headway generator. These sets are queued until there is sufficient room to construct a GTU at the specified lane locations. The speed of a construction GTU may be reduced to ensure it does not run into its immediate leader GTU.

Copyright (c) 2013-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

    • GTU_GENERATED_EVENT

      public static final EventType GTU_GENERATED_EVENT
      Event of a generated GTU. Payload: LaneBasedGtu
  • Constructor Details

    • LaneBasedGtuGenerator

      public LaneBasedGtuGenerator(String id, Supplier<Duration> interarrivelTimeGenerator, LaneBasedGtuCharacteristicsGenerator laneBasedGtuCharacteristicsGenerator, GeneratorPositions generatorPositions, RoadNetwork network, OtsSimulatorInterface simulator, LaneBasedGtuGenerator.RoomChecker roomChecker, Supplier<String> idGenerator) throws nl.tudelft.simulation.dsol.SimRuntimeException, ParameterException, NetworkException
      Construct a new lane base GTU generator. If the ID generator is an instance of IdsWithCharacteristics and its hasIds() method returns true, IDs are assigned in order of GTU characteristics.
      Parameters:
      id - name of the new GTU generator
      interarrivelTimeGenerator - generator for the interval times between GTUs
      laneBasedGtuCharacteristicsGenerator - generator of the characteristics of each GTU
      generatorPositions - location and initial direction provider for all generated GTUs
      network - the OTS network that owns the generated GTUs
      simulator - simulator
      roomChecker - the way that this generator checks that there is sufficient room to place a new GTU
      idGenerator - id generator
      Throws:
      nl.tudelft.simulation.dsol.SimRuntimeException - when startTime lies before the current simulation time
      ParameterException - if drawing from the interarrival generator fails
      NetworkException - if the object could not be added to the network
  • Method Details

    • setNoLaneChangeDistance

      public void setNoLaneChangeDistance(Length noLaneChangeDistance)
      Sets the initial distance over which lane changes shouldn't be performed.
      Parameters:
      noLaneChangeDistance - initial distance over which lane changes shouldn't be performed
    • setBookkeeping

      public void setBookkeeping(LaneBookkeeping bookkeeping)
      Sets how lane bookkeeping at lane changes is done.
      Parameters:
      bookkeeping - how lane bookkeeping at lane changes is done
    • setErrorHandler

      public void setErrorHandler(GtuErrorHandler gtuErrorHandler)
      Sets the GTU error handler.
      Parameters:
      gtuErrorHandler - GTU error handler
    • setIdsInCharacteristicsOrder

      public void setIdsInCharacteristicsOrder(boolean idsInCharacteristicsOrder)
      Sets what order should be used for the ids. By default this is in the order of successful GTU generation. If however the id generator is an instance of IdsWithCharacteristics returning true for hasIds(), it is by default in the order of characteristics drawing.
      Parameters:
      idsInCharacteristicsOrder - ids in order of drawing characteristics, or successful generation otherwise.
    • queueGtu

      public final void queueGtu(LaneBasedGtuCharacteristics characteristics, Lane lane)
      Adds a GTU to the generation queue. This method ignores whether vehicle generation is enabled at the location. This allows an external party to govern (over some time) what vehicles are generated.
      Parameters:
      characteristics - characteristics of GTU to add to the queue
      lane - position to generate the GTU at
    • placeGtu

      public final void placeGtu(LaneBasedGtuCharacteristics characteristics, LanePosition position, Speed speed) throws NamingException, GtuException, NetworkException, nl.tudelft.simulation.dsol.SimRuntimeException
      Places a GTU, regardless of whether it has room. The user of this method should verify this is the case.
      Parameters:
      characteristics - characteristics
      position - position
      speed - speed
      Throws:
      NamingException - on exception
      GtuException - on exception
      NetworkException - on exception
      nl.tudelft.simulation.dsol.SimRuntimeException - on exception
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • getGeneratedGTUs

      public final long getGeneratedGTUs()
      Returns the number of generated GTUs.
      Returns:
      generatedGTUs.
    • getId

      public final String getId()
      Retrieve the id of this LaneBasedGtuGenerator.
      Specified by:
      getId in interface Identifiable
      Returns:
      the id of this LaneBasedGtuGenerator
    • disable

      public void disable(Duration start, Duration end, Lane lane) throws nl.tudelft.simulation.dsol.SimRuntimeException
      Disable the vehicle generator during the specific time. Underlying processes such as drawing characteristics and headways are continued, but simply will not result in the queuing of the GTU.
      Parameters:
      start - start time
      end - end time
      lane - lane to disable generation on
      Throws:
      nl.tudelft.simulation.dsol.SimRuntimeException - if time is incorrect
    • getFullId

      public String getFullId()
      Specified by:
      getFullId in interface NonLocatedObject
    • getPositions

      public Set<GtuGenerator.GtuGeneratorPosition> getPositions()
      Specified by:
      getPositions in interface GtuGenerator