AnyLogic
Expand
Font size

CarSource

CarSource is the block that generates cars and tries to put them into the specified location inside a road network. This block doesn’t have a buffer, so if the car has not been generated at the appropriate time, it will not happen later on.

The car can appear on the specified road or in the specified parking lot (defined by the Appears parameter).

The car does not immediately appear at the specified location. It appears and starts movement only when there is enough space at the specified position of road to prevent collision.

Arrivals of cars can be defined by:

  • interarrival times
  • arrival rate
  • rate schedule
  • arrivals schedule that defines the exact number of cars and times of their arrival
  • call of the inject() function of the CarSource block

Just like in Source block, you can limit the number of arrivals.

If cars are set to appear on a road, the direction of the road should be additionally specified. Cars will appear at the beginning of the specified road and start moving in the specified direction. By default, Random lane parameter is selected, so the cars will appear at random lanes (if there is more than 1 lane in the specified direction on the road). You can explicitly specify index of lane where cars will appear by deselecting the Random lane option and using Lane index parameter.

If cars are set to appear on a road, they enter the road network only when there is enough distance on the lane ahead of the car. The more initial velocity of the car, the longer distance is needed for a car to safely enter the network. Cars that cannot enter the road network immediately, are not created at all, which may cause the CarSource to generate less cars than specified in the Arrival rate parameter.

If cars are set to appear in a parking lot, they appear in free spaces of the specified parking lot and wait until they leave the road network or start moving by entering CarMoveTo block. If all parking spaces are occupied, an error will be generated.

Demo model: CarSource Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

Parameters

Arrivals defined by
Specifies the mode of cars generation:
Rate — Cars are generated at the specified arrival Arrival rate (which is equivalent to exponentially distributed interarrival time with mean = 1/Arrival rate).
Interarrival time — The time between two subsequent cars is defined by the specified expression.
Arrival table in Database — Agents are generated according to the records in the specified database table. You specify the table below in the Database table parameter, then select the table column containing the arrival moments in the Arrival date drop-down list. The block will generate one agent per each data record in the specified table.
Rate schedule — Cars are generated according to the schedule defining how the Arrival rate of cars changes with time.
Arrival schedule — Cars are generated at exact times defined in the arrival schedule.
Calls of inject() function — Cars are not generated automatically and are only generated on calls of inject() function.
Get value: arrivalType
Set new value at runtime: set_arrivalType(new value)
Valid values:
CarSource.RATE
CarSource.INTERARRIVAL_TIME
Source.DATABASE_ARRIVAL_TABLE
CarSource.RATE_SCHEDULE
CarSource.ARRIVAL_SCHEDULE
CarSource.MANUAL
Interarrival time
[Visible and applies only if the Arrivals defined by: Interarrival time option is set]
Expression used to evaluate the delay time for each arriving car.
Value type: double
Arrival schedule
[Visible and applies only if the Arrivals defined by: Arrival schedule option is set]
The name of the schedule with integer value type containing times of car arrivals. Typically, the value column would contain 1 as one car is generated at a time.
Syntax: Schedule<Integer> arrivalSchedule
Set new value at runtime: set_arrivalSchedule(new value)
Database table
[Visible if Arrivals defined by: Arrival table in Database]
Specify the database table containing the data on agent arrivals.
Arrival date
[Visible if Arrivals defined by: Arrival table in Database]
Specify the column of the Database table that contains the agent arrival timestamps.
Arrival rate
[Visible and applies only if the Arrivals defined by: Rate option is set]
The arrival Arrival rate of cars. If Arrival rate is used and it becomes 0, no next arrival will be scheduled until the Arrival rate changes to a positive value.
Syntax: double rate
Set new value at runtime: set_rate(new value)
Rate schedule
[Visible and applies only if the Arrivals defined by: Rate schedule option is set]
The name of the schedule defining how the Arrival rate of cars changes with time.
Syntax: Schedule<Integer> rateSchedule
Set new value at runtime: set_rateSchedule(new value)
Modify rate
[Visible and applies only if the Arrivals defined by Rate schedule option is set]
Enables or disables ability to specify the expression, according to which Arrival rate is modified. The expression is defined in Rate expression parameter below.
Syntax: boolean modifyRate
Set new value at runtime: set_modifyRate(new value)
Rate expression
[Visible and applies only if the Modify rate option is set]
Expression defining arrival rate modification.
Value type: double
Local variable: double baseRate — The current rate value taken from the specified rate schedule
Set agent parameters from DB
[Visible and applies if Arrivals defined by option is not set to Arrival table in Database or Calls of inject() function]
If the option is selected (true), enables initialization of cars' parameters from the specified Database table. The similar technique is described here for agents generated by Source block.
Syntax: boolean setAgentParametersFromDB
Set new value at runtime: set_setAgentParametersFromDB(new value)
Database table
[Visible and applies only if the Set agent parameters from DB option is set]
Specify the database table containing the data on car arrivals.
Syntax: TableInput databaseTable
Set new value at runtime: set_databaseTable(new value)
Limited number of arrivals
[Visible and applies if Arrivals defined by option isn’t set to Calls of inject() function]
If true, the number of arrivals will be limited to Maximum number of arrivals.
Syntax: boolean limitArrivals
Set new value at runtime: set_limitArrivals(new value)
Maximum number of arrivals
[Visible and applies only if the Limited number of arrivals option is set]
The maximum number of cars to be generated by this block.
Syntax: int maxArrivals
Set new value at runtime: set_maxArrivals(new value)
Appears
Here you select where the cars generated by this block will appear: on road, or in parking lot.
on road — The cars will be placed at the beginning of the road specified below in the Road parameter.
in parking lot — The cars will be placed in a randomly chosen free parking space of the parking lot specified below in the Parking lot parameter.
Get value: appears
Set new value at runtime: set_appears(new value)
Valid values:
CarSource.ON_ROAD
CarSource.IN_PARKING_LOT
Road
[Visible and applies only if the on Road option is set]
Road where the car will be placed after start of movement. The car enters the Road at the specified lane (forward lane or backward lane). Lane is specified by the Enters parameter below. Lane is picked randomly (if Random lane option is enabled), or specified explicitly at Lane index parameter below.
Value type: Road
Local variable: car — The car that is being created by this block.
Enters
[Visible and applies only if the option Appears: on road is selected]
Specifies the lane (forward lane or backward lane) of road in which the car will be placed. If the road does not have the specified lane (i.e. is one-way), the error is generated.
Get value: laneDirection
Set new value at runtime: set_laneDirection(new value)
Valid values:
CarSource.FORWARD_LANE
CarSource.BACKWARD_LANE
Random lane
[Visible and applies only if the option Appears: on road is selected]
Specifies whether the car will be placed in randomly selected lane of the road. If this option is disabled, the lane will be specified by Lane index parameter below.
Syntax: boolean isRandomLane
Set new value at runtime: set_isRandomLane(new value)
Lane index
[Visible and applies only if the Random lane option is not selected]
Specifies the index of lane where the car should be placed. Lane indices start with 0 (the outmost lane) and increase to inmost lane. If the specified Road does not have the lane with the specified index, an error is generated.
Value type: int
Local variable: car — The car agent that is being created by this block.
Parking lot
[Visible and applies only if the option Appears: in parking lot is selected]
Parking lot where car will be placed immediately after entering this block. If parking lot does not have free parking spaces, the error will be generated. The car will not move from parking space until it is sent to some destination by CarMoveTo block.
Value type: ParkingLot
Local variable: car — The car that is being created by this block.

