Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
UXsim: Traffic Simulation in Python v1 documentation
UXsim: Traffic Simulation in Python v1 documentation
  • Getting started
  • Tutorial and Examples
    • Step-by-step Tutorial
    • Tutorial on Traffic Signal
    • Advanced example
    • Signal control by PyTorch (DQN)
    • Network data import from OpenStreetMap
    • Taxi / Shared mobility
    • Dynamic Traffic Assignments: DUO, DUE, DSO
    • Huge-scale simulation using Chicago-Sketch dataset
  • Simulation Mechanism
  • Technical Reference
    • uxsim.World
    • uxsim.Node
    • uxsim.Link
    • uxsim.Vehicle
    • uxsim.RouteChoice
    • uxsim.analyzer.Analyzer
    • uxsim.Route
    • uxsim.DTAsolvers.SolverDUE
    • uxsim.DTAsolvers.SolverDSO_D2D
    • uxsim.TaxiHandler.TripRequest
    • uxsim.TaxiHandler.TaxiHandler
    • uxsim.TaxiHandler.TaxiHandler_nearest
    • uxsim.OSMImporter2.OSMImporter2
    • uxsim.ResultGUIViewer.ResultGUIViewer
    • uxsim.uxsim
    • uxsim.utils
    • uxsim.scenario_reader_writer
    • uxsim.ResultGUIViewer.ResultGUIViewer
    • uxsim.TaxiHandler.TaxiHandler
    • uxsim.Utilities.Utilities
Back to top
View this page

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.

actual_travel_time(t)

Get actual travel time of vehicle who enters this link on time t.

arrival_count(t)

Get cumulative vehicle count of arrival to this link on time t.

average_density(t)

Get average density of this link on time t.

average_flow(t)

Get average flow of this link on time t.

average_speed(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)

departure_count(t)

Get cumulative vehicle count of departure from this link on time t.

in_out_flow_constraint()

Link capacity updates.

init_after_tmax_fix()

Initalization before simulation execution.

instant_travel_time(t)

Get instantaneous travel time of this link on time t.

num_vehicles_t(t)

Get number of vehicles on this link on time t.

set_traveltime_instant()

Compute instantaneous travel time.

update()

Make necessary updates when the timestep is incremented.

Attributes

density

flow

num_vehicles

num_vehicles_queue

speed

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

in_out_flow_constraint()[source]¶

Link capacity updates.

init_after_tmax_fix()[source]¶

Initalization before simulation execution.

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

num_vehicles_t(t: float) → float[source]¶

Get number of vehicles on this link on time t.

Parameters:

t (float) – Time in seconds.

Returns:

The number of vehicles.

Return type:

float

set_traveltime_instant()[source]¶

Compute instantaneous travel time.

update()[source]¶

Make necessary updates when the timestep is incremented.

Next
uxsim.Vehicle
Previous
uxsim.Node
Copyright © 2023 Toru Seo
Made with Sphinx and @pradyunsg's Furo
On this page
  • uxsim.Link
    • Link
      • Link.speed
      • Link.density
      • Link.flow
      • Link.num_vehicles
      • Link.num_vehicles_queue
      • Link.free_flow_speed
      • Link.jam_density
      • Link.capacity_out
      • Link.capacity_in
      • Link.merge_priority
      • Link.__init__()
        • Link.speed
        • Link.density
        • Link.flow
        • Link.num_vehicles
        • Link.num_vehicles_queue
        • Link.free_flow_speed
        • Link.jam_density
        • Link.capacity_out
        • Link.capacity_in
        • Link.merge_priority
      • Link.actual_travel_time()
      • Link.arrival_count()
      • Link.average_density()
      • Link.average_flow()
      • Link.average_speed()
      • Link.departure_count()
      • Link.in_out_flow_constraint()
      • Link.init_after_tmax_fix()
      • Link.instant_travel_time()
      • Link.num_vehicles_t()
      • Link.set_traveltime_instant()
      • Link.update()