GraphTheory
MaxFlow
compute optimal value for max flow problem
Calling Sequence
Parameters
Description
Examples
References
Compatibility
MaxFlow(G, s, t)
G
-
weighted graph
s
vertex of the graph (source)
t
vertex of the graph (sink)
The MaxFlow command solves the s to t maximum flow problem using edge weights of G as the flow capacities between vertices. If G is not a weighted graph then every edge is taken to have a capacity of 1. If G is a multigraph every edge is taken to have a capacity equal to its multiplicity. An undirected Graph is treated as a directed graph with edges in both directions, but the output flow matrix will be directional.
This command returns two things: the optimal value for the maximum flow from the vertex s to the vertex t and a sparse matrix of the flows at each edge which achieve that optimal flow. The maximum flow value is unique, while the flow matrix may be one of several possible flows that achieve that maximum.
MaxFlow uses the Push-Relabel (Push-Preflow) algorithm of Goldberg et al. (see Introduction to Algorithms, Cormen, Leiserson, Rivest, 2nd edition). The complexity is O⁡n2⁢m where n is the number of vertices of G and m is the number of edges.
with⁡GraphTheory:
A≔Matrix⁡0,1,0,4,0,0,0,0,2,0,3,0,0,1,0,0,0,1,0,0,3,0,1,0,0,0,0,2,0,4,0,0,0,0,0,0
A≔010400002030010001003010000204000000
N≔Graph⁡A,weighted
N≔Graph 1: a directed weighted graph with 6 vertices and 10 arc(s)
IsNetwork⁡N
1,6
DrawNetwork⁡N
mf,F≔MaxFlow⁡N,1,6
mf,F≔4,010300000020010001002010000003000000
The values in F can be used to show the flows on the network N
M≔Graph⁡F,weighted
M≔Graph 2: a directed weighted graph with 6 vertices and 8 arc(s)
StyleEdgesByProperty⁡M,F,colorscheme=Blue,Purple,Red,thicknessscheme=1,3
DrawGraph⁡M,layout=network
The input to MaxFlow does not have to be a network, or even be a weighted graph
G6≔Graph⁡1,2,1,6,2,3,2,4,3,4,3,5,4,5,5,6
G6≔Graph 3: an undirected graph with 6 vertices and 8 edge(s)
DrawGraph⁡G6
mf2,F2≔MaxFlow⁡G6,1,6
mf2,F2≔2,010001001000000100000010000001000000
M2≔Graph⁡F2,weighted
M2≔Graph 4: a directed weighted graph with 6 vertices and 6 arc(s)
DrawGraph⁡M2,layout=circle
Cormen, Thomas H., Leiserson, Charles E., Rivest, Ronald L., and Stein, Clifford. Introduction to Algorithms, 2nd edition. Cambridge, Mass., MIT Press, 2001.
The GraphTheory[MaxFlow] command was updated in Maple 2024.
See Also
FlowPolynomial
IsCutSet
IsNetwork
WeightMatrix
Download Help Document