uxsim.Node

class uxsim.Node(W: World, name: str, x: float, y: float, signal: list[float] = [0], signal_offset: float = 0, signal_offset_old: float | None = None, flow_capacity: float | None = None, number_of_lanes: int | None = None, auto_rename=False, attribute=None, user_attribute=None, user_function=None)[source]

Node in a network.

Create a node.

Parameters:
  • W (object) – The world to which the node belongs.

  • name (str) – The name of the node.

  • x (float) – The x-coordinate of the node (for visualization purposes).

  • y (float) – The y-coordinate of the node (for visualization purposes).

  • signal (list of float, optional) – A list representing the signal at the node. Default is [0], representing no signal. If a signal is present, the list contains the green times for each group. For example, `signal`=[60, 10, 50, 5] means that this signal has 4 phases, and green time for the 1st group is 60 s.

  • signal_offset (float, optional) – The offset of the signal. Default is 0.

  • signal_offset_old (float, optional) – The old parameter used to set offset of the signal prior to v1.8.1. This is the opposite of the usual definition of offset. Default is None, meaning signal_offset is used.

  • flow_capacity (float, optional) – The maximum flow capacity of the node. Default is None, meaning infinite capacity.

  • auto_rename (bool, optional) – Whether to automatically rename the node if the name is already used. Default is False.

  • number_of_lanes (int, optional) – The number of lanes that can be green simultaneously at the node. Default is None.

  • 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 Node object itself. Example: The following code prints the current number of incoming vehicles to the node at each timestep. If user_function=None (default), no functions will be executed.

    >>> def user_function(node):
    >>>     print(len(node.incoming_vehicles))
    >>> W = World(...)
    >>> W.addNode("node", 0, 0, user_function=user_function)
    >>> ... #define your scenario
    >>> W.exec_simulation()
    

signal_phase

The phase of current signal. Links that have the same signal_group have a green signal.

Type:

int

signal_t

The elapsed time since the current signal phase started. When it is larger than Link.signal[Link.signal_phase], the phase changes to the next one.

Type:

float

__init__(W: World, name: str, x: float, y: float, signal: list[float] = [0], signal_offset: float = 0, signal_offset_old: float | None = None, flow_capacity: float | None = None, number_of_lanes: int | None = None, auto_rename=False, attribute=None, user_attribute=None, user_function=None)[source]

Create a node.

Parameters:
  • W (object) – The world to which the node belongs.

  • name (str) – The name of the node.

  • x (float) – The x-coordinate of the node (for visualization purposes).

  • y (float) – The y-coordinate of the node (for visualization purposes).

  • signal (list of float, optional) – A list representing the signal at the node. Default is [0], representing no signal. If a signal is present, the list contains the green times for each group. For example, `signal`=[60, 10, 50, 5] means that this signal has 4 phases, and green time for the 1st group is 60 s.

  • signal_offset (float, optional) – The offset of the signal. Default is 0.

  • signal_offset_old (float, optional) – The old parameter used to set offset of the signal prior to v1.8.1. This is the opposite of the usual definition of offset. Default is None, meaning signal_offset is used.

  • flow_capacity (float, optional) – The maximum flow capacity of the node. Default is None, meaning infinite capacity.

  • auto_rename (bool, optional) – Whether to automatically rename the node if the name is already used. Default is False.

  • number_of_lanes (int, optional) – The number of lanes that can be green simultaneously at the node. Default is None.

  • 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 Node object itself. Example: The following code prints the current number of incoming vehicles to the node at each timestep. If user_function=None (default), no functions will be executed.

    >>> def user_function(node):
    >>>     print(len(node.incoming_vehicles))
    >>> W = World(...)
    >>> W.addNode("node", 0, 0, user_function=user_function)
    >>> ... #define your scenario
    >>> W.exec_simulation()
    

signal_phase

The phase of current signal. Links that have the same signal_group have a green signal.

Type:

int

signal_t

The elapsed time since the current signal phase started. When it is larger than Link.signal[Link.signal_phase], the phase changes to the next one.

Type:

float

Methods

__init__(W, name, x, y[, signal, ...])

Create a node.

adjust_node_capacity()

Automatically determine the flow_capacity of this node based on the capacity of connected links.

flow_capacity_update()

flow capacity updates.

generate()

Departs vehicles from the waiting queue.

override_signal(signal[, groups, ...])

Override signal setting.

signal_control()

Updates the signal timings for a traffic signal node.

transfer()

Transfers vehicles between links at the node.

update()

Make necessary updates when the timestep is incremented.

adjust_node_capacity()[source]

Automatically determine the flow_capacity of this node based on the capacity of connected links. It does not override if flow_capacity was already set. This calculation is based on an assumption that the node is an intersection with two major roads and two minor roads or similar types. In this case, the node capacity should be the same to that of major roads.

flow_capacity_update()[source]

flow capacity updates.

generate()[source]

Departs vehicles from the waiting queue.

Notes

If there are vehicles in the generation queue of the node, this method attempts to depart a vehicle to one of the outgoing links. The choice of the outgoing link is based on the vehicle’s route preference for each link. Once a vehicle is departed, it is removed from the generation queue, added to the list of vehicles on the chosen link, and its state is set to “run”.

override_signal(signal, groups=None, signal_offset=0, reset=False, signal_offset_old=None)[source]

Override signal setting.

Parameters:
  • signal (list of float) – Duration of each signal phase in seconds. For example, [30, 60] means that this signal has two phases; first is 30 sec green time for phase 0 and second is 60 sec green time for phase 1.

  • groups (list of list of str or Link) – List of links that have green light for each signal phase. For example, [[link1, link2], [link3, link4]] means that link1, link2 will have green in phase 0, and link3, link4 will have green light in phase 1.

  • signal_offset (float, optional) – Offset of the signal cycle in seconds.

  • reset (bool, optional) – If True, reset the current signal phase and elapsed phase time.

  • signal_offset_old (float, optional) – Previous (wrong) signal offset in seconds. When specified, the new offset is calculated relative to the new cycle length. Kept for backward compatibility.

signal_control()[source]

Updates the signal timings for a traffic signal node.

transfer()[source]

Transfers vehicles between links at the node.

Notes

This method handles the transfer of vehicles from one link to another at the node. A vehicle is eligible for transfer if:

  • The next link it intends to move to has space.

  • The vehicle has the right signal phase to proceed.

  • The current link has enough capacity to allow the vehicle to exit.

  • The node capacity is not exceeded.

update()[source]

Make necessary updates when the timestep is incremented.