graph_tool.flow

graph_tool.flow#

This module includes maximum flow / minimum cut algorithms.

Summary#

edmonds_karp_max_flow

Calculate maximum flow on the graph with the Edmonds-Karp algorithm.

push_relabel_max_flow

Calculate maximum flow on the graph with the push-relabel algorithm.

boykov_kolmogorov_max_flow

Calculate maximum flow on the graph with the Boykov-Kolmogorov algorithm.

minimum_st_cut

Get the minimum source-target cut, given the residual capacity of the edges.

minimum_cut

Get the minimum cut of an undirected graph, given the weight of the edges.

min_cost_max_flow

Calculate the maximum flow of minimum cost between two vertices.

min_cost_flow

Calculate the flow of minimum cost that satisfies the vertex supplies and demands.

vertex_connectivity

Compute the vertex connectivity of the graph, or between two vertices.

edge_connectivity

Compute the edge connectivity of the graph, or between two vertices.

disjoint_paths

Return a maximum set of disjoint paths between two vertices.

gomory_hu_tree

Return the Gomory-Hu tree of an undirected graph.

k_components

Return the \(k\)-components of the graph.

all_minimum_st_cuts

Return all minimum cuts between two vertices.

all_minimum_vertex_separators

Return all minimum vertex separators of an undirected graph.

all_minimal_separators

Return all minimal vertex separators of the graph, or between two vertices.

is_separator

Test whether a set of vertices is a separator of the graph.

is_minimal_separator

Test whether a set of vertices is a minimal separator of the graph.

all_pairs_vertex_connectivity

Compute the number of internally vertex-disjoint paths between all pairs of vertices.

average_vertex_connectivity

Compute the average number of internally vertex-disjoint paths between the pairs of vertices.

is_k_edge_connected

Test whether the graph is \(k\)-edge-connected.

label_bridge_components

Label the bridge components (2-edge-connected components) of the graph.

label_k_edge_components

Label the \(k\)-edge-connected components of the graph.

label_k_edge_subgraphs

Label the maximal \(k\)-edge-connected subgraphs of the graph.

k_edge_augmentation

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")
_images/flow-example.png

Example network used in the documentation below. The edge capacities are represented by the edge width.#