0% found this document useful (0 votes)
16 views35 pages

DaLecture19.en.handout

The document outlines the concepts of flow networks, maximum flow, and algorithms such as Ford-Fulkerson and Edmonds-Karp used to determine maximum traffic flow in directed, weighted graphs. It discusses the properties of flow, including conservation of flow and residual capacities, as well as the Max-Flow Min-Cut Theorem. Additionally, it presents quizzes and examples to illustrate the application of these algorithms in solving flow network problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views35 pages

DaLecture19.en.handout

The document outlines the concepts of flow networks, maximum flow, and algorithms such as Ford-Fulkerson and Edmonds-Karp used to determine maximum traffic flow in directed, weighted graphs. It discusses the properties of flow, including conservation of flow and residual capacities, as well as the Max-Flow Min-Cut Theorem. Additionally, it presents quizzes and examples to illustrate the application of these algorithms in solving flow network problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Felix Friedrich, Manuela Fischer

Data Structures and Algorithms


Course at D-MATH of ETH Zurich
Spring 2025
24. Flow in Networks
Flow Network, Flow, Maximum Flow, Residual Capacity, Residual Network,
Augmenting path

Ford-Fulkerson Algorithm
Edmonds-Karp Algorithm

Cuts, Max-Flow Min-Cut Theorem

[Ottman/Widmayer, Kap. 9.7, 9.8.1], [Cormen et al, Kap. 26.1-26.3]

817
Maximum Traffic Flow
Given: Road Network with capacities

Wanted: Maximum traffic flow between Zurich and Geneva


818
Flow Network
directed, weighted graph G = (V, E, c) with capacities c : E → R>0
without antiparallel edges: s
(u, v) ∈ E ⇒ (v, u) 6∈ E 16 13
u v 4
a b
source s ∈ V without ingoing edges: 12 9 14
∀v ∈ V : (v, s) ∈
/E
s 13
c d
sink t ∈ V without outgoing edges: 20 4
∀v ∈ V : (t, v) ∈
/E
t t

819
Flow Network
Which of the following graphs are flow networks?
s s s
2 4 −2 4 3 1
3
7
a b a 0 b a b
6

4 4 6 4 2
t t t

s s s
5 3 6 9

7 6
a b a b a 1 b

6 7 4 8
t t t

820
Flow in Flow Network
Flow is function f : E → ≥0 such that R |f | = 16
Bounded Capacity: ∀e ∈ E : f (e) ≤ c(e)
s
Conservation of flow: ∀v ∈ V \ {s, t} : 6/16 10/13
X X
f (e) = f (e) 0/4
a b
e∈E − (v) e∈E + (v)
| {z } | {z } 6/12 3/9 13/14
=:f − (v) =:f + (v)

10/13
c d
v
13/20 3/4
t
Size of flow: |f | := f + (s) = f − (t)
821
Flow
Which of the following are flows?
s s s
3/4 3/3 1/2 3/6 6/6 1/2

3/6 2/2
a b a 4/4 b a b

6/4 4/5 3/3 2/2 2/2


t t t

s s s
2/2 6/7 0/2 0/1

−4/3 0/6 6/7


a b a b

6/6 2/2 0/3 0/4 t


t t

822
Maximal Flow
Given: Flow network: G = (V, E, c), directed, positively weighted,
without antiparallel edges, with source s and sink t

11/14
b d
11/13 4/4

0/9
s 0/4 7/7 t |fmax | = 23

12/16 19/20
a c
12/12

Wanted: Size |fmax | of the maximum flow in G


823
Quiz Maximum Flow

What is the maximum flow in the following flow network?

s
4 4

a 3 b

2 6
t

824
Intuition: Flow as set of paths s t
|f | = 16

s s
3
10 6/16 10/13

3 0/4
a b a b
3 6/12 3/9 13/14
3 3 3 10
10 10/13
c d c d
3
13/20 3/4
10 3
t t

825
Greedy Algorithm?
Residual capacity of an edge e: r(e) := c(e) − f (e)
Residual capacity of a path p: mine∈p r(e)

Greedy: Starting with f (e) = 0 for all e ∈ E, as long as there exists a path
s t with remaining capacity d > 0, increase flow along this path by d.

2 |f | = 8
a c
0 0
s → a → b → d → t: 3
s 4 4 t s → a → c → t: 2
0
s → b → c → t: 3
4 3
b d
0 but |fmax | = 10
G+
f := (V, E, r := c − f ) 826
Problem with Greedy

