Network flow Definition: A flow network is a directed graph G = - - PowerPoint PPT Presentation

network flow definition a flow network is a directed
SMART_READER_LITE
LIVE PREVIEW

Network flow Definition: A flow network is a directed graph G = - - PowerPoint PPT Presentation

Network flow Definition: A flow network is a directed graph G = (V,E) with two nodes s and t, and a function c(u,v) 0 on each directed edge (u,v) s is called the source t is called the sink c: ER + is called the capacity


slide-1
SLIDE 1

Network flow

slide-2
SLIDE 2

Definition: A flow network is a directed graph G = (V,E) with two nodes s and t, and a function c(u,v) ≥ 0 on each directed edge (u,v)

  • s is called the source
  • t is called the sink
  • c: E→R+ is called the capacity function
  • Example

20 40 40 40 30 s t

slide-3
SLIDE 3
  • A flow f : V x V → R satisfies:

Skew symmetry: f(u,v) = - f(v,u) for every pair (u,v) Capacity constraint f(u,v) ≤ c(u,v) for each (u,v) E ∈ Conservation of flows: f(u,V) = 0 for every u {s,t}, ∉ Where we define f(X,Y) := ∑ f(x,y) over x X and y Y ∈ ∈

  • The value of flow f is | f | = f(s,V)

It represents the amount of flow passing from the source to the sink.

slide-4
SLIDE 4
  • Example

20/20 0/40 20/40 0/40 20/30 s t | f | = 20

slide-5
SLIDE 5

Maximum flow problem Input: A flow network G with s and t, a capacity function c Output: A flow f so that | f | is maximum. Applications: railway traffic, food supply, airline scheduling, image segmentation, baseball elimination...

slide-6
SLIDE 6

Residual network

  • A flow f induces a residual network Gf , consisting of the
  • riginal graph G, and residual capacity function cf :

For every (u,v) such that (u,v) or (v,u) E we set ∈ cf(u,v) := c(u,v) – f(u,v) ≥ 0. Note: the residual network may put non-zero capacity on edges which were non-existing or had zero capacity.

  • An augmenting path is a path from s to t in the residual

network

slide-7
SLIDE 7
  • Example

s

t

40 20 40 20 20 20 s t 20/20 0/40 20/40 0/40 20/30 10

f Gf

slide-8
SLIDE 8
  • Example

s

t

40 20 40 20 20 20 s t 20/20 0/40 20/40 0/40 20/30 10

f Gf

An augmenting path

slide-9
SLIDE 9

Ford—Fulkerson Algorithm Given G, s, t, c(·,·). Start with f ≡ 0 Repeat while there is an augmenting path P in Gf Let m = min(u,v) P

∈ cf(u,v).

Define f'(u,v) = m if (u,v) in P, f'(u,v) = 0 otherwise. Augment the flow by setting f = f + f'

slide-10
SLIDE 10
  • Demo

s

t

40 40 40 s t 0/20 0/40 0/40 0/40 0/30 30 20

Gf | f | = 0

slide-11
SLIDE 11
  • Demo

s

t

40 40 40 s t 0/20 0/40 0/40 0/40 0/30 30 20

Gf | f | = 0 min(u,v) P

∈ cf(u,v) = 20

slide-12
SLIDE 12
  • Demo

s

t

40 20 40 20 20 20 s t 20/20 0/40 20/40 0/40 20/30 10

| f | = 20 Gf

slide-13
SLIDE 13
  • Demo

s

t

40 20 40 20 20 20 s t 20/20 0/40 20/40 0/40 20/30 10

| f | = 20 Gf min(u,v) P

∈ cf(u,v) = 20

slide-14
SLIDE 14
  • Demo

s

t

20 20 20 20 20 s t 20/20 20/40 20/40 20/40 0/30 30

| f | = 40 Gf

20 20

slide-15
SLIDE 15
  • Demo

s

t

20 20 20 20 20 s t 20/20 20/40 20/40 20/40 0/30 30

