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
    • Vehicle routing and its optimization
    • Huge-scale simulation using Chicago-Sketch dataset
  • Simulation Mechanism: Summary
  • Simulation Mechanism: Details
  • Technical Reference
    • uxsim.World
    • uxsim.Node
    • uxsim.Link
    • uxsim.Vehicle
    • uxsim.RouteChoice
    • uxsim.analyzer.Analyzer
    • uxsim.Route
    • uxsim.TaxiHandler.TripRequest
    • uxsim.TaxiHandler.TaxiHandler
    • uxsim.TaxiHandler.TaxiHandler_nearest
    • uxsim.OSMImporter.OSMImporter
    • 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, name, start_node, end_node, length, free_flow_speed=20, jam_density=0.2, jam_density_per_lane=None, number_of_lanes=1, merge_priority=1, signal_group=[0], capacity_out=None, capacity_in=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) – The name of the link.

  • 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, optinal) – User-defined custom function that is automatically called when 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

Notes

Traffic Flow Model:

  • The link model follows a multi-lane, single-pipe approach where FIFO is guaranteed per link and no lane changing occurs.

  • Fundamental diagram parameters such as free_flow_speed, jam_density (or jam_density_per_lane), and number_of_lanes determine the link’s flow characteristics. Reaction time of drivers REACTION_TIME is a grobal parameter.

  • Real-time link status for external reference is maintained with attributes speed, density, flow, num_vehicles, and num_vehicles_queue.

Traffic Flow Model Parameters:

  • Their definition is illustrated as https://toruseo.jp/UXsim/docs/_images/fundamental_diagram.png

  • If you are not familiar to the traffic flow theory, it is recommended that you adjust only free_flow_speed and number_of_lanes for the traffic flow model parameters, leaving the other parameters at their default values.

Capacity and Bottlenecks:

  • The capacity_out and capacity_in parameters set the outflow and inflow capacities of the link. If not provided, the capacities are unlimited.

  • These capacities can represent bottlenecks at the beginning or end of the link.

Connection to Node Model:

  • At the downstream end of a sending link, vehicles in all lanes have the right to be sent out, but FIFO order is maintained.

  • At the upstream end of a receiving link, all lanes can accept vehicles.

Parameter Adjustments:

  • Some traffic flow model parameters like free_flow_speed, jam_density, capacity_out, capacity_in, and merge_priority can be altered during simulation to reflect changing conditions.

Details on Multi-lane model:

  • Link model:
    • Multiple lanes with single-pipe model. FIFO is guaranteed per link. No lane changing.

    • Links have a lanes attribute representing the number of lanes.

    • Each vehicle has a lane attribute.

    • Each vehicle follows the leader vehicle in the same lane, i.e., the vehicle lanes steps ahead on the link.

  • Node model:
    • Sending links:
      • Vehicles in all lanes at the downstream end of the link have the right to be sent out.

      • However, to ensure link FIFO, vehicles are tried to be sent out in the order they entered the link. If a vehicle cannot be accepted, the outflow from that link stops.

    • Receiving links:
      • All lanes at the upstream end of the link can accept vehicles.

Details on Fundamental diagram parameters (+: input, ++: alternative input):

  • free_flow_speed (m/s)+

  • jam_density (veh/m/LINK)+

  • jam_density_per_lane (veh/m/lane)++

  • lanes, number_of_lane (lane)+

  • tau: y-intercept of link FD (s/veh*LINK)

  • REACTION_TIME, World.reaction_time (s/veh*lane)

  • w (m/s)

  • capacity (veh/s/LINK)

  • capacity_per_lane (veh/s/lane)

  • delta: minimum spacing (m/veh*LINK)

  • delta_per_lane: minimum spacing in lane (m/veh*lane)

  • q_star: capacity (veh/s/LINK)

  • k_star: critical density (veh/s/LINK)

  • capacity_in, capacity_out: bottleneck capacity at beginning/end of link (veh/s/LINK)+

  • Node.flow_capacity: node flow capacity (veh/s/LINK-LIKE)+

__init__(W, name, start_node, end_node, length, free_flow_speed=20, jam_density=0.2, jam_density_per_lane=None, number_of_lanes=1, merge_priority=1, signal_group=[0], capacity_out=None, capacity_in=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) – The name of the link.

  • 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, optinal) – User-defined custom function that is automatically called when 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

Notes

Traffic Flow Model:

  • The link model follows a multi-lane, single-pipe approach where FIFO is guaranteed per link and no lane changing occurs.

  • Fundamental diagram parameters such as free_flow_speed, jam_density (or jam_density_per_lane), and number_of_lanes determine the link’s flow characteristics. Reaction time of drivers REACTION_TIME is a grobal parameter.

  • Real-time link status for external reference is maintained with attributes speed, density, flow, num_vehicles, and num_vehicles_queue.

Traffic Flow Model Parameters:

  • Their definition is illustrated as https://toruseo.jp/UXsim/docs/_images/fundamental_diagram.png

  • If you are not familiar to the traffic flow theory, it is recommended that you adjust only free_flow_speed and number_of_lanes for the traffic flow model parameters, leaving the other parameters at their default values.

Capacity and Bottlenecks:

  • The capacity_out and capacity_in parameters set the outflow and inflow capacities of the link. If not provided, the capacities are unlimited.

  • These capacities can represent bottlenecks at the beginning or end of the link.

Connection to Node Model:

  • At the downstream end of a sending link, vehicles in all lanes have the right to be sent out, but FIFO order is maintained.

  • At the upstream end of a receiving link, all lanes can accept vehicles.

Parameter Adjustments:

  • Some traffic flow model parameters like free_flow_speed, jam_density, capacity_out, capacity_in, and merge_priority can be altered during simulation to reflect changing conditions.

Details on Multi-lane model:

  • Link model:
    • Multiple lanes with single-pipe model. FIFO is guaranteed per link. No lane changing.

    • Links have a lanes attribute representing the number of lanes.

    • Each vehicle has a lane attribute.

    • Each vehicle follows the leader vehicle in the same lane, i.e., the vehicle lanes steps ahead on the link.

  • Node model:
    • Sending links:
      • Vehicles in all lanes at the downstream end of the link have the right to be sent out.

      • However, to ensure link FIFO, vehicles are tried to be sent out in the order they entered the link. If a vehicle cannot be accepted, the outflow from that link stops.

    • Receiving links:
      • All lanes at the upstream end of the link can accept vehicles.

Details on Fundamental diagram parameters (+: input, ++: alternative input):

  • free_flow_speed (m/s)+

  • jam_density (veh/m/LINK)+

  • jam_density_per_lane (veh/m/lane)++

  • lanes, number_of_lane (lane)+

  • tau: y-intercept of link FD (s/veh*LINK)

  • REACTION_TIME, World.reaction_time (s/veh*lane)

  • w (m/s)

  • capacity (veh/s/LINK)

  • capacity_per_lane (veh/s/lane)

  • delta: minimum spacing (m/veh*LINK)

  • delta_per_lane: minimum spacing in lane (m/veh*lane)

  • q_star: capacity (veh/s/LINK)

  • k_star: critical density (veh/s/LINK)

  • capacity_in, capacity_out: bottleneck capacity at beginning/end of link (veh/s/LINK)+

  • Node.flow_capacity: node flow capacity (veh/s/LINK-LIKE)+

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

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

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)[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)[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

departure_count(t)[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)[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

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.departure_count()
      • Link.in_out_flow_constraint()
      • Link.init_after_tmax_fix()
      • Link.instant_travel_time()
      • Link.set_traveltime_instant()
      • Link.update()