• No results found

Max-flow and min-cut

N/A
N/A
Protected

Academic year: 2022

Share "Max-flow and min-cut"

Copied!
66
0
0

Loading.... (view fulltext now)

Full text

(1)

Max-flow and min-cut

(2)

Max-Flow and Min-Cut

Two important algorithmic problems, which yield a beautiful duality

Myriad of non-trivial applications, it plays an important role in the optimization of many problems:

Network connectivity, airline schedule (extended to all means of transportation), image segmentation, bipartite matching, distributed computing, data mining, · · · ·

(3)

Flow Networks

Network diagraph G = (V , E ) s.t. it has

I source vertex s ∈ V

I sink vertex t ∈ V

I edge capacities c : E → R+∪ {0}

1 a

s t

b 2

1 2

1 2

Flowf : V × V → R+∪ {0} s.t.

Kirchoff’s laws:

I ∀(u, v ) ∈ E , 0 ≤ f (u, v ) ≤ c(u, v ),

I (Flow conservation) ∀v ∈ V − {s, t}, P

u∈Vf (u, v ) =P

z∈V f (v , z)

I The value of a flow

|f | =X

v ∈V

f (s, v ) = f (s, V ) = f (V , t). Value |f|=3 a

s t

b 2

1

2 1

2/ 1

1/ 2/2

1/

1/

(4)

The Maximum flow problem

INPUT: Given a flow network (G = (V , E ), s, t, c) QUESTION: Find a flow of maximum value on G .

c

2/2

5/5 5/5

1/1 1/5

0/9

0/3 2/4

4/4 1/2

2/2

s

a d

t

e b

The value of the max-flow is7= 4 + 1 + 2 = 5 + 2.

Notice: Although the flow exiting s is not maximum, the flow going into t is maximum (= max. capacity).

Therefore the total flow is maximum.

(5)

The s − t cut

Given (G = (V , E ), s, t, c) as − t cutis a partition of V = S ∪ T (S ∩ T = ∅), with s ∈ S and t ∈ T .

Theflow across the cut:

f (S ) =P

u∈S

P

v ∈Tf (u, v ) −P

v ∈S

P

u∈Tf (v , u).

Thecapacity of the cut: c(S ) =P

u∈S

P

v ∈Tc(u, v ) capacity of cut (S , T ) = sum of weightsleaving S.

Notice because of the capacity constrain: f (S ) ≤ c(S )

f(S,T)=(2+1+5)+(0+2−1−2)=7 2/2

5/5 5/5

1/1 1/5

0/9

0/3 2/4

4/4 1/2

s

c e

t d

b a

T={a,b,e,t}

S = {s,c,d}

2/2

c(S,T)=(4+5+5)+(3+2)=19

(6)

The s − t cut

Given (G = (V , E ), s, t, c) as − t cutis a partition of S , T of V (i.e. V = S ∪ T and S ∩ T = ∅), with s ∈ S and t ∈ T .

Theflow across the cut:

f (S ) =P

u∈S

P

v ∈Tf (u, v ) −P

v ∈T

P

u∈Sf (v , u).

Thecapacity of the cut: c(S ) =P

u∈S

P

v ∈Tc(u, v ) Notice because of the capacity constrain: f (S ) ≤ c(S )

2/2 2/2

5/5 5/5

1/1 1/5

0/9

0/3 2/4

4/4 1/2

s

c e

t d

b

a S = {s,c,a}

T={d,b,e,t}

c(S,T)=2+5+5=12 f(S,T)=2+1+5−1=7

(7)

Notation

Given v ∈ G and cut (S , T ) and a v ∈ S , let S0 = S − {v }. Then

I Denote f (S0, T ) flow between S0 and T (without going by v ).

i.e. f (S0, T ) =P

u∈S0

P

w ∈Tf (u, w ) −P

w ∈T

P

u∈S0f (w , u) with (u, w ) ∈ E and (u, w ) ∈ E,

I denotef (v , T ) flow v → T i.e. f (v , T ) =P

u∈T f (v , u),

I denotef (T , v ) flow T → v i.e. f (T , v ) =P

u∈T f (u, v ),

I denotef (S0, v )flow S0 → v i.e. f (S0, v ) =P

u∈S0f (u, v ),

I denotef (v , S0)flow v → S0 i.e. f (v , S0) =P

u∈S0f (v , u),

t s

v

T

S

S’

(8)

Any s − t cut has the same flow

Theorem

Given (G , s, t, c) the flow through any s − t cut (S , T ) is f (S ) = |f |.

Proof(Induction on |S |)