| f | = 40 Gf

20 20

min(u,v) P

∈ cf(u,v) = 20

slide-16
SLIDE 16
  • Demo

s

t

20 20 40 s t 20/20 40/40 40/40 20/40 30/30 30

| f | = 60 Gf

20 40

slide-17
SLIDE 17
  • Demo

max | f | = 60

s

t

20 20 40 s t 20/20 40/40 40/40 20/40 30/30 30

| f | = 60 Gf

20 40

No augmenting path

slide-18
SLIDE 18

Definition: An s-t cut (S,T) is a partition S, T = V – S such that s in S and t in T. Meaning: removing the edges between S and T disconnects s and t Example: S T t 20 40 40 40 30 s

slide-19
SLIDE 19

Definition: An s-t cut (S,T) is a partition S, T = V – S such that s in S and t in T. Meaning: removing the edges between S and T disconnects s and t Example: S T t 20 40 40 40 30 s

slide-20
SLIDE 20

Definition: An s-t cut (S,T) is a partition S, T = V – S such that s in S and t in T. Meaning: removing the edges between S and T disconnects s and t The capacity of an s-t cut (S,T) is c(S,T) := ∑u S, v T

∈ ∈ c(u,v)

Example: S T T 20 40 40 40 30 S c(S,T) := 40 + 30 + 40 = 110

slide-21
SLIDE 21

Analysis of Ford—Fulkerson algorithm: Lemma: Let f be a flow. For any cut (S,T), f(S,T) = | f | Proof: Let's move x from S to T. We lose f(x,T), and we gain f(S,x). But f(x,T) = - f(x,S) because f(x,V) = 0. qed

slide-22
SLIDE 22

Theorem (Max flow-min cut): The following are equivalent:

  • 1. |f| is maximum
  • 2. the residual network has no augmenting paths
  • 3. | f | = c(S,T) for some cut (S,T)

Proof: 1 → 2: otherwise could increment the flow as said before. 2 → 3: define S := vertices reachable from s on residual

  • network. Note t S. By previous lemma, | f | = f(S,T).

∉ Now note for each edge (u,v) in S×T, f(u,v) = c(u,v), otherwise v would be in S. 3 → 1: if f is not maximum, could have a better flow. But by lemma it would augment the flow on this cut, thus violate capacity constraints. □

slide-23
SLIDE 23

Analysis of running time Fact: Let f be a flow in G. Let f' be a flow on residual network

  • Gf. Then f + f' is a flow on Gf with |f + f'| = |f| + |f'| > |f|.
slide-24
SLIDE 24

Analysis of running time Fact: Let f be a flow in G. Let f' be a flow on residual network

  • Gf. Then f + f' is a flow on Gf with |f + f'| = |f| + |f'| > |f|.

Assume the capacities are all integers. In each iteration, finding an augmentation path takes time ???

slide-25
SLIDE 25

Analysis of running time Fact: Let f be a flow in G. Let f' be a flow on residual network

  • Gf. Then f + f' is a flow on Gf with |f + f'| = |f| + |f'| > |f|.

Assume the capacities are all integers. In each iteration, finding an augmentation path takes time O(|E|) | f | increments by at least 1 Running time ???

slide-26
SLIDE 26

Analysis of running time Fact: Let f be a flow in G. Let f' be a flow on residual network

  • Gf. Then f + f' is a flow on Gf with |f + f'| = |f| + |f'| > |f|.

Assume the capacities are all integers. In each iteration, finding an augmentation path takes time O(|E|) | f | increments by at least 1 Running time O( |E| max |f|) Question: Is O( |E| max |f|) tight?

slide-27
SLIDE 27

Analysis of running time Question: Is O( |E| max |f|) tight? Yes. s t 9999 9999 9999 9999 1

slide-28
SLIDE 28

Analysis of running time Question: Is O( |E| max |f|) tight? Yes. s t 9998 9999 9998 9999 1 1 1

