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.PyDiGraph.add_edge#

PyDiGraph.add_edge(parent, child, edge, /)#

Add an edge between 2 nodes.

Use add_child() or add_parent() to create a node with an edge at the same time as an edge for better performance. Using this method allows for adding duplicate edges between nodes if the multigraph attribute is set to True.

Parameters:
  • parent (int) – The index of the parent node

  • child (int) – The index of the child node

  • edge (T) – The Python object to attach to the edge.

Returns:

The index of the newly created edge

Return type:

int

Raises:

PyIndexError: When the new edge would create a cycle