I If S = {s} then f (S ) = |f |.

I Assume it is true for S0 = S − {v }, i.e. f (S0) = |f |.

Notice f (S0) = f (S0, T ) + f (S0, v ) − f (v , S0). Moreover from the flow conservation, f (S0, v ) + f (T , v ) = f (v , S0) + f (v , T )

⇒ f (v , T ) − f (T , v ) = f (S0, v ) − f (v , S0)

| {z }

I Then f (S ) = f (S0, T ) + f (v , T ) − f (T , v ), using (∗)

f (S ) = f (S0) = |f | 2

t s

v T

S S’

(9)

Residual network

Given a network (G = (V , E ), s, t, c) together with aflow f on it, theresidual network, (Gf = (V , Ef), cf) is the network with the same vertex set and edge set:

I if c(u, v ) − f (u, v ) > 0 then (u, v ) ∈ Ef and

cf(u, v ) = c(u, v ) − f (u, v ) > 0 (forward edges), and

I if f (u, v ) > 0 then (v , u) ∈ Ef and cf(v , u) = f (u, v ) (backward edges). i.e. there are f (u, v ) units of flow we can undo, by pushing flow backward. Notice, if c(u, v ) = f (u, v ) then there is only a backward edge.

I the cf are denoted residual capacity.

s a

s t

b 2/3

2/2 0/1

0/1

2/2 a

t b 2

2 1 2

1 1

G f

(10)

Residual network: Augmenting paths

Given G = (V , E ) and a flow f on G , anaugmenting pathP is anysimplepath in Gf (using forward and backward edges, but P : s t).

Given f : s t in G and P in Gf define thebottleneck (P, f ) to be the minimum residual capacity of any edge in P, with respect to f .

1/3

a t b s

1

1 2

1 2 2 a

t b 2

2 1

s 2

1

1

P: dotted line Gf

G

a t b s

1 1/

1/1 2/2

2/2

(11)

Residual network: Augmenting paths

Given G = (V , E ) and a flow f on G , anaugmenting pathP is anysimplepath in Gf.

Given f s → t in G and P in Gf define thebottleneck (P, f ) to be theminimum residual capacityof any edge in P.

Augment(P, f ) b=bottleneck (P, f ) for each (u, v ) ∈ P do

if (u, v ) is forward edge in G then Increase f (u, v ) in G by b else

Decrease f (u, v ) in G by b end if

end for return f

(12)

Residual network: Augmenting paths

Lemma

Consider f0 =Augment(P, f ), then f0 is a flow in G .

Proof: We have to prove that (1) ∀e ∈ E , 0 ≤ f (e) ≤ c(e) and that ∀v flow to v = flow out of v .

I Capacity lawForward edges (u, v ) ∈ P weincrease f (u, v ) by b, as b ≤ c(u, v ) − f (u, v ) then

f0(u, v ) = f (u, v ) + b ≤ c(u, v ).

Backward edges (u, v ) ∈ P wedecrease f (v , u) by b, as b ≤ f (v , u), f0(v , u) = f (u, v ) − b ≥ 0.

I Conservation law, ∀v ∈ P given edges e1, e2 in P and incident to v , it is easy to check the 4 cases based whether e1, e2 are

forward or backward edges. 2

(13)

Max-Flow Min-Cut theorem

Theorem: For any (G , s, t, c) the value of the max flow f is equal to the capacity of the min (S , T )-cut (over all s − t cuts in G )

f= max{|f |} = min

∀(S,T ){c(S, T )}.

Ford and Fulkerson (1954); Peter Elias, Amiel Feinstein and Claude Shannon (1956) (in framework of information-theory).

Proof:

I For any s − t cut (S , T ) in G ⇒ f(S ) ≤ c(S , T ).

I If f in G is a max flow then Gf has no augmenting path s ; t so it is disconnected.

Let Ss = {v ∈ V |∃s ; v in Gf}, then (Ss, V − {Ss}) is a s − t cut in Gf ⇒ ∀v ∈ Ss, u ∈ V − {Ss}, ( ~v , u) is not a residual edges, so in G f(v , u) = c(v , u), i.e.

c(Ss, V − {Ss}) = f(Ss, V − {Ss}) in G . In particular (Ss, V − {Ss}) is a min-cut in G and = max-flow f. 2

(14)

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:

Maximal flow through a network. Canadian J. of Math.

1956.

Ford-Fulkerson(G , s, t, c) for all (u, v ) ∈ E let f (u, v ) = 0 Gf = G

while there is an s − t path in Gf do find a simple path P in Gf (use DFS) f0= Augment(f , P)