a a
5 5 5 5

s 3 t s t

3 3 3 3
b b
G = (V, E, c) |fmax | = 8

2 a 2 a 3

2 2
s 3 3 t s 3 3 t

3 3 3
b b
Greedy: |f | = 5 Redirection
827
Redirection using flow decrement
2 a a
2 5/5 2/5

s 3 3 t s 3/3 t

3 0/3 3/3
b b
before G = (V, E, f /c)

2 a 3 a
2 5/5 5/5

s 3 3 t s 0/3 t

3 3 3/3 3/3
b
after b
G = (V, E, f 0 /c)

⇒ Umleitung entspricht Verringerung des Flusses durch Kante 828


Idea: Flow increments and decrements
f (e)/c(e)
u v

Increment: r(e)
flow through e can be increased by at most u v
r(e) := c(e) − f (e) G+
f := (V, E, r := c − f )

Decrement:
flow through e can be decreased by at most f (e)
f (e) u v


G−
f := (V, E , f )
⇒ flow through ←

e can be increased by at
most f (e)
829
Residual Network
12/12
a c
8/16 14/20

s 4/4 6/7 t
4/9

10/13 4/4
b d
10/14

12
0
8 a c 14

8 4 6
s 4 0 1 6 t
5
3
0
4
10 b d
4
10

Residual network: Gf := G+
f ∪ Gf = (V, Ef , cf )
830
Ford-Fulkerson: Flow augmentation
12
0
12 a c 18
12/12
a c
12/16 18/20
4 0 2
s 0/4
0/9
6/7 t s 0 4 1 6 t
9
10/13 4/4
3
b d 0
10/14
4
10 b d
4
10

Augmenting Path: path p : s → t with residual capacity d > 0 in Gf


augment flow along this path for all e ∈ P by d:
decrease residual capacity cf (e) in Gf by d; increase cf (←

e ) by d


increase flow through e ∈ E by d; decrease through e ∈ E

⇒ total flow |f | in G is increased by t, since first (and last) edge ∈ E 831


Algorithm Ford-Fulkerson(G, s, t)
Input: Flow network G = (V, E, c), source s, sink t
Output: Maximal flow f
for e ∈ E do
f (e) ← 0
while exists augmenting path p : s t in residual network Gf = (V, Ef , cf ) do
d ← mine∈p cf (e)
foreach (u, v) ∈ p do
if (u, v) ∈ E then
f ((u, v)) ← f ((u, v)) + d
else
f ((v, u)) ← f ((v, u)) − d

return f
832
Example Ford-Fulkerson
4
0
5 a c 5
4/4
a c
5/5 5/5
0 3 0
s 1/7
3/3
2/4 t s 1 6 2 2 t
0
5/7 5/6
2 1
b d
3/3
0 5
5 b d
3

nodes reachable from s


nodes not reachable from s

all outgoing edges have residual capacity 0 in Gf


⇒ flow fully exhausts capacity on these edges!
833
Quiz Ford-Fulkerson

100 100

s 1 t

100 100

How many iterations does Ford-Fulkerson need in the worst case?

834
Solution

u u
2 2
2/100 2/100
98
98
s 1/1
0/1 t s 1 0 t
98
98
2/100 2/100
2 2
v v

After i iterations: |f | = i
⇒ in total |fmax | = 200 iterations

835
Running Time Analysis of Ford-Fulkerson
Running time of each iteration: search of an augmenting path s t
⇒ BFS or DFS: O(|V | + |E|) = O(|E|)
(|V | ≤ |E| + 1, because all non-reachable nodes can be ignored.)

Number of iterations:
In every step, the size of the flow increases by d > 0.
integer capacities ⇒ increment by ≥ 1 ⇒ at most |fmax | iterations

⇒ O(|fmax | · |E|) for flow networks G = (V, E, c) with c : E → N≥1

Edmonds-Karp Algorithm: (Variant of Ford-Fulkerson)


shortest augmenting path (number of edges) ⇒ O(|V | · |E|2 ) (without
explanation)
836
Quiz Edmonds-Karp

100 100

s 1 t

100 100

How many iterations does Edmonds-Karp need in the worst case?

837
Solution

u u
100 100
100/100 100/100
0
0
s 0/1 t s 1 0 t
0
0
100/100 100/100
100 100
v v

Termination after 2 iterations!

