SciPy provides an implementation of a max flow algorithm: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.maximum_flow.html
I would like to partition the input graph by the min cut into vertex sets S and T.
The SciPy MaximumFlow object contains a flow member, which according to the SciPy GitHub PR 16004:
represents the flow function of the maximum flow, whereas the residual is given by the difference between the input graph and this flow function.
Given the MaximumFlow object, how do I partition the graph into the source and sink nodes by cutting along the min cut?
To do this, we can perform a flood fill with either depth-first or breadth-first search from the source node on the residual graph.
The residual graph is the difference between the original capacity graph and the flow graph returned by
maximum_flow. Please note that theresidualfield in theMaximumFlowobject is a misnomer and has been removed (renamed toflow).To perform depth-first search, we can use the built-in
scipy.sparse.csgraph.depth_first_order.Make sure that your input
graph_csrhas all the edges, including the reverse edges.Tested on
scipy-1.10.1withpython 3.8.10