Update f to f0 Update Gf to Gf0

end while return f

30

G f=0

Gf P

a

s t

b a

s t

b 0/30 0/10

0/10

0/20 0/15

15 10 10

20

(15)

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:

Maximal flow through a network. Canadian J. of Math.

1956.

Ford-Fulkerson(G , s, t, c) for all (u, v ) ∈ E let f (u, v ) = 0 Gf = G

while there is an s − t path in Gf do find a simple path P in Gf (use DFS) f0= Augment(f , P)

Update f to f0 Update Gf to Gf0

end while return f

20 G

Gf P

a

s t

b a

s t

b 0/10

0/20 0/15

10/10 10/30

10 10

20

f=10

15 10

(16)

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:

Maximal flow through a network. Canadian J. of Math.

1956.

Ford-Fulkerson(G , s, t, c) for all (u, v ) ∈ E let f (u, v ) = 0 Gf = G

while there is an s − t path in Gf do find a simple path P in Gf (use DFS) f0= Augment(f , P)

Update f to f0 Update Gf to Gf0

end while

return f 5

G

Gf P

a

s t

b a

s t

b 0/10

10/10 10/30

10 10

20

15/20 15/15

f=25

15 10

15

(17)

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:

Maximal flow through a network. Canadian J. of Math.

1956.

Ford-Fulkerson(G , s, t, c) for all (u, v ) ∈ E let f (u, v ) = 0 Gf = G

while there is an s − t path in Gf do find a simple path P in Gf (use DFS) f0= Augment(f , P)

Update f to f0 Update Gf to Gf0

end while return f

20 G

Gf

a

s t

b a

s t

b 10/10

10

15/15

15 10 5

15/30

10/10 f=30

15 15 20/20

No Path

(18)

Analysis of Ford Fulkerson

We are considering networks that initial flow and capacities are integers,

Lemma (Integrality invariant)

At every iteration of the Ford-Fulkerson algorithm, the flow values f (e) and the residual capacities in Gf are integers.

Proof: (induction)

I The statement is true before the while loop.

I Inductive Hypothesis: The statement is true after j iterations.

I iteration j + 1: As all residual capacities in Gf are integers, then bottleneck (P, f ) ∈ Z, for the augmenting path found in iteration j + 1. Thus the flow f0 will have integer values ⇒ so will the capacities in the new residual graph. 2

(19)

Corollary: Integrality theorem

Theorem (Integrality theorem)

There exists a max-flow f for which every flow value f is an integer.

Proof:

Since the algorithm terminates, the theorem follows from the

integrality invariant lemma. 2

(20)

Analysis of Ford Fulkerson

Lemma

If f is a flow in G and f0 is the flow after an augmentation, then

|f | < |f0|.

Proof: Let P be the augmenting path in Gf. The first edge e ∈ P leaves s, and as G has no incoming edges to s, e is a forward edge.

Moreover P is simple ⇒ never returns to s. Therefore, the value of

the flow increases in edge e. 2

(21)

Correctness of Ford-Fulkerson

Consequence of the Max-flow min-cut theorem.

Theorem

The flow returned by Ford-Fulkerson f is the max-flow.

Proof:

I For any flow f and s − t cut (S , T ) we have |f | ≤ c(S , T ).

I The flow f is such that |f| = c(S, T), for some s − t cut

(S, T) ⇒ f is the max-flow. 2

Therefore, for any (G , s, t, c) the value of the max s − t flow is equal to the capacity of the minimum s − t cut.

(22)

Analysis of Ford Fulkerson: Running time

Lemma

Let C be the min cut capacity (=max. flow value), Ford-Fulkerson terminates after finding at most C augmenting paths.

Proof: The value of the flow increases by ≥ 1 after each

augmentation. 2

I The number of iterations is ≤ C . At each iteration:

I We have to modify Gf, with E (Gf) ≤ 2m, to time O(m).

I Using DFS, the time to find an augmenting path P is O(n + m)

I Total running time isO(C (n + m)) = O(Cm)

I Is that polynomic?

(23)

Running time of Ford-Fulkerson

The number of iterations of Ford-Fulkerson could be Ω(C ) As it is described Ford-Fulkerson can alternate C times between the blue and red paths if the figure.

in a G with 4 vertices!!

a

s t

b C=1000000000

1/C

1/C 1/1 1/1 2/C 2/C

2000 million iteractions

Recall apseudopolynomial algorithm is an algorithm that is polynomial in theunary encoding of the input.

Is there a polynomial time algorithm for the max-flow problem?

(24)

Dinic and Edmonds-Karp algorithm

