Car Source

CarSource is the block that generates cars and tries to put them into the specified location inside a road network. The car can appear on the specified road or in the specified parking lot (defined by the Appears parameter).

Arrivals of cars can be defined by interarrival times, arrival rate, rate schedule or arrivals schedule – similarly to Source block. In addition, there is a "manual” mode when CarSource would generate a car only when its inject() function is called. Just like in Source, you can limit the number of arrivals.

To generate cars of custom car type defined by user, specify the name of this car type in the New car field.

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 on the specified 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 accumulated in queue inside CarSource block and taken from the queue when there is enough space in the specified lane to place a car.

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

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_TIMESource.DATABASE_ARRIVAL_TABLE; CarSource.RATE_SCHEDULE; CarSource.ARRIVAL_SCHEDULE; CarSource.MANUAL
Interarrival time [dynamic]
[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.
Type of value: 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 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 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 [dynamic]
[Visible and applies only if the Modify rate option is set] Expression defining arrival rate modification.
Type of value: 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] Enables or disables initialization of agents' parameters from Database table.
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 is not 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_ROADCarSource.IN_PARKING_LOT
Road [dynamic]
[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.
Note that car does not immediately appear at the specified location. The car appears and starts movement only when:
- there is enough space at the specified position of road to prevent collision, and
- the car is sent to some destination by CarMoveTo block.
Type of value: 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_LANECarSource.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 [dynamic]
[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.
Type of value: 
int
Local variable:  car - the car agent that is being created by this block.
Parking lot [dynamic]
[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.
Type of value: 
ParkingLot
Local variable:  car - the car that is being created by this block.
Car
New car [dynamic]
The car type created by this CarSource block. (This type should have the option that it is used in flowcharts as car.)
Type of value: Agent
Length [dynamic]
Length of the generated car. Length must be > 0.
Type of value: double
Local variable:  car - the car that is being generated by this block
Initial speed [dynamic]
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.
Type of value: double
Local variable:  car - the car that is being generated by this block
Preferred speed [dynamic]
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
Type of value: double
Local variable:  car - the car that is being generated by this block
Max acceleration [dynamic]
Maximum acceleration of the generated car. Maximum acceleration should be >0.
Type of value: double
Local variable:  car - the car that is being generated by this block
Max deceleration [dynamic]
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.
Type of value: 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: falsetrue
Car population [dynamic]
[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.
Type of value: 
AgentList
Local variable:  car - agent that is being created by this block.
Actions
On exit [code]
Code that is executed when car exits this block.
Local variable:  car - the car that exits this block

Functions

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. The function argument passes the number of cars that must be generated per one call. It is usually one car.

Ports

out
The output port.