Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow...

73
Max-flow and min-cut

Transcript of Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow...

Page 1: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Max-flow and min-cut

Page 2: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Max-Flow problem: Introduction

This slides deal with the problem of finding a fast algorithm for theMaximum flow problem (Max-Flow).

The Max-Flow problem consists: Given as input,

I a directed graph ~G , with two distinguished verticess, t ∈ V ( ~G ), such that s has not incoming edges and t hasnot exiting edges, and

I given a positive integer weight for each edge, which indicatedthe maximum capacity though that edge.

We want to find the maximum amount of flow that we can sendfrom s to t, constrained at each edge by its maximum capacity.(Formal definitions will be given).

Page 3: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Max-Flow problem

Intuitively, the Max-Flow problem has a nice simile in a network ofpipes to transport water from a source s to t, where s is a sourceof water and t is a sink of water, as a pool or a faucet. Theamount of water we can send is constrained by the diameter of thedifferent pipes.

There are beautiful algorithmic issues arising from the solution ofthe Max-Flow problem itself. However, the most important issue isthat an efficient solution to the Max-Flow, will allow us to developefficient solution for a myriad of apparently unrelated optimizationproblems.

The main idea is that if we have an efficient solution for Max-Flow,we can solve a myriad of non-trivial optimization problems byreducing each problem to a version of Max-Flow:Network connectivity, airline schedule, image segmentation,bipartite matching, data mining, · · · · · ·

Page 4: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Max-Flow problem: How to construct the reduction

For instance, we shall see and efficient algorithm for the surveydesign problem: Given a company that sells a large set of productsand a has a large number of clients that buy some products, wewant to design an efficient algorithm to survey the customersatisfaction (the degree of appreciation by customers of eachproduct).

The solution we present is a polynomial time reduction from thesurvey design problem (no network involved here) to a variant ofthe network flow problem.

That is, given and input to the survey design problem, inpolynomial time we construct an input to the Max-flow networkproblem, so a polynomial time algorithm for the Max-Flow problemyields a polynomial time algorithm for the survey design problem.

Page 5: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Road-map for the slides

1 We present the basic Max-Flow problem and its associate dualthe minimum (capacity) cut problem (Min-Cut). As we willsee the Min-Cut problem consists in finding a 2-partition ofthe vertices in the network, which minimized the capacity ofthe edges between the partition.

2 We present the basic technique to develop polynomial timealgorithms: Residual networks and augmenting paths. Wepresent the basic Max-flow vs. Min-cut Theorem, which is akey concept to understand this set of slides.

3 We present two polynomial time algorithms for Max-Flow.The first based on DFS is nice and simple, but not alwaysyield a polynomial time solution. The second based on BFS ismore complicated but it is always polynomial.

Page 6: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Road-map for the slides

4 We present some applications of the developed algorithms forMax-Flow, to problems on netwoks, as designing polynomialtime algorithms for finding the Min-Cut in a network, findingthe maxum bisection in a bipartite graph, or finding disjointpaths s ; t in a network.

5 We follow with some variation models of the basic Max-flowproblem, which are useful to reduce to, from particularoptimization problems.

6 Finally, we present some examples of applications for thepreviously described technique, for a set of two differentproblems: Exam scheduling and the mentioned survey design.

Page 7: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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

21

1

2

Flow f : 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,∑u∈V f (u, v) =

∑z∈V f (v , z)

I The value of a flow

|f | =∑v∈V

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

a

s t

b

2

1

2 1

2/ 1

21/ 2/

1/

1/

Page 8: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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/41/2

2/2

s

a d

t

e

b

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

Therefore the total flow is maximum.

Page 9: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

The s − t cut

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

The flow across the cut:f (S) =

∑u∈S

∑v∈T f (u, v)−

∑v∈S

∑u∈T f (v , u).

The capacity of the cut: c(S) =∑

u∈S∑