J.Edmonds, R. Karp: Theoretical improvements in algorithmic efficiency for network flow problems. Journal ACM 1972.

Yefim Dinic: Algorithm for solution of a problem of maximum flow in a network with power estimation. Doklady Ak.N. 1970

Choosing agood

augmenting path can lead to a faster algorithm.

Use BFS to find shorter augmenting paths in Gf.

Using BFS on Gf we can find the shortest augmenting path P in O(m + n),independently of max capacity C .

(25)

Edmonds-Karp algorithm

Greedy type algorithm: Using BFS, hoose the augmenting path Gf with the smallest number of edges. Uses BFS to find the

augmenting path at each Gf with fewer number of edges.

Edmonds-Karp(G , s, t, c)

For all e = (u, v ) ∈ E let f (u, v ) = 0 G0 = G

while there is an s t path in Gf

do

P = BFS(Gf, s, t) f0 = Augment(f , P)

Update Gf = Gf0 and f = f0 end while

return f

or a

s t

b 1 1 C C

C C

The BFS in EK will choose:

(26)

Level graph

Given G = (V , E ), s, defineLG = (V , EG) to be its the level graph by:

I `(v ) = number of edges in shortest path s v in G,

I LG = (V , EG) is the subgraph of G thatcontains only edges (v , w ) ∈ E s.t. `(w ) = `(v ) + 1.

Notice:

I Using BFS we can compute LG in O(n + m)

I Important property: P is a shortest s ; t in G iff P is an s ; t path in LG.

G s

c e

t d a

4 2

3

5 5

2 4

2

5 b

9 1

1 2 3

c e

t d a

4 2

5 5

4

2

5 b

1

1 2 3

s

G L

(27)

The working of the EK algorithm

4/5

s

c e

t d a

4 2

2

5 b

1

3 9

4

1

4 1 2

Gf

s

c e

t d a

4 2

2

5 b

1

3 9

s

c e

t d a

4

2

b 4/4

4/5

4/5 3 9

4/4

4/5

1/5

1/1

1/2

2

2 G,f G,f´

t s

c e

d a

b

L 1 s

c e

t d a

4

2

b 1

3 9

4 1

4 1 2

G

11

1 4 4

4

s 4

c e

d a

4

2

b

L 1

1/1 1/5

1/2

3 t 1/2

1/4 f’

1/1

2

3

2

(28)

The working of the EK algorithm

5/5 s

c e

t d a

b 1

3 2

1/4 1/1

1/2

1

s

c e

t d a

b 1

3 9

4

1

4 1 2

G

1

1 4 4

s

c e

t d a

b

1

1 4 2

1 1 1

3

f’’

Lf’’

s

c e

t d a

b 3

9 2

1/2

4/4

4/5

4/5

1/1 2/2

1/4 1/5

s

c e

t d a

b 9

2 4/4

4/5

2/2 1/5

1

1

1

2/4

2/2 1/1

1/3 G,f’’

G,f*

(29)

EK algorithm: Properties

Lemma

Throughout the algorithm, the length of the shortest path never decreases.

Proof:

I Let f and f0 be the flow before and after a shortest path augmentation

I let L and L0 be the levels graphs of Gf and Gf0.

I Only back edges added to Gf0. 2

Lemma

After at most m shortest path augmentations, the length of P is monotonically increasing.

Proof:

I The bottleneck edge is deleted from L after each augmentation.

I No new edge is added to L until length of shortest path

strictly increases 2

(30)

Complexity of Edmonds-Karp algorithm

Using the the previous lemmas, we prove Theorem

The EK algorithms runs in O(m2n) steps. Therefore it is a polynomial time algorithm.

Proof:

I Need time O(m + n) to find the augmenting path using BFS.

I Need O(m) augmentations for paths of length k.

I Every augmentation path is simple ⇒ 1 ≤ k ≤ n ⇒ O(nm)

augmentations 2

(31)

Finding a min-cut

Given (G , s, t, c) to find a min-cut:

1. Compute the max-flow f in G . 2. Obtain Gf.

3. Find the set S = {v ∈ V |s ; v} in Gf. 4. Output the cut

(S , V − {S }) = {(v , u)|v ∈ S andu ∈ V − {S }} in G . The running time is the same than the algorithm to find the max-flow.

S

2/2

5/5 5/5

1/1 1/5

0/9

0/3 2/4

4/4 1/2

s

c e

t b

a

2/2 d

s

c e

t b

a d

1 9 1

2 2

4

5

5 2

1 2

4 1

3

(32)

The max-flow problems: History

I Ford-Fulkerson (1956)O(mC ), where C is max capacity.

I Dinic (1970) (blocking flow) O(n2m)

I Edmond-Karp (1972) (shortest augmenting path) O(nm2)

I Karzanov (1974), O(n2m)Goldberg-Tarjant (1986) (push re-label preflow + dynamic trees) O(nm lg(n2/m)) (for this time uit uses parallel implementation)

I King-Rao-Tarjan (1998)O(nm logm/n lg nn).

I J. Orlin (2013)O(nm)(clever follow up to KRT-98) So: Maximum flows can be computed in O(nm) time!

(33)

Maximum matching problem

Given an undirected graph G = (V , E ) a subset of edges M ⊆ E is a matchingif each node appears at most in one edge (a node may not appear at all).

Aperfect matchingin G is a matching M such that |M| = |V |/2 Themaximum matching problemgiven a graph G a matching with maximum cardinality.

(34)

Maximum matching in graphs bipartite

A graph G = (V , E ) is said to bebipartiteif V can be partite in L and R, L ∪ R = V , L ∩ R = ∅, such that every e ∈ E connects L with R.

Themax matching bipartite graph problem: given a bipartite G = (L ∪ R, E ) with 2n vertices find a maximum matching.

Max matchings = 4

(35)

Maximum matching: flow formulation

Given a bipartite graph G = (L ∪ R, E ) construct ˆG = ( ˆV , ˆE ):

I Add vertices s and t: ˆV = L ∪ R ∪ {s, t}.

I Add directed edges s → L with capacity 1. Add directed edges R → t with capacity 1.

I Direct the edges E from L to R, and give them capacity ∞.

I E = {s → L} ∪ E ∪ {R → t}.ˆ

t 1

1 1

1

s

(36)

Maximum matching: flow formulation

Given a bipartite graph G = (L ∪ R, E ) construct ˆG = ( ˆV , ˆE ):

I Add vertices s and t: ˆV = L ∪ R ∪ {s, t}.

I Add directed edges s → L with capacity 1. Add directed edges R → t with capacity 1.

I Direct the edges E from L to R, and give them capacity ∞.

I E = {s → L} ∪ E ∪ {R → t}.ˆ

t 1

1 1

1

s

(37)

Maximum matching: Analysis

Theorem

Max flow in ˆG =Max bipartite matching in G . Proof ≤

Given a matching M in G with k-edges,

consider the flow F that sends 1 unit along each one of the k paths.

f is a flow and has value k.

1 1

1 1

1

s t

1 1

1 1 0

0

1 1 1

1

1 1 1

(38)

Maximum matching: Analysis

Max flow ≤Max bipartite matching

I If there is a flow f in ˆG , |f | = k, as capacities are Z ⇒ an integral flow existsis.

I Consider the cut C = ({s} ∪ L, R ∪ {t}) in ˆG .

I Let F be the set of edges in C with flow=1, then |F | = k.

I Each node in L is in at most one e ∈ F and every node in R is in at most one head of an e ∈ F

I Therefore, exists a bipartite matching F in G with |F | ≤ |f | 2

1

1 1

1

s t

1 1 1

1

1 1 1 1

1 1

1

1 0

0

(39)

Disjoint path problem

Given a digraph (G = (V , E ), s, t), a set of paths isedge-disjoint if their edges are disjoint (although them may go through some of the same vertices)

The disjoint path problemgiven G , s, t find themax number of edge disjoint paths s ; t

c

a b

e

s t

d

(40)

Disjoint path problem

Given a digraph (G = (V , E ), s, t), a set of paths isedge-disjoint if their edges are disjoint (although them may go through some of the same vertices)

The disjoint path problemgiven G , s, t find themax number of edge disjoint paths s ; t

c

a b

e

s t

d

(41)

Disjoint path problem: Max flow formulation

Assign unit capacity to every edge Theorem

The max number of edge disjoint paths s ; t is equal to the max flow value

Max flow=3

a b

e

s t

d c

a b

e

s t

d 1 c

1

1 1

1 1 1

1

1 1

1

1 1

1

1 1

1

1

1 1

1 1 1

(42)

Disjoint path problem: Proof of the Theorem

Number of disjoints paths ≤ max flow

If we have k edge-disjoints paths s; t in G then making f (e) = 1 for each e in a path, we get a flow = k

Number of disjoints paths ≥ max flow

If max flow |f| = k ⇒ ∃ 0-1 flow f with value k

⇒ ∃k edges (s, v ) s.t. f (s, v ) = 1, byflow conservationwe can extend to k paths s ; t, where each edge is a path carries flow

= 1. 2

If we have an undirected graph, with two distinguised nodes u, v , how would you apply the max flow formulation to solve the problem of finding the max number of disjoint paths between u and t?

(43)

Circulation with demands

Given a graph G = (V , E ) with capacities c in the edges, such that each v ∈ V is associate with ademand d (v ), where

I If d (v ) > 0 ⇒ v is a sink, v can receive d (v ) units of flow more than it sends.

I If d (v ) < 0 ⇒ v is a source, v can send d (v ) units of flow more than it receives.

I If d (v ) = 0 then v is neither a source or a sink.

I Define S to be the set of sources and T the set of sinks.

T

2

4

2 2

3 3

−3 2

−3 S

(44)

Circulation with demands problem

Given G = (V , E ) with c ≥ 0 and {d (v )}v ∈V, define acirculation as a function f : E → R+ s.t.

1. capacity: For each e ∈ E , 0 ≤ f (e) ≤ c(e), 2. conservation: For each v ∈ V ,

X

(u,v )∈E

f (u, v )− X

(v ,z)∈E

f (v , z) = d (v ). 2/

2

4 2

2

−3

−3

2/3 2/

1/3

2/2

Circulation with demands feasibility problem: Given G = (V , E ) with c ≥ 0 and {d (v )}v ∈V,does it exists a feasible circulation?

Feasible circulation: a function f on G with c ≥ 0 and {d (v )}v ∈V, such that it satisfies (1) and (2)?

(45)

Circulation with demands problem

Notice that if f is a feasible circulation, then

X

v ∈V

d (v ) = X

v ∈V

 X

(u,v )∈E

f (u, v )

| {z }

edges to v

− X

(v ,z)∈E

f (v , z)

| {z }

edges out of v

 .

NoticeP

v ∈V d (v ) = 0, so we have,

SoIf there is a feasible circulation with demands {d (v )}v ∈V, then P

v ∈Vd (v ) = 0.

Therefore as S = {v ∈ V |d (v ) > 0} and T = {v ∈ V |d (v ) < 0}, we can define D = −P

v ∈Sd (v ) =P

v ∈Td (v ).

2/

2

4 2

2

−3

−3

2/3

2/

1/3

2/2

(46)

Circulation with demands: Max-flow formulation

Extend G = (V , E ) to G0 = (V0, E0) by

I Add new source s and sink t.

I For each v ∈ S (d (v ) < 0) add (s, v ) with capacity −d (v ).

I For each v ∈ T (d (v ) > 0) add (v , s) with capacity d (v ).

G

2

4 2

2

−3

−3 3

2 3

2

4 2

2

−3

−3

3 3

s

t 2

3

3

2 T 4

S G’

(47)

Analysis

1.-Every flow f : s ; t in G0 must be |f | ≤ D

The capacity c({s}, V ) = D ⇒ by max-flow min-cut Thm. any max-flow f in G0, |f | ≤ D.

2.-If there is a feasible circulation f with {d (v )}v ∈V in G , then we have a max-flow f : s ; t in G with |f | = D

∀(s, v ) ∈ E0, f0(s, v ) = −d (v ) and ∀(u, t) ∈ E0, f0(u, t) = d (v ).

G’ 2

G

2

4 2

−3

−3

3 3

s

t 3

3

4 1/

2/

2/

2

4 2

2

−3

−3 3

2/2 2/3

4/

3/

3/

1/

2/

2/

2/

2/ 2/2

2

(48)

Analysis

3.-If there is a flow f0: s ; t in G0 with |f | = D:

1. ∀(s, v ) ∈ E0 and ∀(u, t) ∈ E0 must be saturated ⇒if we delete these edges in G0 we obtain a circulation f in G. 2. f satisfies d (v ) = X

(u,v )∈E

f (u, v )

| {z }

edges to v

− X

(v ,z)∈E

f (v , z)

| {z }

edges out of v

.

G’ 2

G

2

4 2

−3

−3

3 3

s

t 3

3

4 1/

2/

2/

2

4 2

2

−3

−3 3

2/2 2/3

4/

3/

3/

1/

2/

2/

2/

2/ 2/2

2

(49)

Main results

Theorem (Circulation integrality theorem)

If all capacities and demands are integers, and there exists a circulation, then there exists an integer valued circulation.

Sketch ProofMax-flow formulation + integrality theorem for

max-flow 2

From the previous discussion, we can conclude:

Theorem (Necessary and sufficient condition)

There is a feasible circulation with {d (v )}v ∈V in G iff the max-flow in G0 has value D.

(50)

Circulations with demands and lower bounds: Max-flow formulation

Generalization of the previous problem: besides satisfy demands at nodes, we want to force the flow to use certain edges.

Introduce a new constrain `(e) on each e ∈ E , indicating the min-value the flow must be on e.