slide-29
SLIDE 29

Analysis of running time Question: Is O( |E| max |f|) tight? Yes. s t 9998 9998 9998 9998 1 1 1 1 1

slide-30
SLIDE 30

Analysis of running time Question: Is O( |E| max |f|) tight? Yes. s t 9997 9998 9997 9998 2 2 1 1 1

slide-31
SLIDE 31

Analysis of running time Question: Is O( |E| max |f|) tight? Yes. s t 9997 9997 9997 9997 1 2 2 2 2

slide-32
SLIDE 32

Edmonds—Karp algorithm

  • Same as Ford-Fulkerson, but each time use a shortest path

in residual network Let's run it on the previous example.

slide-33
SLIDE 33

Edmonds—Karp algorithm Edmonds—Karp on previous example: s t 0/9999 0/9999 0/9999 0/9999 0/1

slide-34
SLIDE 34

Edmonds—Karp algorithm Edmonds—Karp on previous example: s t 9999 9999 9999 9999 1

slide-35
SLIDE 35

Edmonds—Karp algorithm Edmonds—Karp on previous example: s t 9999 9999 9999 9999 1

slide-36
SLIDE 36

Analysis of Edmonds—Karp algorithm Correctness: ???

slide-37
SLIDE 37

Analysis of Edmonds—Karp algorithm Correctness: Follows from previous analysis. Running time:

slide-38
SLIDE 38

Analysis of Edmonds—Karp algorithm Correctness: Follows from previous analysis. Running time: Let δf(s,v) be the distance from s to v in Gf Lemma: Each time we update the flow, δf(s,v) does not decrease i.e. δf'(s,v) ≥ δf(s,v) for every v, for every f' after f Meaning: shortest path distances increase after each iteration.

slide-39
SLIDE 39

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f.

slide-40
SLIDE 40

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' .

slide-41
SLIDE 41

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We claim that (u,v) G ∉

f.

slide-42
SLIDE 42

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We claim that (u,v) G ∉

  • f. Otherwise,

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

slide-43
SLIDE 43

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We claim that (u,v) G ∉

  • f. Otherwise,

δf(s,v) ≤ δf(s,u) + 1 (Triangle inequality) ≤ δf' (s,u) + 1

slide-44
SLIDE 44

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We claim that (u,v) G ∉

  • f. Otherwise,

δf(s,v) ≤ δf(s,u) + 1 (Triangle inequality) ≤ δf' (s,u) + 1 (u B because δ ∉

f'(s,u) < δf'(s,v))

= δf'(s,v)

slide-45
SLIDE 45

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We claim that (u,v) G ∉

  • f. Otherwise,

δf(s,v) ≤ δf(s,u) + 1 (Triangle inequality) ≤ δf' (s,u) + 1 (u B because δ ∉

f'(s,u) < δf'(s,v))

= δf'(s,v) Contradicting our assumption. So we have (u,v) in Gf' but (u,v) G ∉

f

That means ???

slide-46
SLIDE 46

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We claim that (u,v) G ∉

  • f. Otherwise,

δf(s,v) ≤ δf(s,u) + 1 (Triangle inequality) ≤ δf' (s,u) + 1 (u B because δ ∉

f'(s,u) < δf'(s,v))

= δf'(s,v) Contradicting our assumption. So we have (u,v) in Gf' but (u,v) G ∉

f

That means the augmentation from f to f' must have (v, u) on the augmented path.

slide-47
SLIDE 47

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We have (u,v) in Gf' but (u,v) G ∉

f

That means the augmentation from f to f' must have (v, u) on the augmented path. But augmentations are along shortest paths, so δf(s,v) = δf(s,u) – 1

slide-48
SLIDE 48

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We have (u,v) in Gf' but (u,v) G ∉

f

That means the augmentation from f to f' must have (v, u) on the augmented path. But augmentations are along shortest paths, so δf(s,v) = δf(s,u) – 1 ≤ δf'(s,u) – 1