v∈T c(u, v)

capacity of cut (S ,T ) = sum of weights leaving 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/41/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

Page 10: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

The s − t cut

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

The flow across the cut:f (S) =

∑u∈S

∑v∈T f (u, v)−

∑v∈T

∑u∈S f (v , u).

The capacity of the cut: c(S) =∑

u∈S∑

v∈T c(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/41/2

s

c e

t

d

b

aS = s,c,a

T=d,b,e,t

c(S,T)=2+5+5=12

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

Page 11: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

An example Min-Cut = Max-Flow

The next example gives the intuition why the Min-Cut in Cdetermines the Max-Flow in G .

c(S,T)=1 therefore Maxflow=1t

a

b

c

d e

f

g

s 110

10 1010

10 10 10

101010

10

S=s,a,b,c,d T=e,f,g,t

Page 12: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Changing weights effect on Min-Cut and Max-Flow

Given a network (G = (V ,E ), s, t, c(e)) such that ∀e ∈ E ,c(e) ∈ Z+, and assume G a Min-Cut (S ,T ). If we change theinput by adding 1 to the capacity of every edge, then it mayhappen than (S ,T ) is not longer the Min-Cut of the new input, asthe below counterexample indicates,

2

4 5

11

1 1

11

2 2

22

2

Page 13: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Having a network with rational cpacities

Recall that a rational number is the fraction of two integers (3/4or 7/5). So far we have considered capacities that are integers.However, everything we have said, also works if we considernetworks with rational capacities.

The reason is that given a network with rational capacities, we cantransform it into a new network with the same topology, andmultiplying all capacities by the least common multiple (m.c.m.)of all capacities.For instance if c(e1) = 3/2, c(e2) = 2/3, c(e3) = 5/6, c(e4) = 3then mcm (2, 3, 6, 1) = 6 andc ′(e1) = 9, c ′(e2) = 4, c ′(e3) = 5, c ′(e4) = 18.

Page 14: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Notation

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

I Denote f (S ′,T ) flow between S ′ and T (without going by v).i.e. f (S ′,T ) =

∑u∈S′

∑w∈T f (u,w)−

∑w∈T

∑u∈S′ f (w , u) with

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

I denote f (v ,T ) flow v → T i.e. f (v ,T ) =∑

u∈T f (v , u),

I denote f (T , v) flow T → v i.e. f (T , v) =∑

u∈T f (u, v),

I denote f (S ′, v) flow S ′ → v i.e. f (S ′, v) =∑

u∈S ′ f (u, v),

I denote f (v ,S ′) flow v → S ′ i.e. f (v ,S ′) =∑

u∈S ′ f (v , u),

ts

v

T

S

S’

Page 15: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Any s − t cut has the same flow

TheoremGiven (G , s, t, c) the flow through any s − t cut (S ,T ) isf (S) = |f |.Proof (Induction on |S |)I If S = s then f (S) = |f |.I Assume it is true for S ′ = S − v, i.e. f (S ′) = |f |.

Notice f (S ′) = f (S ′,T ) + f (S ′, v)− f (v , S ′). Moreover fromthe flow conservation, f (S ′, v) + f (T , v) = f (v , S ′) + f (v ,T )⇒ f (v ,T )− f (T , v) = f (S ′, v)− f (v ,S ′)︸ ︷︷ ︸

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

f (S) = f (S ′) = |f | 2

ts

v

T

S

S’

Page 16: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Residual networkGiven a network (G = (V ,E ), s, t, c) together with a flow f on it,the residual network, (Gf = (V ,Ef ), cf ) is the network with thesame vertex set and edge set:

I if c(u, v)− f (u, v) > 0 then (u, v) ∈ Ef andcf (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 canundo, 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/2a

t

b

2

2

21

1

1

Gf

Page 17: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Residual network: Augmenting paths

Given G = (V ,E ) and a flow f on G , an augmenting path P isany simple path in Gf (using forward and backward edges, butP : s t).

Given f : s t in G and P in Gf define the bottleneck (P, f ) to bethe 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

1s 2

1

1

P: dotted line

GfG

a

t

b

s

11/

1/1 2/2

2/2

Page 18: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Residual network: Augmenting paths

Given G = (V ,E ) and a flow f on G , an augmenting path P isany simple path in Gf .

Given f s → t in G and P in Gf define the bottleneck (P, f ) to bethe minimum residual capacity of 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 thenIncrease f (u, v) in G by b

elseDecrease f (u, v) in G by b

end ifend forreturn f

Page 19: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Residual network: Augmenting paths

LemmaConsider f ′ =Augment(P, f ), then f ′ is a flow in G .

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

I Capacity law Forward edges (u, v) ∈ P we increase f (u, v) byb, as b ≤ c(u, v)− f (u, v) thenf ′(u, v) = f (u, v) + b ≤ c(u, v).Backward edges (u, v) ∈ P we decrease f (v , u) by b, asb ≤ f (v , u), f ′(v , u) = f (u, v)− b ≥ 0.

I Conservation law, ∀v ∈ P given edges e1, e2 in P and incidentto v , it is easy to check the 4 cases based whether e1, e2 areforward or backward edges. 2

Page 20: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Max-Flow Min-Cut theorem

Theorem: For any (G , s, t, c) the value of the max flow f ∗ is equalto 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 paths ; t so it is disconnected.Let Ss = v ∈ V |∃s ; v in Gf ∗, then (Ss ,V − Ss) is as − t cut in Gf ∗ ⇒ ∀v ∈ Ss , u ∈ V − Ss, ( ~v , u) is not aresidual 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

Page 21: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:Maximal flow through anetwork. Canadian J. of Math.1956.

Ford-Fulkerson(G , s, t, c)for all (u, v) ∈ E let f (u, v) = 0Gf = Gwhile there is an s − t path in Gf do

find a simple path P in Gf (use DFS)f ′ = Augment(f ,P)Update f to f ′

Update Gf to Gf ′

end whilereturn f

30

G f=0

Gf

P

a

s t

b

a

s t

b

0/300/10

0/10

0/20 0/15

15

10

10

20

Page 22: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:Maximal flow through anetwork. Canadian J. of Math.1956.

Ford-Fulkerson(G , s, t, c)for all (u, v) ∈ E let f (u, v) = 0Gf = Gwhile there is an s − t path in Gf do

find a simple path P in Gf (use DFS)f ′ = Augment(f ,P)Update f to f ′

Update Gf to Gf ′

end whilereturn 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

Page 23: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:Maximal flow through anetwork. Canadian J. of Math.1956.

Ford-Fulkerson(G , s, t, c)for all (u, v) ∈ E let f (u, v) = 0Gf = Gwhile there is an s − t path in Gf do

find a simple path P in Gf (use DFS)f ′ = Augment(f ,P)Update f to f ′

Update Gf to Gf ′

end whilereturn 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

Page 24: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Ford-Fulkerson algorithm

L.R. Ford, D.R. Fulkerson:Maximal flow through anetwork. Canadian J. of Math.1956.

Ford-Fulkerson(G , s, t, c)for all (u, v) ∈ E let f (u, v) = 0Gf = Gwhile there is an s − t path in Gf do

find a simple path P in Gf (use DFS)f ′ = Augment(f ,P)Update f to f ′

Update Gf to Gf ′

end whilereturn f 5

G

Gf

a

s t

b

a

s t

b

10/10

10

15/15

15

15/30

f=30

15

15

20/20

No Path

20

5/10

5

Page 25: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Analysis of Ford Fulkerson

We are considering networks that initial flow and capacities areintegers,

Lemma (Integrality invariant)

At every iteration of the Ford-Fulkerson algorithm, the flow valuesf (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 initeration j + 1. Thus the flow f ′ will have integer values ⇒ sowill the capacities in the new residual graph. 2

Page 26: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Corollary: Integrality theorem

Theorem (Integrality theorem)

There exists a max-flow f ∗ for which every flow value f ∗ is aninteger.

Proof:Since the algorithm terminates, the theorem follows from theintegrality invariant lemma. 2

Page 27: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Analysis of Ford Fulkerson

LemmaIf f is a flow in G and f ′ is the flow after an augmentation, then|f | < |f ′|.Proof: Let P be the augmenting path in Gf . The first edge e ∈ Pleaves 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 ofthe flow increases in edge e. 2

Page 28: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Correctness of Ford-Fulkerson

Consequence of the Max-flow min-cut theorem.

TheoremThe 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 isequal to the capacity of the minimum s − t cut.

Page 29: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Analysis of Ford Fulkerson: Running time

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

Proof: The value of the flow increases by ≥ 1 after eachaugmentation. 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 isO(n + m)

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

I Is that polynomic?

Page 30: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Running time of Ford-Fulkerson

Notice the fact of using a DFS yields the possibility of choosingthe path s → a→ b → c.

The number of iterations ofFord-Fulkerson could be Ω(C )As it is described Ford-Fulkerson canalternate C times between the blueand 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 a pseudopolynomial algorithm is an algorithm that ispolynomial in the unary encoding of the input.

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

Page 31: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Dinic and Edmonds-Karp algorithm

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

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

Choosing a goodaugmenting path can leadto a faster algorithm.Use BFS to find shorteraugmenting paths in Gf .

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

Page 32: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Edmonds-Karp algorithm

Greedy type algorithm: Using BFS, hoose the augmenting path Gf

with the smallest number of edges. Uses BFS to find theaugmenting 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) = 0G0 = Gwhile there is an s t path in Gf

doP = BFS(Gf , s, t)f ′ = Augment(f ,P)Update Gf = Gf ′ and f = f ′

end whilereturn f

or

a

s t

b

11

CC

C C

The BFS in EK will

choose:

Page 33: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Level graphGiven G = (V ,E ), s, define LG = (V ,EG ) to be its the level graphby:

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

I LG = (V ,EG ) is the subgraph of G that contains 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 ans ; t path in LG .

G

s

c e

t

da

42

3

5

5

2 4

2

b5

9 1

1 2 3

c e

t

da

42

5

5

4

2

b5

1

1 2 3

s

G L

Page 34: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

The working of the EK algorithm

4/5

s

c e

t

da

42

2

b5

1

3

9

4

1

4

1

2

G f

s

c e

t

da

42

2

b5

1

3

9

s

c e

t

da

4

2

b

4/4

4/5

4/5

3

9

4/4

4/5

1/5

1/11/2

22

G,f´G,f

t s

c e

da

b

1L

s

c e

t

da

4

2

b

1

3

9

4

1

4

1

2

G

11

1

44

4

4s

c e

da

4

2

b

1L

1/1

1/5

1/2

t3

1/2

1/4

f’

1/1

23

2

Page 35: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

The working of the EK algorithm

5/5

s

c e

t

da

b

1

3

2

1/41/1

1/2

1

s

c e

t

da

b

1

3

9

4

1

4

1

2

G

1

1

4

4

s

c e

t

da

b

1

1

24

111

3

f’’

L f’’

s

c e

t

da

b 3

9

2

1/2

4/4

4/5

4/5

1/12/21/4

1/5

s

c e

t

da

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*

Page 36: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

EK algorithm: Properties

LemmaThroughout the algorithm, the length of the shortest path neverdecreases.

Proof:I Let f and f ′ be the flow before and after a shortest path

augmentationI let L and L′ be the levels graphs of Gf and Gf ′ .I Only back edges added to Gf ′ . 2

LemmaAfter at most m shortest path augmentations, the length of P ismonotonically 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

Page 37: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Complexity of Edmonds-Karp algorithm

Using the the previous lemmas, we prove

TheoremThe EK algorithms runs in O(m2n) steps. Therefore it is apolynomial 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

Page 38: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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 ∈ Sandu ∈ V − S in G .

The running time is the same than the algorithm to find themax-flow.

S

2/2

5/5

5/5

1/1

1/5

0/9

0/3

2/4

4/41/2

s

c e

tb

a

2/2d

s

c e

tb

a d

1

19

2

2

4

5

5

2

1

2

4

1

3

Page 39: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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) (pushre-label preflow + dynamic trees) O(nm lg(n2/m)) (for thistime uit uses parallel implementation)

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

I J. Orlin (2013) O(nm) (clever follow up to KRT-98)

So: Maximum flows can be computed in O(nm) time!

Page 40: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Maximum Matching problem

Given an undirected graph G = (V ,E ) a subset of edges M ⊆ E isa matching if each node appears at most in one edge (a node maynot appear at all).

A perfect matching in G is a matching M such that |M| = |V |/2

The Maximum Matching problem: Given as input a graph G ,find a matching with maximum cardinality.

Page 41: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Maximum matching in graphs bipartiteA graph G = (V ,E ) is said to be bipartite if V can be partite in Land R, L ∪ R = V , L ∩ R = ∅, such that every e ∈ E connects Lwith R.

The Maximum Matching Bipartite Graph problem: Givenas input a bipartite graph G = (L ∪ R,E ) with 2n vertices, find amaximum matching.

Max matchings = 4

Page 42: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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

Page 43: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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

Page 44: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Maximum matching algorithm: Analysis

TheoremMax 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 kpaths.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

Page 45: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Maximum matching algorithm: Analysis

Max flow ≤Max bipartite matching

I If there is a flow f in G , |f | = k , as capacities are Z∗ ⇒ anintegral 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 isin 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

Page 46: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Disjoint Path problem

Given a digraph (G = (V ,E ), s, t), a set of paths is edge-disjoint iftheir edges are disjoint (although them may go through some ofthe same vertices)

Disjoint Path problem: Given as input G , s, t, find the maxnumber of edge disjoint paths s ; t

c

a b

e

st

d

Page 47: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Disjoint Path problem

Given a digraph (G = (V ,E ), s, t), a set of paths is edge-disjoint iftheir edges are disjoint (although them may go through some ofthe same vertices)

The disjoint path problem given G , s, t find the max number ofedge disjoint paths s ; t

c

a b

e

st

d

Page 48: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Disjoint Path: Max flow formulation

Assign unit capacity to every edge

TheoremThe max number of edge disjoint paths s ; t is equal to the maxflow value

Max flow=3

a b

e

st

d

c

a b

e

st

d

c1

1

11

1

1

1

1

1

1

11

1

1

11

1

1

1

1

1

1

1

Page 49: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Disjoint Path: Proof of the Theorem

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

Number of disjoints paths ≥ max flowIf max flow |f ∗| = k ⇒ ∃ 0-1 flow f ∗ with value k⇒ ∃k edges (s, v) s.t. f (s, v) = 1, by flow conservation we canextend 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 problemof finding the max number of disjoint paths between u and t?

Page 50: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Circulation with demands

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

I If d(v) > 0 ⇒ v is a sink, v canreceive d(v) units of flow morethan it sends.

I If d(v) < 0 ⇒ v is a source, v cansend d(v) units of flow more thanit receives.

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

I Define S to be the set of sourcesand T the set of sinks.

T

2

4

2 2

3 3

2−3

−3

S

Page 51: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Circulation with demands problem

We introduce a variation of the basic network-flow problem, todeal with supply and demand optimization problems.Given G = (V ,E ) with c ≥ 0 and d(v)v∈V , define a circulationas a function f : E → R+ s.t.

1. capacity: For eache ∈ E , 0 ≤ f (e) ≤ c(e),

2. conservation: For each v ∈ V ,∑(u,v)∈E

f (u, v)−∑

(v ,z)∈E

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

2

4

2

2

−3

−3

2/ 3

2/

31/

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)?

Notice that it may not exists always a feasible circulation.

Page 52: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Circulation with demands problem

Notice that if f is a feasible circulation, then

∑v∈V

d(v) =∑v∈V

(u,v)∈E

f (u, v)

︸ ︷︷ ︸edges to v

−∑

(v ,z)∈E

f (v , z)

︸ ︷︷ ︸edges out of v

.

Notice∑

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

So If there is a feasible circulation with demands d(v)v∈V , then∑v∈V d(v) = 0.

Therefore as S = v ∈ V |d(v) > 0 andT = v ∈ V |d(v) < 0, we can defineD = −

∑v∈S d(v) =

∑v∈T d(v).

2/

2

4

2

2

−3

−3

2/ 3

2/

31/

2/ 2

Page 53: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Circulation with demands: Max-flow formulation

Extend G = (V ,E ) to G ′ = (V ′,E ′) 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).

G2

4

2

2

−3

−3

3

2

3

2

4

2

2

−3

−3

33

s

t

2

3

3

2

4T

S

G’

Page 54: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Analysis

1.- Every flow f : s ; t in G ′ must be |f | ≤ DThe capacity c(s,V ) = D ⇒ by max-flow min-cut Thm. anymax-flow f in G ′, |f | ≤ D.

2.- If there is a feasible circulation f with d(v)v∈V in G , then wehave a max-flow f : s ; t in G with |f | = D∀(s, v) ∈ E ′, f ′(s, v) = −d(v) and ∀(u, t) ∈ E ′, f ′(u, t) = d(v).

2G’G2

4

2

−3

−3

33

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

Page 55: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Analysis

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

1. ∀(s, v) ∈ E ′ and ∀(u, t) ∈ E ′ must be saturated ⇒ if wedelete these edges in G ′ we obtain a circulation f in G .

2. f satisfies d(v) =∑

(u,v)∈E

f (u, v)

︸ ︷︷ ︸edges to v

−∑

(v ,z)∈E

f (v , z)

︸ ︷︷ ︸edges out of v

.

2G’G2

4

2

−3

−3

33

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

Page 56: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Main results

Theorem (Circulation integrality theorem)

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

Sketch Proof Max-flow formulation + integrality theorem formax-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 themax-flow in G ′ has value D.

Page 57: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Circulations with demands and lower bounds: Max-flowformulation

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 themin-value the flow must be on e.

Given G = (V ,E ) with c(e), c(e) ≥ `(e) ≥ 0, for each e ∈ E andd(v)v∈V , define a circulation as a function f : E → R+ s.t.

1. capacity: For each e ∈ E ,`(e) ≤ f (e) ≤ c(e),

2. conservation: For each v ∈ V ,∑(u,v)∈E

f (u, v)−∑

(v ,z)∈E

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

[

2

4

2 2

3

2−3

−3

3]2,

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

Page 58: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Circulations with demands and lower bounds:Max-flow formulation

Let G = ((V ,E ), c , `, d(·)) be a graph, constructG ′ = ((V ,E ), c ′, d ′), where for each e = (u, v) ∈ E , with`(e) > 0:

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

I Update the demands on both ends of e:(d ′(u) = d(u) + `(e) and d ′(v) = d(v)− `(e))

G’2

4

2 2

3

2−3

−3

3]2,[

2

4

2 2

3

2

1

−5

−1

G

Page 59: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Main result

TheoremThere exists a circulation in G iff there exists a circulation in G ′.Moreover, if all demands, capacities and lower bounds in G areintegers, then there is a circulation in G that is integer-valued.

Sketch Proof Need to prove f (e) is a circulation in G ifff ′(e) = f (e)− `(e) is a circulation in G ′.The integer-valued circulation part is a consequence of theinteger-value circulation Theorem for f ′ in G ′. 2

Page 60: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Applications: Generic reduction to Max Flow

Consider a generic problem GP where we have as input d finitesets X1, . . . ,Xd , each representing a different resources.Our goal is to chose the ”largest” number of d-tuples, eachd-tuple containing exactly one element from each Xi , subject tothe 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 inat 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 areconstrained.

Page 61: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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 copyx ′ 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 → tfor every y ∈ Xd . Give capacities c(s, x) = c(x) andc(y , t) = c(y).

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

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

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

Page 62: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Flow Network: The reduction

1

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

ts

c(t)c(s)

c(y,z)z

X X X2 3

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

Page 63: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Final’s Scheduling

We have as input:

I n courses, each one with a final. Each exam must be given inone room. Each course 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 giveone final.

I p professors to watch exams. Each exam needs one professorin each class and time. Each professor has its own restrictionsof availability and no professor supposed to oversee more than6 finals. For each p` and τk define a Boolean variableA[k , `] = T if p` is available at τk .

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

Page 64: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Construction of the network

Construct the network ~G with vertices s, t, ci, rj, τk, p`.Edges:

I s → ci , c(s, ci ) = 1 (each course 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)

Page 65: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Final’s Scheduling: Flow Network

courses

roomstimes

1 11

6

s

t

professors

1

Page 66: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Final’s Scheduling

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

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

To maximize the number of finals to be given, we compute themax-flow f ∗ from s to t.If |f ∗| = n then we can schedule all finals, otherwise we can notschedule 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 thecomplexity of solving the problem is O(n~E ).

Page 67: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Survey Design problemProblem: 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 ofproducts between ci (l.b.) and c ′i ([ci , c

′i ]) which he has

purchased.

I For each product j we want to collect date for a minimum ofpj distinct customers and a maximum of p′j ([pj , p

′j ])

Page 68: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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 ofcustomers 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 , c′i ] on the

number of products i can be asked about.

I For each j ∈ 1, . . . , n, we we have bounds ([pj , p′j ]) on the

number of customers that can be asked about it.

Page 69: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Survey Design: Bipartite graph G

6: [1,2]

PC

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,63,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]

Page 70: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Survey Design: Max flow formulation

We construct G ′ from G , by adding:Edges: s → C, P → t, and(t, s).Capacities: c(t, s)l.b. =

∑i ci , cap. =

∑i c′i

c(i , j) = 1,c(s, i) = [ci , c

′i ],

c(j , t) = [pj , p′j ].

0,1

0,

p,p´ji

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.

Page 71: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

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

11

d:[2,3]

[2,3]1

1

2

2

2

2

10

2

3

3

Page 72: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Main result

Theorem G ′ has a feasible circulation iff there is a feasible way todesign the survey.

Proof if 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 G ′

If there is an integral, feasible circulation in G ′:

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

I the constrains (ci , c′i , pj , p

′j) will be satisfied. 2

Page 73: Max- ow and min-cutmjserna/docencia/grauA/P20... · Max-Flow problem Intuitively, the Max-Flow problem has a nice simile in a network of pipes to transport water from a source s to

Conclusions

Max-Flow/ Min-Cut problem is an intuitively easy problem withlots of applications.We just presented a few ones. A peculiar nice, but difficult,example is the Image Segmentation algorithm (see for ex 7.10 inKleinberg, Tardos: Algorithm Design).An alternative point of view can be obtained from duality in LinearProgramming

The material in this talk has been basically obtained from twotextbooks:

I Chapter 7 of Kleinberg, Tardos: Algorithm Design.

I The Dinik-Edmond-Karp algorithm are basically inspired froman old set of lectures notes by Larry Harper in 1975, whichcan’t be found in internet.