Given G = (V , E ) with c(e), c(e) ≥ `(e) ≥ 0, for each e ∈ E and {d (v )}v ∈V, define acirculationas a function f : E → R+ s.t.

1. capacity: For each e ∈ E ,

`(e) ≤ f (e) ≤ c(e),

2. conservation: For each v ∈ V , X

(u,v )∈E

f (u, v )− X

(v ,z)∈E

f (v , z) = d (v ).

[

2

4

2 2

3

−3 2

−3 3] 2,

Circulation problems with lower bounds: Given (G , c, `, {d (v )}), does there exists a feasible circulation?

(51)

Circulations with demands and lower bounds:

Max-flow formulation

Let G = ((V , E ), c, `, d (·)) be a graph, construct

G0 = ((V , E ), c0, d0), where for each e = (u, v ) ∈ E , with

`(e) > 0:

I c0(e) = c(e) − `(e) (sent `(e) units along e).

I Update the demands on both ends of e:

(d0(u) = d (u) + `(e) and d0(v ) = d (v ) − `(e))

G’

2

4

2 2

3

−3 2

−3 3] [2,

2

4

2 2

3 2 1

−5

−1

G

(52)

Main result

Theorem

There exists a circulation in G iff there exists a circulation in G0. Moreover, if all demands, capacities and lower bounds in G are integers, then there is a circulation in G that is integer-valued.

Sketch ProofNeed to prove f (e) is a circulation in G iff f0(e) = f (e) − `(e) is a circulation in G0.

The integer-valued circulation part is a consequence of the

integer-value circulation Theorem for f0 in G0. 2

(53)

Applications: Generic reduction to Max Flow

Consider ageneric problemGP where we have as input s finite sets X1, . . . , Xd, each representing a different resources.

Our goal is to chose the ”largest” number of d -tuples, each d -tuple containing exactly one element from each Xi, subject to the constrains:

I For each i ∈ [d ], each x ∈ Xi can appears in at most c(x ) selected tuples.

I For each i ∈ [d ], any two x ∈ Xi and y ∈ Xi +1 can appear in at most c(x , y ) selected tuples.

I The values for c(x ) and c(x , y ) are either in Z+ or ∞.

Notice that only pairs of objects between adjacent Xi and Xi +1 are constrained.

(54)

Applications: Generic reduction to Max-Flow

Make the reduction from GP to the following input s − t network G :~

I G contains a vertex for each element x in each Xi, and a copy x0 for each element x ∈ Xi for 1 ≤ i < d .

I We add vertex s and vertex t.

I Add an edge s → x for each x ∈ X1 and add an edge y → t for every y ∈ Xd. Give capacities c(s, x ) = c(x ) and

c(y , t) = c(y ).

I Add an edge x0 → y for every pair x ∈ Xi and y ∈ Xi +1. Give a capacity c(x , y ). Omit the edges with capacity 0.

I For every x ∈ Xi for 1 ≤ i < d , add an edge x → x0 with c(x , x0) = c(x ).

Every path s; t in ~G is a feasible d -tuple, conversely every d -tuple that satisfies the constrains is a path s; t.

(55)

Flow Network: The reduction

1

x c(x) x´c(x,y) y c(y) y´

t s

c(s) c(t)

c(y,z) z

X X2 X3

So to solve GP we construct from the input a s-t network, and find the maximum flow f.

(56)

Example: Final’s scheduling

We have as input:

I n classes, each one with a final. Each exam must be given in one room. Each class ci has E [i ] students.

I r rooms. Each rj has a capacity S [j ],

I τ time slots. For each room and time slot we only can give one final.

I p professorsto watch exams. Each exam needs one professor in each class and time. Each professor has its own restrictions of availability and no professor supposed to oversee more than 6 finals. For each p` and τk define a Boolean variable

A[k, `] = T if p` is available at τk.

Design an efficient algorithm that correctly schedules a room, a time slot and a professor to every final, or report that not such schedule is possible.

(57)

Construction of the network

Construct the network ~G withvertices {s, t, {ci}, {rj}, {τk}, {p`}}.

