Note
Go to the end to download the full example code.
Maximum Flow
This example shows how to construct a max flow on a directed graph with edge capacities using igraph.Graph.maxflow()
.
import igraph as ig
import matplotlib.pyplot as plt
First, we generate a graph and assign a “capacity” to each edge:
To find the max flow, we can simply run:
flow = g.maxflow(3, 0, capacity=g.es["capacity"])
print("Max flow:", flow.value)
print("Edge assignments:", flow.flow)
# Output:
# Max flow: 6.0
# Edge assignments [1.0, 5.0, 1.0, 2.0, 3.0, 3.0, 3.0]
Max flow: 6.0
Edge assignments: [1.0, 5.0, 1.0, 2.0, 3.0, 3.0, 3.0]
Finally, we can plot the directed graph to look at the situation:

Total running time of the script: (0 minutes 0.097 seconds)