Car

New car
The car type created by this CarSource block. (This type should have the option that it is used in flowcharts as car.)
Value type: Agent
Length
Length of the generated car. Length must be > 0.
Value type: double
Local variable: car — The car that is being generated by this block
Initial speed
Initial speed of the generated car. Initial speed must be >=0. If initial speed is less than preferred speed, the car will start accelerating to its preferred speed once it is sent to some destination by CarMoveTo block.
Value type: double
Local variable: car — The car that is being generated by this block
Preferred speed
Preferred speed of the generated car. Preferred speed must be >=0. If preferred speed is equal to 0 and initial speed is equal to 0, the car will not start movement even if it is sent to some destination by CarMoveTo block. Car will only start accelerating when positive initial speed is assigned to it by call of setPreferredSpeed(speed) method.
The car always tries to move with speed equal to its preferred speed. The following factors prevent car from moving with its preferred speed:
  • Inability to accelerate or decelerate immediately to the preferred speed
  • Car ahead that is moving slower that the preferred speed of the car
  • Stop line with red light ahead
  • Closeness to parking space or bus stop, where the car should decelerate to park or stop
  • Speed limit
  • Value type: double
    Local variable: car — The car that is being generated by this block
    Max acceleration
    Maximum acceleration of the generated car. Maximum acceleration should be > 0.
    Value type: double
    Local variable: car — The car that is being generated by this block
    Max deceleration
    Maximum deceleration of the generated car. Maximum deceleration should be > 0. The car decelerates with its maximum deceleration only in emergency cases. At other times, it uses some fraction of max deceleration.
    Value type: double
    Local variable: car — The car that is being generated by this block

    Advanced

    Add cars to
    This parameter specifies where the cars created by this block will be stored: in the default population of root agent, or in some custom population (specified below in the Car population property).
    Syntax: boolean addCarToCustomPopulation
    Set new value at runtime: set_addCarToCustomPopulation(new value)
    Valid values:
    false
    true
    Car population
    [Visible and applies only if the Add cars to: custom population option is selected]
    The name of the agent population where the cars created by this block will be stored.
    Value type: <Agent> List
    Local variable: car — Agent that is being created by this block.

    Actions

    On exit
    Code that is executed when car exits this block.
    Local variable: car — The car that exits this block

    Functions

    Generating cars
    Function Description
    void inject() Generates a single car at the time of call. Can be applied if Arrivals defined by: calls of inject() function option is selected.
    void inject(int n) Generates the specified number of cars (n) at the time of call. Can be applied if Arrivals defined by: calls of inject() function option is selected.

    n — The number of cars that must be generated per one call.

    Ports

    out
    The output port.
    How can we improve this article?