CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007.

Slides:



Advertisements
Similar presentations
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Advertisements

1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
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.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
1 Maximum Flow w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2 
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
1 Efficient implementation of Dinic’s algorithm for maximum flow.
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)
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
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.
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
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
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.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
1 Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
1 Efficient implementation of Dinic’s algorithm for maximum flow.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 5 Wednesday, 10/4/06 Graph Algorithms: Part 2.
CSE 326: Data Structures Graph Algorithms Graph Search Lecture 23 1.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
CS774. Markov Random Field : Theory and Application Lecture 13 Kyomin Jung KAIST Oct
Lecture 5: Network Flow Algorithms Single-Source Shortest-Path (SSSP) (Dijkstra's Algorithm) Max Flow - Min Cut (Ford-Fulkerson) Job Sequencing.
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Maximum Flow. p2. Maximum Flow A flow network G=(V, E) is a DIRECTED graph where each has a nonnegative capacity u.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
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.
1 Network Flow CSC401 – Analysis of Algorithms Chapter 8 Network Flow Objectives: Flow networks –Flow –Cut Maximum flow –Augmenting path –Maximum flow.
Fall 2003Maximum Flow1 w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2 
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
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)
Honors Track: Competitive Programming & Problem Solving Push-Relabel Algorithm Claire Claassen.
CSE 326: Data Structures Graph Algorithms Graph Search Lecture 23
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
Richard Anderson Lecture 23 Network Flow
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
Efficient implementation of Dinic’s algorithm for maximum flow
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Network Flows and Matching (Supplementary)
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
Network Flow CSE 373 Data Structures.
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
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Richard Anderson Lecture 22 Network Flow
Presentation transcript:

CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007

2 Network Flows Given a weighted, directed graph G=(V,E) Treat the edge weights as capacities How much can we flow through the graph? A C B D F H G E I

3 Network flow: definitions Define special source s and sink t vertices Define a flow as a function on edges: –Capacity: f(v,w) <= c(v,w) –Skew symmetry: f(v,w) = -f(w,v) –Conservation:for all u except source, sink –Value of a flow: –Saturated edge: when f(v,w) = c(v,w)

4 Network flow: definitions Capacity: you can’t overload an edge Skew symmetry: sending f from u  v implies you’re “sending -f”, or you could “return f” from v  u Conservation: Flow entering any vertex must equal flow leaving that vertex We want to maximize the value of a flow, subject to the above constraints

5 Example (1) Capacity

6 Example (2) 3/3 0/2 1/1 2/2 0/4 3/4 Flow / Capacity Are all the constraints satisfied?

7 Main idea: Ford-Fulkerson method Start flow at 0 “While there’s room for more flow, push more flow across the network!” –While there’s some path from s to t, none of whose edges are saturated –Push more flow along the path until some edge is saturated –Called an “augmenting path”

8 How do we know there’s still room? Construct a residual graph: –Same vertices –Edge weights are the “leftover” capacity on the edges –Add extra edges for backwards-capacity too! –If there is a path s  t at all, then there is still room

9 Example (1) A BC D FE Flow / Capacity Initial graph – no flow

10 Example (2) A BC D FE 0/3 0/2 0/1 0/2 0/4 Flow / Capacity Residual Capacity Include the residual capacities

11 Example (3) 1/3 0/2 1/1 0/2 0/4 1/4 Flow / Capacity Residual Capacity A BC D FE Augment along ABFD by 1 unit (which saturates BF)

12 Example (4) 3/3 0/2 1/1 2/2 0/4 3/4 Flow / Capacity Residual Capacity A BC D FE Augment along ABEFD (which saturates BE and EF)

13 Now what? There’s more capacity in the network… …but there’s no more augmenting paths But we broke our own rules – didn’t build the residual graph correctly

14 Example (5) 3/3 0/2 1/1 2/2 0/4 3/4 Flow / Capacity Residual Capacity Backwards flow A BC D FE Add the backwards edges, to show we can “undo” some flow

15 Example (6) 3/3 2/2 1/1 0/2 2/2 2/4 3/4 Flow / Capacity Residual Capacity Backwards flow A BC D FE 2 Augment along AEBCD (which saturates AE and EB, and empties BE)

16 Example (7) 3/3 2/2 1/1 0/2 2/2 2/4 3/4 Flow / Capacity Residual Capacity Backwards flow A BC D FE Final, maximum flow

17 How should we pick paths? Two very good heuristics (Edmonds-Karp): –Pick the largest-capacity path available Otherwise, you’ll just come back to it later…so may as well pick it up now –Pick the shortest augmenting path available For a good example why…

18 Bad example A B C D 0/2000 0/1 Augment along ABCD, then ACBD, then ABCD, then ACBD… Should just augment along ACD, and ABD, and be finished

19 Running time? Each augmenting path can’t get shorter…and it can’t always stay the same length –So we have at most O(E) augmenting paths to compute for each possible length, and there are only O(V) possible lengths. –Each path takes O(E) time to compute Total time = O(E 2 V)

20 One more definition on flows We can talk about the flow from a set of vertices to another set, instead of just from one vertex to another: –Should be clear that f(X,X) = 0 –So the only thing that counts is flow between the two sets

21 Network cuts Intuitively, a cut separates a graph into two disconnected pieces Formally, a cut is a pair of sets (S, T), such that and S and T are connected subgraphs of G

22 Minimum cuts If we cut G into (S, T), where S contains the source s and T contains the sink t, What is the minimum flow f(S, T) possible?

23 Example (8) A BC D FE T S Capacity of cut = 5

24 Coincidence? NO! Max-flow always equals Min-cut Why? –If there is a cut with capacity equal to the flow, then we have a maxflow: We can’t have a flow that’s bigger than the capacity cutting the graph! So any cut puts a bound on the maxflow, and if we have an equality, then we must have a maximum flow. –If we have a maxflow, then there are no augmenting paths left Or else we could augment the flow along that path, which would yield a higher total flow. –If there are no augmenting paths, we have a cut of capacity equal to the maxflow Pick a cut (S,T) where S contains all vertices reachable in the residual graph from s, and T is everything else. Then every edge from S to T must be saturated (or else there would be a path in the residual graph). So c(S,T) = f(S,T) = f(s,t) = |f| and we’re done.

25

26 Single-Source Shortest Path Given a graph G = (V, E) and a single distinguished vertex s, find the shortest weighted path from s to every other vertex in G. All-Pairs Shortest Path: Find the shortest paths between all pairs of vertices in the graph. How?

27 Analysis Total running time for Dijkstra’s: O(|V| log |V| + |E| log |V|) (heaps) What if we want to find the shortest path from each point to ALL other points?

28 Dynamic Programming Algorithmic technique that systematically records the answers to sub-problems in a table and re-uses those recorded results (rather than re-computing them). Simple Example: Calculating the Nth Fibonacci number. Fib(N) = Fib(N-1) + Fib(N-2)

29 Floyd-Warshall for (int k = 1; k =< V; k++) for (int i = 1; i =< V; i++) for (int j = 1; j =< V; j++) if ( ( M[i][k]+ M[k][j] ) < M[i][j] ) M[i][j] = M[i][k]+ M[k][j] Invariant: After the kth iteration, the matrix includes the shortest paths for all pairs of vertices (i,j) containing only vertices 1..k as intermediate vertices

30 abcde a b c--0-1 d---04 e----0 b c d e a Initial state of the matrix: M[i][j] = min(M[i][j], M[i][k]+ M[k][j])

31 abcde a b-0-21 c--0-1 d---04 e----0 b c d e a Floyd-Warshall - for All-pairs shortest path Final Matrix Contents