slide-49
SLIDE 49

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We have (u,v) in Gf' but (u,v) G ∉

f

That means the augmentation from f to f' must have (v, u) on the augmented path. But augmentations are along shortest paths, so δf(s,v) = δf(s,u) – 1 ≤ δf'(s,u) – 1 (because u B) ∉ = δf'(s,v) – 1 – 1

slide-50
SLIDE 50

Proof: We show that δf'(s,v) ≥ δf(s,v) if f' is right after f. Suppose not. Let v be the vertex v among B:={v: δf'(s,v) < δf(s,v)} such that δf'(s,v) is minimal. Take shortest path s ~~~> u ~> v in Gf ' . We have (u,v) in Gf' but (u,v) G ∉

f

That means the augmentation from f to f' must have (v, u) on the augmented path. But augmentations are along shortest paths, so δf(s,v) = δf(s,u) – 1 ≤ δf'(s,u) – 1 (because u B) ∉ = δf'(s,v) – 1 – 1 (because δf'(s,u) < δf'(s,v)) which contradicts our assumption. □

slide-51
SLIDE 51

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof:

slide-52
SLIDE 52

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. (i.e. (u,v) is the bottleneck edge of the augmenting path).

slide-53
SLIDE 53

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be ???

slide-54
SLIDE 54

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network.

slide-55
SLIDE 55

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network. It can only come back to the critical edge if ???

slide-56
SLIDE 56

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network. It can only come back to the critical edge if edge (v,u) is used

  • n a flow augmentation of a new residual network Gf'.
slide-57
SLIDE 57

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network. It can only come back to the critical edge if edge (v,u) is used

  • n a flow augmentation of a new residual network Gf'.

But then δf'(s,u) = δf'(s,v) + 1

slide-58
SLIDE 58

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network. It can only come back to the critical edge if edge (v,u) is used

  • n a flow augmentation of a new residual network Gf'.

But then δf'(s,u) = δf'(s,v) + 1 (since always use shortest augmentation path) ≥ δf(s,v) + 1

slide-59
SLIDE 59

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network. It can only come back to the critical edge if edge (v,u) is used

  • n a flow augmentation of a new residual network Gf'.

But then δf'(s,u) = δf'(s,v) + 1 (since always use shortest augmentation path) ≥ δf(s,v) + 1 (by previous lemma) = δf(s,u) + 1 + 1

slide-60
SLIDE 60

Theorem: Total # of flow augmentations in Edmond—Karp is O( |V| |E|) Proof: Call (u,v) critical in residual network Gf if cf(u,v) is minimial among all edges on an augmenting path. Note there is always a critical edge. After the flow augmentation, the edge will be saturated and thus will disappear from the network. It can only come back to the critical edge if edge (v,u) is used

  • n a flow augmentation of a new residual network Gf'.

But then δf'(s,u) = δf'(s,v) + 1 (since always use shortest augmentation path) ≥ δf(s,v) + 1 (by previous lemma) = δf(s,u) + 1 + 1 (again because you augment along shortest path).

slide-61
SLIDE 61
  • Note that between two times that (u,v) becomes critical, the

distance of u increases by ???

slide-62
SLIDE 62
  • Note that between two times that (u,v) becomes critical, the

distance of u increases by 2. Thus (u,v) becomes critical O(|V|) times.

slide-63
SLIDE 63
  • Note that between two times that (u,v) becomes critical, the

distance of u increases by 2. Thus (u,v) becomes critical O(|V|) times. Thus, the total # of augmentation is ???

slide-64
SLIDE 64
  • Note that between two times that (u,v) becomes critical, the

distance of u increases by 2. Thus (u,v) becomes critical O(|V|) times. Thus, the total # of augmentation is O(|V| |E|). □

slide-65
SLIDE 65
  • Note that between two times that (u,v) becomes critical, the

distance of u increases by 2. Thus (u,v) becomes critical O(|V|) times. Thus, the total # of augmentation is O(|V| |E|). □ Remark This is NOT saying every augmentation increases the distance of some node This is saying every 2 augmentations of same edge increase distance of starting point.

slide-66
SLIDE 66

Application: Maximum matching Definition: Given a bipartite graph (L R,E) ∪ . M E is a ⊂ matching if no edges in M share a vertex.

slide-67
SLIDE 67

Application: Maximum matching Definition: Given a bipartite graph (L R,E). M E is a ∪ ⊂ matching if no edges in M share a vertex. Input: a bipartite graph (L R,E) ∪ Output: max |M|

slide-68
SLIDE 68

Application: Maximum matching Definition: Given a bipartite graph (L R,E). M E is a ∪ ⊂ matching if no edges in M share a vertex. Input: a bipartite graph (L R,E) ∪ Output: max |M| Example: |M| = ???

slide-69
SLIDE 69

Application: Maximum matching Definition: Given a bipartite graph (L R,E) ∪ . M E is a ⊂ matching if no edges in M share a vertex. Input: a bipartite graph (L R,E) ∪ Output: max |M| Example: |M| = 2 |M| = 3

slide-70
SLIDE 70

Application: Maximum matching We turn it into a maximum flow problem

slide-71
SLIDE 71

Application: Maximum matching We turn it into a maximum flow problem

  • Direct every edge from L to R
slide-72
SLIDE 72

Application: Maximum matching We turn it into a maximum flow problem

  • Direct every edge from L to R
  • Add a source and a sink

s t

slide-73
SLIDE 73

Application: Maximum matching We turn it into a maximum flow problem

  • Direct every edge from L to R
  • Add a source and a sink
  • Add edges between s and vertices in L, and between t and

the vertices in R s t

slide-74
SLIDE 74

Application: Maximum matching We turn it into a maximum flow problem

  • Direct every edge from L to R
  • Add a source and a sink
  • Add edges between s and vertices in L, and between t and

the vertices in R

  • Set capacities of all edges to 1

s t 1 1 1 1 1 1 1 1 1 1 1 1

slide-75
SLIDE 75

Application: Maximum matching We turn it into a maximum flow problem Claim: Matching of size M flow of value M ∃ ⇔ ∃ Proof: ⇒:

slide-76
SLIDE 76

Application: Maximum matching We turn it into a maximum flow problem Claim: Matching of size M flow of value M ∃ ⇔ ∃ Proof: ⇒: Clear ⇐: Let f be a flow. There are |f| units. The |f| units form |f| edge-disjoint paths from s to t because ???

slide-77
SLIDE 77

Application: Maximum matching We turn it into a maximum flow problem Claim: Matching of size M flow of value M ∃ ⇔ ∃ Proof: ⇒: Clear ⇐: Let f be a flow. There are |f| units. The |f| units form |f| edge-disjoint paths from s to t because all edges have capacity 1. So there are exactly |f| edges (u,v) in (L∪R,E) with f(u,v) = 1.

slide-78
SLIDE 78

Application: Maximum matching We turn it into a maximum flow problem Claim: Matching of size M flow of value M ∃ ⇔ ∃ Proof: ⇒: Clear ⇐: Let f be a flow. There are |f| units. The |f| units form |f| edge-disjoint paths from s to t because all edges have capacity 1. So there are exactly |f| edges (u,v) in (L∪R,E) with f(u,v) = 1. No two vertices in L and R shares these edges because ???

slide-79
SLIDE 79

Application: Maximum matching We turn it into a maximum flow problem Claim: Matching of size M flow of value M ∃ ⇔ ∃ Proof: ⇒: Clear ⇐: Let f be a flow. There are |f| units. The |f| units form |f| edge-disjoint paths from s to t because all edges have capacity 1. So there are exactly |f| edges (u,v) in (L∪R,E) with f(u,v) = 1. No two vertices in L and R shares these edges because each edge touching s or t has capacity 1. So the |f| edges form a matching.□