CS 401 Max Flow / Bipartite Matching Xiaorui Sun 1 Flow network - - PowerPoint PPT Presentation

cs 401
SMART_READER_LITE
LIVE PREVIEW

CS 401 Max Flow / Bipartite Matching Xiaorui Sun 1 Flow network - - PowerPoint PPT Presentation

CS 401 Max Flow / Bipartite Matching Xiaorui Sun 1 Flow network Flow network. G = (V, E) = directed graph, no parallel edges. Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e. 9 2 5 10 15 15 10 4 source 5


slide-1
SLIDE 1

CS 401

Max Flow / Bipartite Matching

Xiaorui Sun

1

slide-2
SLIDE 2

Flow network.

G = (V, E) = directed graph, no parallel edges. Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e.

Flow network

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4

capacity source sink

slide-3
SLIDE 3

3

Min s-t cut problem. Find an s-t cut of minimum capacity.

Minimum Cut Problem

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 A Capacity = 10 + 8 + 10 = 28

slide-4
SLIDE 4

4

Max flow problem. Find s-t flow of maximum value.

Maximum Flow Problem

10 9 9 14 4 10 4 8 9 1 14

capacity flow

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4

Value = 28

slide-5
SLIDE 5

Max Flow Algorithm

Ford-Fulkerson(G, s, t, c) { foreach e Î E f(e) ¬ 0 Gf ¬ residual graph while (there exists augmenting path P) { f ¬ Augment(f, c, P) update Gf } return f }

Max-flow min-cut theorem. [Ford-Fulkerson 1956] The value of the max flow is equal to the value of the min cut.

slide-6
SLIDE 6

Running Time

  • Assumption. All capacities are integers between 1 and C.
  • Invariant. Every flow value f(e) and every residual

capacities cf (e) remains an integer throughout the algorithm.

  • Theorem. The algorithm terminates in at most v(f*) £ nC

iterations.

  • Pf. Each augmentation increase value by at least 1. ▪
  • Corollary. If C = 1, Ford-Fulkerson runs in O(mn) time.

Integrality theorem. If all capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer.

  • Pf. Since algorithm terminates, theorem follows from
  • invariant. ▪
slide-7
SLIDE 7

7.3 Choosing Good Augmenting Paths

slide-8
SLIDE 8

Ford-Fulkerson: Exponential Number

  • f Augmentations
  • Q. Is generic Ford-Fulkerson algorithm polynomial in input

size?

  • A. No. If max capacity is C, then algorithm can take C

iterations.

s 1 2 t

C C C C 1

s 1 2 t

C C 1

X 1

C C

X X X

1 1 1

X X

1 1

X X X

1 1

m, n, and log C

slide-9
SLIDE 9

Choosing Good Augmenting Paths

Use care when selecting augmenting paths.

Some choices lead to exponential algorithms. Clever choices lead to polynomial algorithms. If capacities are irrational, algorithm not guaranteed to terminate!

Goal: choose augmenting paths so that:

Can find augmenting paths efficiently. Few iterations.

Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970]

Sufficiently large bottleneck capacity. Fewest number of edges.

slide-10
SLIDE 10

Capacity Scaling

  • Intuition. Choosing path with highest bottleneck capacity

increases flow by max possible amount.

How to find exact highest bottleneck path? Homework 4 Maintain scaling parameter D. Let Gf (D) be the subgraph of the residual graph consisting of only arcs with capacity at least D.

110

s 4 2 t

1 170 102 122 Gf 110

s 4 2 t

170 102 122 Gf (100)

slide-11
SLIDE 11

Capacity Scaling

Scaling-Max-Flow(G, s, t, c) { foreach e Î E f(e) ¬ 0 D ¬ smallest power of 2 greater than or equal to C Gf ¬ residual graph while (D ³ 1) { Gf(D) ¬ D-residual graph while (there exists augmenting path P in Gf(D)) { f ¬ augment(f, c, P) update Gf(D) } D ¬ D / 2 } return f }

slide-12
SLIDE 12

Capacity Scaling: Correctness

  • Assumption. All edge capacities are integers between 1