838
Flows and Cuts: Bottleneck Intuition
Upper bounds on size of flow:
what can flow out of s: c+ (s) 11
s
what can flow into t: c− (t) 6 7
what can flow through arbitrary cut 13
what can flow through bottleneck: cmin a b
1
9
cmin 3 6
2
8
c d
s t
10
6 4
t
⇒ flow |f | ≤ bottleneck
⇒ maximum flow ≤ bottleneck 839
Cut
|f | = 6
(s, t)-Cut of graph G = (V, E, c): Partition
(S, T) of V such that s ∈ S, t ∈ T s
3/6 3/7
E(S, T ) := {(u, v) ∈ E : u ∈ S, v ∈ T }
1/1
Size of cut: a b
c(S, T ) := e∈E(S,T) c(e)
P
1/2
Flow through cut of flow network: 2/3 5/6
f (S, T ) := e∈E(S,T) f (e) − e∈E(T,S) f (e) 1/8
P P
c d
Observation:
∀f, S, T : |f | = f (S, T ) ≤ c(S, T ) 2/6 4/4
t c(S, T) = 18
⇒ |fmax | ≤ cmin f (S, T ) = 6
840
f (S, T ) = |f | for every (s, t)-cut E(S, T )

Sv− Tv− Sv− Tv−


v v
Sv+ Tv+ Sv+ Tv+

S T S0 T0
   
f (S 0 , T 0 ) = f (S, T ) − f (Sv− , v) − f (v, Sv+ ) + f (v, Tv+ ) − f (Tv− , v)
 
= f (S, T ) + f (v, Sv+ ) + f (v, Tv+ ) − f (Sv− , v) + f (Tv− , v)


= f (S, T )
I.H.
= |f |
841
Maximum Flow and Minimum Cut
3
3 a c 5
3/3 0
a c 3 1
3/6 5/6 0
s 0/1 2/8 t s 0 1 6 2 t
0/2 2
0
6/7 4/4
b d 1 4
6/6 0
6 b d
6

after termination of Ford-Fulkerson/Edmonds-Karp:


reachable from s, T ⊆ V nodes not reachable from s ⇒ Cut (S, T)
all outgoing edges e have remaining capacity 0 in Gf
f (S, T ) = e : S→T f (e) − e : T→S f (e) = e : S→T c(e) = c(S, T)
P P P

⇒ |fmax | = cmin
842
Max-Flow Min-Cut Theorem

Max-Flow Min-Cut Theorem


For a flow f in a flow network G = (V, E, c) with source s and sink t, the
following statements are equivalent:
1. f is a maximum flow in G.
2. The residual network Gf does not provide any augmenting paths.
3. |f | = c(S, T ) for a (minimum) cut (S, T ) of G.

843
Quiz Max-Flow-Min-Cut

b
3 4
2
s t
5

3 1
a

What is the minimum cut?


What is the maximum flow?

844
Summary

Definitions: flow networks, flow, cut


Concepts: Redirection, remainder network, augmenting path
Algorithms
Greedy: incorrect!
Ford-Fulkerson: O(|fmax | · |E|)
Greedy augmenting paths in remainder network
Edmonds-Karp: O(|V | · |E|2 )
Ford-Fulkerson with shortest augmenting paths (number of edges)

Max Flow = Min Cut

845
Application Examples

Maximum Rate:
water in sewage system
cars in traffic
current in electrical networks
components on conveyors
information flow in communication networks

Scheduling
Image Segmentation
Bipartite Matching

846
Bipartite Graph

A graph where V can be partitioned into disjoint sets U and W such that
each e ∈ E provides a node in U and a node in W is called bipartite.

847
Maxium Bipartite Matching

Given: bipartite undirected graph G = (V, E).


Matching: M ⊆ E such that |{m ∈ M : v ∈ m}| ≤ 1 for all v ∈ V .
Maximum Matching: Matching M with |M | ≥ |M 0 | for each matching M 0 .

848
Corresponding flow network

s t

U W U W

Construct a flow network that corresponds to the partition (U, W ) of a


bipartite graph B = (U ∪ W, EB ) with source s and sink t, with directed
edges from s to U , from U to W according to EB and from W to t. Each
edge has capacity 1.
849
Integer number theorem

Theorem 23
If the capacities of a flow network are integers, then the maximal flow
generated by the Ford-Fulkerson method provides integer numbers for
each f (u, v), u, v ∈ V .
[without proof]
Consequence: Ford-Fulkerson generates for a flow network that
corresponds to a bipartite graph a maximal matching
M = {(u, v) : f (u, v) = 1}.

850

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy