Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.digraph_union#

digraph_union(first, second, /, merge_nodes=False, merge_edges=False)#

Return a new PyDiGraph by forming a union from two input PyDiGraph objects

The algorithm in this function operates in three phases:

  1. Add all the nodes from second into first. operates in \(\mathcal{O}(n_2)\), with \(n_2\) being number of nodes in second.

  2. Merge nodes from second over first given that:

    • The merge_nodes is True. operates in \(\mathcal{O}(n_1 n_2)\), with \(n_1\) being the number of nodes in first and \(n_2\) the number of nodes in second

    • The respective node in second and first share the same weight/data payload.

  3. Adds all the edges from second to first. If the merge_edges parameter is True and the respective edge in second and first share the same weight/data payload they will be merged together.

Parameters:
  • first (PyDiGraph) – The first directed graph object

  • second (PyDiGraph) – The second directed graph object

  • merge_nodes (bool) – If set to True nodes will be merged between second and first if the weights are equal. Default: False.

  • merge_edges (bool) – If set to True edges will be merged between second and first if the weights are equal. Default: False.

Returns:

A new PyDiGraph object that is the union of second and first. It’s worth noting the weight/data payload objects are passed by reference from first and second to this new object.

Return type:

PyDiGraph