and C. Integrality invariant. All flow and residual capacity values are integral.

  • Correctness. If the algorithm terminates, then f is a max

flow. Pf.

By integrality invariant, when D = 1 Þ Gf(D) = Gf. Upon termination of D = 1 phase, there are no augmenting paths. ▪

slide-13
SLIDE 13

Capacity Scaling: Running Time

Lemma 1. The outer while loop repeats 1 + élog2 Cù times.

  • Pf. Initially C £ D < 2C. D decreases by a factor of 2 each iteration. ▪

Lemma 2. Let f be the flow at the end of a D-scaling phase. Then the value of the maximum flow is at most v(f) + m D. Lemma 3. There are at most 2m augmentations per scaling phase. Let f be the flow at the end of the previous scaling phase. L2 Þ v(f*) £ v(f) + m (2D). Each augmentation in a D-phase increases v(f) by at least D. ▪

  • Theorem. The scaling max-flow algorithm finds a max flow in O(m

log C) augmentations. It can be implemented to run in O(m2 log C)

  • time. ▪

proof on next slide

slide-14
SLIDE 14

Capacity Scaling: Running Time

Lemma 2. Let f be the flow at the end of a D-scaling phase. Then value of the maximum flow is at most v(f) + m D.

  • Pf. (almost identical to proof of max-flow min-cut theorem)

We show that at the end of a D-phase, there exists a cut (A, B) such that cap(A, B) £ v(f) + m D. Choose A to be the set of nodes reachable from s in Gf(D). By definition of A, s Î A. By definition of f, t Ï A.

  • riginal network

s t

A B

slide-15
SLIDE 15

Summary

Min s-t cut problem. Find an s-t cut of minimum capacity. Max flow problem. Find s-t flow of maximum value. Max-flow min-cut theorem. The value of the max flow is equal to the value of the min cut. Ford-Fulkerson Algorithm. Augment flow along augmenting path Running time:

  • O(nm) for unit capacity graph
  • O(m2 log C) for integer capacity graph

15

slide-16
SLIDE 16

Bipartite Matching

slide-17
SLIDE 17

Maximum Matching Problem

Given an undirected graph ! = ($, &). A set ( ⊆ & is a matching if each node appears in at most 1 edge in (. Goal: find a matching with largest cardinality.

17

slide-18
SLIDE 18

Bipartite Matching Problem

Given an undirected bipartite graph ! = ($ ∪ &, () A set * ⊆ ( is a matching if each node appears in at most 1 edge in *. Goal: find a matching with largest cardinality.

18

1 3 5 1' 3' 5' 2 4 2' 4'

X Y

slide-19
SLIDE 19

Bipartite Matching using Max Flow

Create digraph ! as follows:

  • Orient all edges from " to #, and assign infinite (or unit) capacity.
  • Add source $, and unit capacity edges from $ to each node in %.
  • Add sink &, and unit capacity edges from each node in ' to &.

19

s 1 3 5 1' 3' 5' t 2 4 2' 4' 1 1

Y X

H

slide-20
SLIDE 20

Bipartite Matching: Proof of Correctness

  • Thm. Max cardinality matching in ! = value of max flow in H.
  • Proof. Matching value £ maxflow value

Given max matching " of cardinality #. Consider flow $ that sends 1 unit along each of # edges of ". $ is a flow, and has cardinality #. ▪

20

1 3 5 1' 3' 5' 2 4 2' 4'

G

4 4' s 1 3 5 1' 3' 5' t 2 2' 1 1

∞ H

slide-21
SLIDE 21

Bipartite Matching: Proof of Correctness

  • Thm. Max cardinality matching in G = value of max flow in H.
  • Proof. (matching val ≥ maxflow val) Let " be a max flow in # of value $.

Integrality theorem Þ $ is integral and we can assume " is 0-1. Consider % = set of edges from & to ' with " ( = 1.

  • each node in & and ' participates in at most one edge in %.
  • |%| = $: consider s-t cut (. ∪ &, 1 ∪ ')

21

s 1 3 5 1' 3' 5' t 2 4 2' 4' 1 1

∞ H

1 3 5 1' 3' 5' 2 4 2' 4'

G