introduction to algorithms

31
Introduction to Algorithms Maximum Flow My T. Thai @ UF

Upload: amalie

Post on 14-Jan-2016

26 views

Category:

Documents


0 download

DESCRIPTION

Introduction to Algorithms. Maximum Flow My T. Thai @ UF. Flow networks. A flow network G = ( V , E ) is a directed graph Each edge ( u , v )  E has a nonnegative capacity If ( u , v )  E , then If , A source s and a sink t. Flow networks. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to Algorithms

Introduction to Algorithms

Maximum Flow

My T. Thai @ UF

Page 2: Introduction to Algorithms

Flow networks

A flow network G = (V, E) is a directed graph Each edge (u, v) E has a nonnegative capacity

If (u, v) E , then

If , A source s and a sink t

My T. [email protected]

2

Page 3: Introduction to Algorithms

Flow networks

A flow in G is a real-valued function that satisfies the two properties: Capacity constraint

u, vV: 0 f(u, v) c(u, v)

Flow conservation

uV {s, t}: v V f(u, v) = v V f(v, u)

The value |f| of a flow f:

My T. [email protected]

3Label of each edge: f/c

(the total flow out of the source minus the flow into the source)

Page 4: Introduction to Algorithms

Max-Flow Problem

Input: A flow network G = (V, E), s, and t Output: Find a flow of maximum value

Applications: Flow of liquid through pipes Information through communication networks Flow in a transport network …

My T. [email protected]

4

Page 5: Introduction to Algorithms

Remove antiparallel edges

My T. [email protected]

5

(v1, v2) and (v2, v1) are antiparallel edges

Vertex v’ is added to remove edge (v1, v2)

Page 6: Introduction to Algorithms

Multiple sources and sinks

My T. [email protected]

6

Add supersource s Add supersink t

Page 7: Introduction to Algorithms

Ford-Fulkerson Method

My T. [email protected]

7

Page 8: Introduction to Algorithms

Example

My T. [email protected]

8

Augmenting path sv2v3t

All flows in the augmenting path are increased by 4 units

Page 9: Introduction to Algorithms

Residual network

Given flow f, the residual capacity of edge (u, v)

Residual network induced by f is Gf = (V, Ef)

My T. [email protected]

9

Page 10: Introduction to Algorithms

f is a flow in G and f’ is a flow in Gf , the augmentation of flow f by f’( ), is a function from , defined by:

Flow augmentation

My T. [email protected]

10

Page 11: Introduction to Algorithms

Augmenting path

Any simple path p from s to t in G f is an augmenting path in G with respect to f

Flows on edges of p can be increased by the residual capacity of p

My T. [email protected]

11

Cf(p) =4 with p is the shaded path

Page 12: Introduction to Algorithms

Increase the value of flow along augmenting paths

My T. [email protected]

12

Page 13: Introduction to Algorithms

Cuts A cut (S,T) of a flow network G = (V, E) is a partition of V

into S and T = V S such that s S and t T. The net flow across the cut

The capacity of the cut

A minimum cut of G is a cut

whose capacity is minimum

over all cuts of GMy T. Thai

[email protected]

13

Page 14: Introduction to Algorithms

Proof:Flow conservation => ,

My T. [email protected]

14

=>

(regroup the formula)

(partition V to S and T)

Page 15: Introduction to Algorithms

Upper bound of flow value

Proof: Let (S, T) be any cut, f be any flow

My T. [email protected]

15

Page 16: Introduction to Algorithms

Max-flow min-cut theorem

Proof: (1) => (2): If Gf has an augmenting path p, then by Corollary 26.3,

there exists a flow of value |f| + Cf(p) > |f| that is a flow in G

(2) => (3): Suppose (2) holds. Define S = {vV: path from s to v in Gf}, and T = V – S. (S, T) is a cut. For u S, v T, f(u,v) = c(u,v)

By Lemma 26.4, |f | = f(S,T) = c(S,T) (3) => (1): By Corollary 26.5, |f | = c(S,T) implies f is a maximum flowMy T. Thai

[email protected]

16

Page 17: Introduction to Algorithms

Ford-Fulkerson algorithm

Running time: If capacities are integers, then O(E|f*|), where f* is the

maximum flow With irrational capacities, might never terminate.

My T. [email protected]

17

Page 18: Introduction to Algorithms

Example

My T. [email protected]

18

Page 19: Introduction to Algorithms

My T. [email protected]

19

Page 20: Introduction to Algorithms

My T. [email protected]

20

No augmenting path

Page 21: Introduction to Algorithms

Bad example

FORD-FULKERSON runs 1000,000 iterations

My T. [email protected]

21

Page 22: Introduction to Algorithms

Edmonds-Karp algorithm

Do FORD-FULKERSON, but compute augmenting paths by BFS of Gf . Augmenting paths are shortest paths from s to t in Gf , with all edge weights = 1

Running time: O(VE2) There are O(VE) flow augmentations Time for each augmentation (BFS) is O(E)

My T. [email protected]

22

Page 23: Introduction to Algorithms

Analysis of E-K

Proof: (by contradiction) Suppose that there exist 2 continuous flows f

and f’ such that f(s,v) f(s,v) for some v V ∈

W.l.o.g suppose v is the nearest vertex (to s) satisfying f(s,v) < f(s,v) (*)

My T. [email protected]

23

Page 24: Introduction to Algorithms

Proof of Lemma 26.7

Let u be the vertex before v on the shortest path from s to v

=>=> u is not the nearest vertex to s satisfying (*)

=>

Claim: . If not we have:

My T. [email protected]

24(Contradicted)

Page 25: Introduction to Algorithms

=> The augmentation must increase flow v to u Edmonds-Karp augments along shortest paths,

the shortest path s to u in Gf has v → u as its last edge

My T. [email protected]

25

(Contradicted)

Page 26: Introduction to Algorithms

Time bound

Proof: Suppose p is augmenting path, (u, v) p, and cf(p)

= cf(u,v). Then (u, v) is critical, and disappears from the residual network after augmentation.

Before (u, v) becomes a critical edge again, there must be a flow back from v to u

My T. [email protected]

26

Page 27: Introduction to Algorithms

Time bound Claim: each of the |E| edges can become critical ≤ |V| /2 −

1 times Consider edge (u, v), when (u, v) becomes critical first time,

δf(s, v) = δf(s, u) + 1

(u, v) reappears in the residual network after (v, u) is on an augmenting path in Gf’ , δf’(s, u) = δf’(s, v) + 1

=>

My T. [email protected]

27

=>The claim is proved => The theorem is proved

Page 28: Introduction to Algorithms

Maximum bipartite matching

A matching is a subset of edges M E⊆ such that for all v V∈ , ≤ 1 edge of M is incident on v.

Problem: Given a bipartite graph find a matching of maximum cardinality.

My T. [email protected]

28

each edge has capacity 1

(A maximum matching) (Reduce to the maximum flow problem)

Page 29: Introduction to Algorithms

Integrality theorem

My T. [email protected]

29

Page 30: Introduction to Algorithms

Summary

Max-flow min-cut theorem: the capacity of the minimum cut equals to the value of the maximum flow

Ford-Fulkerson method: iteratively find an augmenting path and augment flow along the path

Ford-Fulkerson algorithm: find an arbitrary augmenting path in each iteration If capacities are integers, then O(E|f*|), where f* is the maximum

flow With irrational capacities, might never terminate.

My T. [email protected]

30

Page 31: Introduction to Algorithms

Summary

Edmonds-Karp algorithm: find a shortest augmenting path in each iteration Time: O(VE2)

Integrality theorem: if all capacities are integral values, then the value of the maximum flow as well as flows on edges are integers

My T. [email protected]

31