Edges:

I s → ci, c(s, ci) = 1 (each class has one final)

I ci → rj, if E [i ] ≤ S [j ]. Then, c(ci, rj) = ∞

I ∀j, k, rj → τk, c(rj, τk) = 1 (one final per room).

I τk → p` if A[k, `] = T , c(τk, p`) = 1 (p can watch one final if p is available at τk).

I p`→ t, c(p`, t) = 6(each p can watch ≤ 6 finals)

(58)

Flow Network

1

classes

rooms

times

1 1 1

6

s

t

professors

(59)

Final’s schedule

Notice the input size to the problem is N = n + r + τ + p + 2. and size of the network is O(N) vertices and O(N2) edges, why?

Every path s t is a valid assignment of room-time-professor a single final, and every valid assignment room-time-professor a class final is represented by a path s t.

To maximize the number of finals to be given, wecompute the max-flow f from s to t.

If |f| = n then we can schedule all finals, otherwise we can not schedule all the finals.

Complexity: To construct ~G from the input, we need O( ~E ).

As |f| ≤ n, we can use Ford-Fulkerson to compute f, so the complexity of solving the problem isO(n ~E ).

(60)

Survey design problem

Problem: Design a survey among customers of products(KT-7.8)

I Each customer will receive questions about some products.

I Each customer i can only be asked about a number of products between ci (l.b.) and ci0 ([ci, ci0]) which he has purchased.

I For each product j we want to collect date for a minimum of pj distinct customers and a maximum of pj0 ([pj, p0j])

(61)

Survey design problem

Measuring customer satisfaction.

Consider n customers and m products.

Formally we want to model the problem as:

I A bipartite graph G = (C ∪ P, E ), where C = {i } is the set of customers and P = {i } is the set of products.

I There is an (i , j ) ∈ E is i has purchased product j .

I For each i ∈ {1, . . . , n}, we we have bounds [ci, ci0] on the number of products i can be asked about.

I For each j ∈ {1, . . . , n}, we we have bounds ([pj, pj0]) on the number of customers that can be asked about it.

(62)

Survey design problem: Bipartite graph G

6: [1,2]

P C

a b c d

1 2 3 4 5 6

Customers C={a,b,c,d}

Products P={1,2,3,4,5,6}

Customer a b

Buys

c d

1,2 1,2,4

3,6 3,4,5,6 G

a:[1,2]

b:[1,3]

c:[1,2]

d:[2,4]

1: [1,2]

2: [1,2]

3: [1,2]

4: [1,2]

5: [0,1]

(63)

Survey design problem: Max flow formulation

We construct G0 from G , by adding:

Edges: s → {C }, {P} → t, and (t, s).

Capacities: c(t, s) l.b. =P

ici, cap. =P

ici0 c(i , j ) = 1,

c(s, i ) = [ci, ci0], c(j , t) = [pj, pj0].

0,1 0,

p,p´

i j

s t

c,c´ 0,1

Notice if f is the flow:

I f (i , j ) = 1 ⇒ customer i is asked about product j ,

I f (s, i ) # products to ask customer i for opinion,

I f (j , t) = # customers to be asked to review product j ,

I f (t, s) is the number of questions asked.

(64)

Max flow formulation: Example

2

a b c d

1,2 1,2,4 3,6 3,4,5,6 a

b c d

1 2

3 4

5

6

a:[1,2]

b:[1,3]

c:[1,2]

1: [1,2]

2: [1,2]

3: [1,2]

4: [1,2]

5: [0,1]

6: [1,2]

s

t [1,2]

[1,3]

[1,2]

[1,2]

[1,2]

[1,2]

[1,2]

[1,2]

[0,1]

1 1

1 1 1

1

1

1 1

d:[2,3]

[2,3]

1 1 2 2

2 2 10

2 3

3

(65)

Main result

Theorem G0 has a feasible circulation iff there is a feasible way to design the survey.

Proofif there is a feasible way to design the survey:

I if i is asked about j then f (i , j ) = 1,

I f (s, i ) = number questions asked to i ,

I f (j , t) = number of customers who were asked about j ,

I f (t, s) = total number of questions.

I easy to verify that f is feasible in G0 If there is an integral, feasible circulation in G0:

I if f (i , j ) = 1 then i will be asked about j ,

I the constrains (ci, ci0, pj, pj0) will be satisfied. 2

(66)

Conclusions

Max-Flow/ Min-Cut problem is an intuitively easy problem with lots of applications.

We just presented a few ones.

An alternative point of view can be obtained from duality in Linear Programming

The material in this talk has been basically obtained from two textbooks:

I Chapter 7 of Kleinberg, Tardos: Algorithm Design.

I The Dinik-Edmond-Karp algorithm are basically inspired from an old set of lectures notes by Larry Harper in 1975, which I don’t think there are in internet.

References

Related documents