uxsim.Link¶
- class uxsim.Link(W: World, name: str, start_node: Node | str, end_node: Node | str, length: float, free_flow_speed: float = 20, jam_density: float = 0.2, jam_density_per_lane: float | None = None, number_of_lanes: int = 1, merge_priority: float = 1, signal_group: list[int] = [0], capacity_out: float | None = None, capacity_in: float | None = None, eular_dx=None, attribute=None, user_attribute=None, user_function=None, auto_rename=False)[source]¶
Link in a network.
Create a link.
- Parameters:
W (object) – The world to which the link belongs.
name (str | None) – The name of the link. If None, the name is automatically generated as “{start_node.name}-{end_node.name}”.
start_node (str | Node) – The name of the start node of the link.
end_node (str | Node) – The name of the end node of the link.
length (float) – The length of the link.
free_flow_speed (float, optional) – The free flow speed on the link, default is 20.
jam_density (float, optional) – The jam density on the link, default is 0.2. If jam_density_per_lane is specified, this value is ignored.
jam_density_per_lane (float, optional) – The jam density per lane on the link. If specified, it overrides the jam_density value.
number_of_lanes (int, optional) – The number of lanes on the link, default is 1.
merge_priority (float, optional) – The priority of the link when merging at the downstream node, default is 1.
signal_group (int or list, optional) – The signal group(s) to which the link belongs, default is 0. If signal_group is int, say 0, it becomes green if end_node.signal_phase is 0. If signal_group is list, say [0,1], it becomes green if the end_node.signal_phase is 0 or 1.
capacity_out (float, optional) – The capacity out of the link, default is calculated based on other parameters.
capacity_in (float, optional) – The capacity into the link, default is calculated based on other parameters.
eular_dx (float, optional) – The space aggregation size for link traffic state computation, default is 1/10 of link length or free flow distance per simulation step, whichever is larger.
attribute (any, optional) – Additional (meta) attributes defined by users.
user_attribute (any, optional) – Additional (meta) attributes defined by users. Same functionality to attribute, but with more understandable name.
user_function (func, optional) –
User-defined custom function that is automatically called when the timestep is incremented (more precisely, when update() is called). It takes only one argument: the Link object itself. Example: The following code prints the current number of vehicles on the link at each timestep. If user_function=None (default), no functions will be executed.
>>> def user_function(link): >>> print(len(link.vehicles)) >>> W = World(...) >>> W.addLink("link", "node1", "node2, 1000, user_function=user_function) >>> ... #define your scenario >>> W.exec_simulation()
auto_rename (bool, optional) – Whether to automatically rename the link if the name is already used. Default is False (raise an exception).
- speed¶
Average speed of traffic on the link.
- Type:
float
- density¶
Density of traffic on the link.
- Type:
float
- flow¶
Flow of traffic on the link.
- Type:
float
- num_vehicles¶
Number of vehicles on the link.
- Type:
float
- num_vehicles_queue¶
Number of slow vehicles (due to congestion) on the link.
- Type:
float
- free_flow_speed¶
Free flow speed of the link.
- Type:
float
- jam_density¶
Jam density of the link.
- Type:
float
- capacity_out¶
Capacity for outflow from the link.
- Type:
float
- capacity_in¶
Capacity for inflow to the link.
- Type:
float
- merge_priority¶
The priority of the link when merging at the downstream node.
- Type:
float
- __init__(W: World, name: str, start_node: Node | str, end_node: Node | str, length: float, free_flow_speed: float = 20, jam_density: float = 0.2, jam_density_per_lane: float | None = None, number_of_lanes: int = 1, merge_priority: float = 1, signal_group: list[int] = [0], capacity_out: float | None = None, capacity_in: float | None = None, eular_dx=None, attribute=None, user_attribute=None, user_function=None, auto_rename=False)[source]¶
Create a link.
- Parameters:
W (object) – The world to which the link belongs.
name (str | None) – The name of the link. If None, the name is automatically generated as “{start_node.name}-{end_node.name}”.
start_node (str | Node) – The name of the start node of the link.
end_node (str | Node) – The name of the end node of the link.
length (float) – The length of the link.
free_flow_speed (float, optional) – The free flow speed on the link, default is 20.
jam_density (float, optional) – The jam density on the link, default is 0.2. If jam_density_per_lane is specified, this value is ignored.
jam_density_per_lane (float, optional) – The jam density per lane on the link. If specified, it overrides the jam_density value.
number_of_lanes (int, optional) – The number of lanes on the link, default is 1.
merge_priority (float, optional) – The priority of the link when merging at the downstream node, default is 1.
signal_group (int or list, optional) – The signal group(s) to which the link belongs, default is 0. If signal_group is int, say 0, it becomes green if end_node.signal_phase is 0. If signal_group is list, say [0,1], it becomes green if the end_node.signal_phase is 0 or 1.
capacity_out (float, optional) – The capacity out of the link, default is calculated based on other parameters.
capacity_in (float, optional) – The capacity into the link, default is calculated based on other parameters.
eular_dx (float, optional) – The space aggregation size for link traffic state computation, default is 1/10 of link length or free flow distance per simulation step, whichever is larger.
attribute (any, optional) – Additional (meta) attributes defined by users.
user_attribute (any, optional) – Additional (meta) attributes defined by users. Same functionality to attribute, but with more understandable name.
user_function (func, optional) –
User-defined custom function that is automatically called when the timestep is incremented (more precisely, when update() is called). It takes only one argument: the Link object itself. Example: The following code prints the current number of vehicles on the link at each timestep. If user_function=None (default), no functions will be executed.
>>> def user_function(link): >>> print(len(link.vehicles)) >>> W = World(...) >>> W.addLink("link", "node1", "node2, 1000, user_function=user_function) >>> ... #define your scenario >>> W.exec_simulation()
auto_rename (bool, optional) – Whether to automatically rename the link if the name is already used. Default is False (raise an exception).
- speed¶
Average speed of traffic on the link.
- Type:
float
- density¶
Density of traffic on the link.
- Type:
float
- flow¶
Flow of traffic on the link.
- Type:
float
- num_vehicles¶
Number of vehicles on the link.
- Type:
float
- num_vehicles_queue¶
Number of slow vehicles (due to congestion) on the link.
- Type:
float
- free_flow_speed¶
Free flow speed of the link.
- Type:
float
- jam_density¶
Jam density of the link.
- Type:
float
- capacity_out¶
Capacity for outflow from the link.
- Type:
float
- capacity_in¶
Capacity for inflow to the link.
- Type:
float
- merge_priority¶
The priority of the link when merging at the downstream node.
- Type:
float
Methods
__init__(W, name, start_node, end_node, length)Create a link.
Get actual travel time of vehicle who enters this link on time t.
Get cumulative vehicle count of arrival to this link on time t.
Get average density of this link on time t.
average_flow(t)Get average flow of this link on time t.
Get average speed (=inverse of instantaneous travel time) of this link on time t.
change_free_flow_speed(new_value)change_jam_density(new_value)Get cumulative vehicle count of departure from this link on time t.
Link capacity updates.
Initalization before simulation execution.
Get instantaneous travel time of this link on time t.
Get number of vehicles on this link on time t.
Compute instantaneous travel time.
update()Make necessary updates when the timestep is incremented.
Attributes
- actual_travel_time(t: float) float[source]¶
Get actual travel time of vehicle who enters this link on time t. Note that small error may occur due to fractional processing.
- Parameters:
t (float) – Time in seconds.
- Returns:
The actual travel time.
- Return type:
float
- arrival_count(t: float) float[source]¶
Get cumulative vehicle count of arrival to this link on time t.
- Parameters:
t (float) – Time in seconds.
- Returns:
The cumulative arrival vehicle count.
- Return type:
float
- average_density(t: float) float[source]¶
Get average density of this link on time t.
- Parameters:
t (float) – Time in seconds.
- Returns:
The average density.
- Return type:
float
- average_flow(t: float) float[source]¶
Get average flow of this link on time t.
- Parameters:
t (float) – Time in seconds.
- Returns:
The average flow.
- Return type:
float
- average_speed(t: float) float[source]¶
Get average speed (=inverse of instantaneous travel time) of this link on time t.
- Parameters:
t (float) – Time in seconds.
- Returns:
The instantaneous travel time.
- Return type:
float
- departure_count(t: float) float[source]¶
Get cumulative vehicle count of departure from this link on time t.
- Parameters:
t (float) – Time in seconds.
- Returns:
The cumulative departure vehicle count.
- Return type:
float
- instant_travel_time(t: float) float[source]¶
Get instantaneous travel time of this link on time t.
- Parameters:
t (float) – Time in seconds.
- Returns:
The instantaneous travel time.
- Return type:
float