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.


PyDiGraph.to_undirected(multigraph=True, weight_combo_fn=None)#

Generate a new PyGraph object from this graph

This will create a new PyGraph object from this graph. All edges in this graph will be created as undirected edges in the new graph object. For directed graphs with bidirectional edges, you can set multigraph=False to condense them into a single edge and specify a function to combine the weights/data of the edges. Do note that the node and edge weights/data payloads will be passed by reference to the new PyGraph object.


The node indices in the output PyGraph may differ if nodes have been removed.

  • multigraph (bool) – If set to False the output graph will not allow parallel edges. Instead parallel edges will be condensed into a single edge and their data will be combined using weight_combo_fn. If weight_combo_fn is not provided, the data of the edge with the largest index will be kept. Default: True.

  • weight_combo_fn – An optional python callable that will take in a two edge weight/data object and return a new edge weight/data object that will be used when adding an edge between two nodes connected by multiple edges (of either direction) in the original directed graph.


A new PyGraph object with an undirected edge for every directed edge in this graph

Return type: