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:
Generator<Duration>
for inter-arrival timesLaneBasedGtuCharacteristicsGenerator
throughasLaneBasedGtuCharacteristicsGenerator
GeneratorPositions
RoomChecker
Supplier<String>
for GTU ids
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opentrafficsim.road.gtu.generator.GeneratorPositions
GeneratorPositions.GeneratorLanePosition, GeneratorPositions.GeneratorLinkPosition, GeneratorPositions.GeneratorZonePosition, GeneratorPositions.LaneBias, GeneratorPositions.LaneBiases, GeneratorPositions.RoadPosition
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Destination column id.static final String
Front column id.static final String
GTU type column id.static final String
Id column id.static final String
Lane column id.static final String
Length column id.static final String
Link column id.static final String
Maximum acceleration column id.static final String
Maximum deceleration column id.static final String
Maximum speed column id.static final String
Origin column id.static final String
Position (on lane) column id.static final String
Route column id.static final String
Speed column id.static final String
Time column id.static final String
Width column id. -
Constructor Summary
ConstructorDescriptionInjections
(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) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns a characteristics generator view of the injections, as used byLaneBasedGtuGenerator
.canPlace
(SortedSet<HeadwayGtu> leaders, LaneBasedGtuCharacteristics characteristics, org.djunits.value.vdouble.scalar.Duration since, LanePosition initialPosition) Returns placement for injected GTUs, as used byLaneBasedGtuGenerator
.org.djunits.value.vdouble.scalar.Duration
draw()
draw
(GtuType gtuType, LaneBasedGtuCharacteristics characteristics, Map<CrossSectionLink, Map<Integer, Integer>> unplaced) Draw a new position to generate a GTU.get()
Returns all underlying positions.boolean
Returns whether the column of given id is present.
-
Field Details
-
TIME_COLUMN
Time column id.- See Also:
-
ID_COLUMN
Id column id.- See Also:
-
GTU_TYPE_COLUMN
GTU type column id.- See Also:
-
POSITION_COLUMN
Position (on lane) column id.- See Also:
-
LANE_COLUMN
Lane column id.- See Also:
-
LINK_COLUMN
Link column id.- See Also:
-
SPEED_COLUMN
Speed column id.- See Also:
-
ORIGIN_COLUMN
Origin column id.- See Also:
-
DESTINATION_COLUMN
Destination column id.- See Also:
-
ROUTE_COLUMN
Route column id.- See Also:
-
LENGTH_COLUMN
Length column id.- See Also:
-
WIDTH_COLUMN
Width column id.- See Also:
-
MAX_SPEED_COLUMN
Maximum speed column id.- See Also:
-
MAX_ACCELERATION_COLUMN
Maximum acceleration column id.- See Also:
-
MAX_DECELERATION_COLUMN
Maximum deceleration column id.- See Also:
-
FRONT_COLUMN
Front column id.- See Also:
-
-
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 IllegalArgumentExceptionConstructor. Depending on what information is provided in the injections table, some arguments may or should not benull
. In particular:- "time": always required, allows the
Injections
to be used as aGenerator<Duration>
. - "id": allows the
Injections
to be used as aSupplier<String>
for GTU ids. - "position", "lane", "link": allows the
Injections
to be used as aGeneratorPositions
, requires network. - "speed": allows the
Injections
to be used as aRoomChecker
, requires timeToCollision. - all other columns: allows the
Injections
to be used as aLaneBasedGtuCharacteristicsGenerator
throughasLaneBasedGtuCharacteristicsGenerator()
, requires gtuTypes, network, strategicalPlannerFactory and stream.
- Parameters:
table
- Table; table with at least a "time" column.network
- Network; network, may benull
.gtuTypes
- ImmutableMap<String, GtuType>; GTU types, as obtained fromDefinitions
, may benull
.strategicalPlannerFactory
- LaneBasedStrategicalPlannerFactory<?>; strategical planner factory, may benull
.stream
- StreamInterface; random number stream, may benull
.timeToCollision
- Duration; critical time-to-collision to allow GTU generation, may benull
.- Throws:
IllegalArgumentException
- when the right arguments are not provided for the columns in the injection table.
- "time": always required, allows the
-
-
Method Details
-
get
-
hasColumn
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 interfaceGenerator<org.djunits.value.vdouble.scalar.Duration>
- Throws:
ProbabilityException
org.opentrafficsim.base.parameters.ParameterException
-
asLaneBasedGtuCharacteristicsGenerator
Returns a characteristics generator view of the injections, as used byLaneBasedGtuGenerator
. 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
public GeneratorPositions.GeneratorLanePosition draw(GtuType gtuType, LaneBasedGtuCharacteristics characteristics, Map<CrossSectionLink, Map<Integer, throws GtuExceptionInteger>> unplaced) Draw a new position to generate a GTU.- Specified by:
draw
in interfaceGeneratorPositions
- 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
Returns all underlying positions.- Specified by:
getAllPositions
in interfaceGeneratorPositions
- 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 byLaneBasedGtuGenerator
. 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 interfaceLaneBasedGtuGenerator.RoomChecker
- Parameters:
leaders
- SortedSet<HeadwayGtu>; leaders, usually 1, possibly more after a branchcharacteristics
- LaneBasedGtuCharacteristics; characteristics of the proposed new GTUsince
- Duration; time since the GTU wanted to arriveinitialPosition
- 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 structureGtuException
- on parameter exception
-