graph_tool.flow#
This module includes maximum flow / minimum cut algorithms.
Summary#
Calculate maximum flow on the graph with the Edmonds-Karp algorithm. |
|
Calculate maximum flow on the graph with the push-relabel algorithm. |
|
Calculate maximum flow on the graph with the Boykov-Kolmogorov algorithm. |
|
Get the minimum source-target cut, given the residual capacity of the edges. |
|
Get the minimum cut of an undirected graph, given the weight of the edges. |
|
Calculate the maximum flow of minimum cost between two vertices. |
|
Calculate the flow of minimum cost that satisfies the vertex supplies and demands. |
|
Compute the vertex connectivity of the graph, or between two vertices. |
|
Compute the edge connectivity of the graph, or between two vertices. |
|
Return a maximum set of disjoint paths between two vertices. |
|
Return the Gomory-Hu tree of an undirected graph. |
|
Return the \(k\)-components of the graph. |
|
Return all minimum cuts between two vertices. |
|
Return all minimum vertex separators of an undirected graph. |
|
Return all minimal vertex separators of the graph, or between two vertices. |
|
Test whether a set of vertices is a separator of the graph. |
|
Test whether a set of vertices is a minimal separator of the graph. |
|
Compute the number of internally vertex-disjoint paths between all pairs of vertices. |
|
Compute the average number of internally vertex-disjoint paths between the pairs of vertices. |
|
Test whether the graph is \(k\)-edge-connected. |
|
Label the bridge components (2-edge-connected components) of the graph. |
|
Label the \(k\)-edge-connected components of the graph. |
|
Label the maximal \(k\)-edge-connected subgraphs of the graph. |
|
Find a set of edges whose addition makes the graph \(k\)-edge-connected. |
Example network#
The following network will be used as an example throughout the documentation.
from numpy.random import seed, random
from scipy.linalg import norm
gt.seed_rng(42)
seed(42)
points = random((400, 2))
points[0] = [0, 0]
points[1] = [1, 1]
g, pos = gt.triangulation(points, type="delaunay")
g.set_directed(True)
edges = list(g.edges())
# reciprocate edges
for e in edges:
g.add_edge(e.target(), e.source())
# The capacity will be defined as the inverse Euclidean distance
cap = g.new_edge_property("double")
for e in g.edges():
cap[e] = min((1.0 / norm(pos[e.target()].a - pos[e.source()].a), 10))
g.edge_properties["cap"] = cap
g.vertex_properties["pos"] = pos
g.save("flow-example.xml.gz")
gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(cap, mi=0, ma=3, power=1),
output="flow-example.pdf")
Example network used in the documentation below. The edge capacities are represented by the edge width.#