Max Flow1
Max Flow1
Chapter 26
Flow Graph
A common scenario is to use a graph to
represent a flow network and use it to answer
questions about material flows
Flow is the rate that material moves through the
network
Each directed edge is a conduit for the material
with some stated capacity
Vertices are connection points but do not collect
material
Flow into a vertex must equal the flow leaving the
vertex, flow conservation
Sample Networks
Network
Nodes
Arcs
Flow
voice, video,
packets
gates, registers,
processors
wires
current
joints
heat, energy
hydraulic
reservoirs, pumping
stations, lakes
pipelines
fluid, oil
financial
stocks, companies
transactions
money
transportation
highways, railbeds,
airway routes
freight,
vehicles,
passengers
sites
bonds
energy
communication
circuits
mechanical
chemical
Flow Concepts
Source vertex s
where material is produced
Sink vertex t
where material is consumed
Flow a function f : V V R
Capacity constraint: For all u, v V: f(u,v) c(u,v)
Skew symmetry: For all u, v V: f(u,v) = f(v,u)
Flow conservation: For all u V {s, t}:
2/15
0/9
5/14
vV
4/19
2/5
f (u, v) f (u,V ) 0, or
3/3
f (v, u) f (V , u ) 0
vV
Cancellation of flows
We would like to avoid two positive flows
in opposite directions between the same
pair of vertices
Such flows cancel (maybe partially) each
other due to skew symmetry
2/15
2/9
5/14
5/5
2/15
5/19
2/3
0/9
5/14
5/19
3/5
2/3
Max Flow
We want to find a flow of maximum value
from the source to the sink
Denoted by |f|
Ford-Fulkerson method
Contains several algorithms:
Residue networks
Augmenting paths
Find a path p from s to t (augmenting path), such that there is
some value x > 0, and for each edge (u,v) in p we can add x
units of flow
f(u,v) + x c(u,v)
Augmenting Path?
10/15
s
6/14
a
2/4
8/13
10
b
9
8/11
13/19
5/5
3/3
Residual Network
To find augmenting path we can find any path in the
residual network:
Residual capacities: cf(u,v) = c(u,v) f(u,v)
i.e. the actual capacity minus the net flow from u to v
Net flow may be negative
Sub-graph
With
c(u,v) and
f(u,v)
b
0/14
5/6
Residual
Sub-Graph
10
b
19
c
5
Residual Graph
Compute the residual graph of the graph with the
following flow:
10/15
s
6/14
a
2/4
8/13
10
b
9
8/11
13/19
5/5
3/3
The algorithms based on this method differ in how they choose p in step 3.
If chosen poorly the algorithm might not terminate.
Cuts
Does the method find the minimum flow?
Yes, if we get to the point where the residual graph has no path from s
to t
A cut is a partition of V into S and T = V S, such that s S and t T
The net flow (f(S,T)) through the cut is the sum of flows f(u,v), where s
S and t T
Includes negative flows back from T to S
The capacity (c(S,T)) of the cut is the sum of capacities c(u,v), where s
S and t T
s
6/14
Cut capacity = 24
a
2/4
8/13
10
b
9
8/11
13/19
5/5
3/3
Min Cut capacity = 21
Augmenting path of 1
Edmonds Karp
Take shortest path (in terms of number of
edges) as an augmenting path
Edmonds-Karp algorithm
How do we find such a shortest path?
Running time O(VE2), because the number of
augmentations is O(VE)
Skipping the proof here
Even better method: push-relabel, O(V2E)
runtime
15
10
4
14
4
c
e
15
13
11
f
9
t
3
13
i
14
c
e
15
y
3
13
11
f
9
13
11
10
4
14
13
10
15
13
11
10
4
14
13
t
13
Bipartite Graph
A bipartite graph is an undirected graph G=(V,E) in
which V can be partitioned into two sets V1 and V2 such
that (u,v) E implies either u V1 and v V12 or vice
versa.
That is, all edges go between the two sets V1 and V2 and
not within V1 and V2.
Y
C
Z
Men
Z
D
Women
A matching
Z
D
Optimal matching
B
Y
C
B
Y
C
Z
D
Z
D