MaxFlow - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


GraphTheory

  

MaxFlow

  

compute optimal value for max flow problem

 

Calling Sequence

Parameters

Description

Examples

References

Compatibility

Calling Sequence

MaxFlow(G, s, t)

Parameters

G

-

weighted graph

s

-

vertex of the graph (source)

t

-

vertex of the graph (sink)

Description

• 

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 On2m where n is the number of vertices of G and m is the number of edges.

Examples

withGraphTheory:

AMatrix0,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

A010400002030010001003010000204000000

(1)

NGraphA,weighted

NGraph 1: a directed weighted graph with 6 vertices and 10 arc(s)

(2)

IsNetworkN

1,6

(3)

DrawNetworkN

mf,FMaxFlowN,1,6

mf,F4,010300000020010001002010000003000000

(4)

The values in F can be used to show the flows on the network N

MGraphF,weighted

MGraph 2: a directed weighted graph with 6 vertices and 8 arc(s)

(5)

StyleEdgesByPropertyM,F,colorscheme=Blue,Purple,Red,thicknessscheme=1,3

DrawGraphM,layout=network

The input to MaxFlow does not have to be a network, or even be a weighted graph

G6Graph1,2,1,6,2,3,2,4,3,4,3,5,4,5,5,6

G6Graph 3: an undirected graph with 6 vertices and 8 edge(s)

(6)

DrawGraphG6

mf2,F2MaxFlowG6,1,6

mf2,F22,010001001000000100000010000001000000

(7)

M2GraphF2,weighted

M2Graph 4: a directed weighted graph with 6 vertices and 6 arc(s)

(8)

DrawGraphM2,layout=circle

References

  

Cormen, Thomas H., Leiserson, Charles E., Rivest, Ronald L., and Stein, Clifford. Introduction to Algorithms, 2nd edition. Cambridge, Mass., MIT Press, 2001.

Compatibility

• 

The GraphTheory[MaxFlow] command was updated in Maple 2024.

See Also

FlowPolynomial

IsCutSet

IsNetwork

WeightMatrix