Advanced Graph Homer Lee 2013/10/31.

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
The Maximum Network Flow Problem. CSE Network Flows.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
1 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method Maximum bipartite matching.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
The max flow problem
Maximum Flows Lecture 4: Jan 19. Network transmission Given a directed graph G A source node s A sink node t Goal: To send as much information from s.
Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 5 Wednesday, 10/4/06 Graph Algorithms: Part 2.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
Chapter 7 May 3 Ford-Fulkerson algorithm Step-by-step walk through of an example Worst-case number of augmentations Edmunds-Karp modification Time complexity.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
The Maximum Network Flow Problem
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Network Flow What is a network? Flow network and flows
Maximum Flow Chapter 26.
The Maximum Network Flow Problem
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Max-flow, Min-cut Network flow.
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
Algorithm Design and Analysis
Lectures on Network Flows
Network flow problem [Adapted from M.Chandy].
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Max-flow, Min-cut Network flow.
Network Flow 2016/04/12.
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Network Flows and Matching (Supplementary)
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 21 Network Flow
Lecture 5 Tuesday, 3/2/10 Graph Algorithms: Part 2
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
EE5900 Advanced Embedded System For Smart Infrastructure
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Text Book: Introduction to algorithms By C L R S
Lecture 21 Network Flow, Part 1
MAXIMUM flow by Eric Wengert.
Maximum Flow Neil Tang 4/8/2008
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Maximum Bipartite Matching
Presentation transcript:

Advanced Graph Homer Lee 2013/10/31

Reference Slides from Prof. Ya-Yunn Su’s and Prof. Hsueh-I Lu’s course

Today’s goal Flow networks Ford-Fulkerson (and Edmonds-Karp) Bipartite matching

Flow networks

Network A directed graph G, each of whose edges has a capacity 1 4 Network 2 * s 2 t 3 3 1 A directed graph G, each of whose edges has a capacity Two nodes s and t of G Denoted as (G,s,t)

1 1 Flow 4 2 1 2 1 s 2 t 3 2 1 3 A flow of network (G,s,t) is (weighted) subgraph of G satisfying the capacity constraint and the conservation law

1 1 4 2 1 2 Capacity constraint 1 s 2 3 2 1 3 Given capacity constraint function c, for all u,v∈V, 0 ≤ f(u,v) ≤ c(u,v) 流過edge的flow大小要小於流量限制 常表示為圖的edge的weight

Conservation Law For all 𝑢 ∈𝑉 −{𝑠,𝑡} , 𝑣∈𝑉 𝑓 𝑢,𝑣 = 𝑣∈𝑉 𝑓 𝑣,𝑢 1 1 4 2 1 2 Conservation Law 1 s 2 3 2 1 3 For all 𝑢 ∈𝑉 −{𝑠,𝑡} , 𝑣∈𝑉 𝑓 𝑢,𝑣 = 𝑣∈𝑉 𝑓 𝑣,𝑢 換句話說,流進來的等於流出去的 上面的sigma是對所有的v,那假如u,v沒有接在一起 怎麼辦? => If (u,v)∉ E, f(u,v) = 0

What’s maximum flow problem? The value of a flow is denoted as |f| |f| = 𝑣∈𝑉 𝑓 𝑠,𝑣 − 𝑣∈𝑉 𝑓 𝑣,𝑠 Given flow network (G,s,t) => Find a flow of maximum value

A famous theorem Maximum flow  Minimum cut

How to solve the problem? 1 2 1 s 2 t 2 1 1

Ford-Fulkerson Idea: Iteratively increase the value of the flow Start with f(u,v) = 0 In each iteration Find an augmenting path in the residual network 𝐺 𝑓 Until no more augmenting paths exist

Residual Network What if we choose the wrong path? Just give it a second chance!! For each edge (u,v) in G,construct 𝐺 𝑓 If f(u,v) > 0, 𝐺 𝑓 has an edge (v,u) with weight f(u,v) If c(u,v) ≥ f(u,v) 𝐺 𝑓 has an edge (u,v) with weight c(u,v) – f(u,v)

illustration s t 3 1 4 2 1 1 2 1 2 s 1 t 2 1 2 1 1

Some notes Why adding an edge if c(u,v) ≥ f(u,v) ? | E 𝑓 |≤ 2|E|,Why? 讓他有回頭的機會 | E 𝑓 |≤ 2|E|,Why? Residual Networks上的edges會是原本Flow network 有的edge (with different weight) 或反方向 You can try to prove it by simply using case analysis.

How can residual network help us? Lemma: Let G = (V,E) be a flow network, and let f be a flow in G. Let 𝐺 𝑓 be the residual network of G induced by f. Let g be a flow in 𝐺 𝑓 . Then f+g = is a valid flow in G. Idea: capacity constraint and flow conservation still holds.

Augmenting paths Given a flow network G and a flow f, an augmenting path is a simple path from s to t in the residual network 𝐺 𝑓 簡單的來說,就是在residual network上找一條可以 走的路

How can Augmenting paths help us? There exists an augmenting path => there exist some potential flow in the path => By the capacity constraint, trivially the maximum flow in the path = min{ 𝐶 𝑓 (u,v)|(u,v) is on augmenting path}

How do we know when we have found maximum flow? From the maximum-flow-minimum-cut theorem, we stop when its residual graph contains no augmenting graph 2 equivalent things: 1. f is a maximum flow in G 2. The residual network 𝐺 𝑓 contains no augmenting path

Let’s prove it! f is a maximum flow in G => The residual network 𝐺 𝑓 contains no augmenting path => is simple, use contradiction. If 𝐺 𝑓 still contains augmenting paths, then we can still find 𝑓 𝑝 to add to f. Then result in bigger flow |f| + | 𝑓 𝑝 | > |f|

Let’s prove it!! Goal: f is a maximum flow in G <= The residual network 𝐺 𝑓 contains no augmenting path Equivalent statement: f is not a maximum flow in G => The residual network 𝐺 𝑓 contains some augmenting path If h is a flow whose value larger than that of f, then g = h – f has to be a positive flow in 𝐺 𝑓

Let’s prove it!!! Goal: f is not a maximum flow in G <= The residual network 𝐺 𝑓 contains some augmenting path Here provides a sketch of the proof If h is a flow whose value larger than that of f, then g = h – f has to be a positive flow in 𝐺 𝑓 Then why g has to be a positive flow in 𝐺 𝑓 ? Do the remaining job by yourself!

Pseudo code Ford-Folkerson (G,s,t){ for each edge (u,v) in G.E (u,v).f = 0 while there exists an augmenting path p in residual network 𝐺 𝑓 𝒄 𝒇 (𝐩) = min( 𝒄 𝒇 (u,v) | (u,v) is on p) for each edge (u,v) on p //雙向都要考慮 if (u,v) ∈ E, (u,v).f += 𝒄 𝒇 𝐩 else, (v,u).f -= 𝒄 𝒇 𝐩 }

Example: 1 4 2 s 2 t 3 3 1

Running time analysis Initializing part: O(E) How to find a path in residual network? BFS or DFS What time complexity does it take? | E 𝑓 | ≤ 2|E| It takes O(V+ E 𝑓 ) = O(E) times

Running time analysis If the edge capacity are integer, and f be the maximum flow of the network The for-loop may be executed at most f times(increment by 1 unit at a time) Each time takes O(E) times Totally O(E)+O(E)*O(f) = O(Ef) => This depends on f, not a good idea

Issues What is C is not an integer?(each time the amount that the augmenting path adding has no lower-bound) How can we improve this bound? (Edmonds-Karp)

To improve the time complexity A key observation: Let P be a shortest path from s to t in the residual network 𝐺 𝑓 . Let g be the flow corresponding to P. Then, the distance of any nodes v from s in 𝐺 𝑓+𝑔 is no less than that in 𝐺 𝑓 IDEA: If the above thing holds, it seems that the update times will be bounded

2 1 3 2 1 2 1 s 2 t 3 1 1 2 3 1 1 2 2 2 1 1 1 1 1 1 3 2 2 1 1 1 2 1

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

2 2 3 3 2 2 1 s 2 t 3 3 2 3 2 2 ∞ ∞ 3 2 2 1 1 ∞ 3 1 ∞ ∞ 2

Proof of the monotonically increased distance Assume for contradiction that there is a node v whose distance d*(v) in 𝐺 𝑓+𝑔 is less than its distance d(v) in 𝐺 𝑓 Let Q be a shortest path from s to v in 𝐺 𝑓+𝑔 There has to be some node u on Q such that d*(u) ≥ d(u).(s is such a u.) So we can assume Q = s~u->v, so d*(v) = d*(u)+1 and (u,v)∈ 𝐺 𝑓+𝑔 . such u exists. v s u

That’s what we said last page Note: d*(u) ≤ d(u) v s v u

Proof-contd. Claim: (u,v) cannot be an edge in 𝐺 𝑓 since the following contradiction: d(v) ≤ d(u)+1 ≤ d*(u)+1 = d*(v) Since (u,v) belongs to 𝐺 𝑓+𝑔 but not 𝐺 𝑓 , we know g goes from v to u, but still reach the following contradiction: d(v) = d(u)-1 ≤ d*(u)-1 = d*(v)-2