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.PyDAG.reverse#

PyDAG.reverse()#

Reverse the direction of all edges in the graph, in place.

This method modifies the graph instance to reverse the direction of all edges. It does so by iterating over all edges in the graph and removing each edge, then adding a new edge in the opposite direction with the same weight.

For Example:

import rustworkx as rx

graph = rx.PyDiGraph()

# Generate a path directed path graph with weights
graph.extend_from_weighted_edge_list([
    (0, 1, 3),
    (1, 2, 5),
    (2, 3, 2),
])
# Reverse edges
graph.reverse()

assert graph.weighted_edge_list() == [(3, 2, 2), (2, 1, 5), (1, 0, 3)];