CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths and Network Flow.

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.
CSEP 521 Applied Algorithms Richard Anderson Lecture 7 Dynamic Programming.
CSE 421 Algorithms Richard Anderson Lecture 23 Network Flow Applications.
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)
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 
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
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.
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.
Minimum Cost Flow Lecture 5: Jan 25. Problems Recap Bipartite matchings General matchings Maximum flows Stable matchings Shortest paths Minimum spanning.
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.
CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths.
CSEP 521 Applied Algorithms
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness and course wrap up.
Chapter 7 April 28 Network Flow.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
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.
Exercise 6.1 Find the number of different shortest paths from point A to point B in a city with perfectly horizontal streets and vertical avenues as shown.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 23.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
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.
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,
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Flow A flow f for a network N is is an assignment of an integer value f(e) to each edge e that satisfies the following properties: Capacity Rule: For each.
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
Submodularity Reading Group Minimum Cut, Dinic’s Algorithm
Lectures on Network Flows
Richard Anderson Lecture 23 Network Flow
Maximum Flow 9/13/2018 6:12 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
Lecture 22 Network Flow, Part 2
Shortest Paths with Dynamic Programming
Network Flow 2016/04/12.
Edmonds-Karp Algorithm
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
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
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Network Flow and Connectivity in Wireless Sensor Networks
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Richard Anderson Lecture 23 Network Flow Applications
Richard Anderson Lecture 20 LCS / Shortest Paths
Analysis of Algorithms
Richard Anderson Lecture 21 Shortest Path Network Flow Introduction
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Richard Anderson Lecture 21 Shortest Paths
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
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
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 23 Network Flow Applications
Richard Anderson Lecture 20 Shortest Paths and Network Flow
Lecture 22 Network Flow, Part 2
Richard Anderson Lecture 22 Network Flow
Richard Anderson Lecture 20 Space Efficient LCS
Memory Efficient Dynamic Programming / Shortest Paths
Presentation transcript:

CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths and Network Flow

Shortest Paths with Dynamic Programming

Shortest Path Problem Dijkstra’s Single Source Shortest Paths Algorithm –O(mlog n) time, positive cost edges Bellman-Ford Algorithm –O(mn) time for graphs with negative cost edges

Shortest paths with a fixed number of edges Find the shortest path from v to w with exactly k edges

Express as a recurrence Opt k (w) = min x [Opt k-1 (x) + c xw ] Opt 0 (w) = 0 if v=w and infinity otherwise

Algorithm, Version 1 foreach w M[0, w] = infinity; M[0, v] = 0; for i = 1 to n-1 foreach w M[i, w] = min x (M[i-1,x] + cost[x,w]);

Algorithm, Version 2 foreach w M[0, w] = infinity; M[0, v] = 0; for i = 1 to n-1 foreach w M[i, w] = min(M[i-1, w], min x (M[i-1,x] + cost[x,w]))

Algorithm, Version 3 foreach w M[w] = infinity; M[v] = 0; for i = 1 to n-1 foreach w M[w] = min(M[w], min x (M[x] + cost[x,w]))

Correctness Proof for Algorithm 3 Key lemma – at the end of iteration i, for all w, M[w] <= M[i, w]; Reconstructing the path: –Set P[w] = x, whenever M[w] is updated from vertex x

If the pointer graph has a cycle, then the graph has a negative cost cycle If P[w] = x then M[w] >= M[x] + cost(x,w) –Equal when w is updated –M[x] could be reduced after update Let v 1, v 2,…v k be a cycle in the pointer graph with (v k,v 1 ) the last edge added –Just before the update M[v j ] >= M[v j+1 ] + cost(v j+1, v j ) for j < k M[v k ] > M[v 1 ] + cost(v 1, v k ) –Adding everything up 0 > cost(v 1,v 2 ) + cost(v 2,v 3 ) + … + cost(v k, v 1 ) v2v2 v3v3 v1v1 v4v4

Negative Cycles If the pointer graph has a cycle, then the graph has a negative cycle Therefore: if the graph has no negative cycles, then the pointer graph has no negative cycles

Finding negative cost cycles What if you want to find negative cost cycles?

Foreign Exchange Arbitrage USDEURCAD USD EUR CAD USD CADEUR USD CADEUR

Network Flow

Outline Network flow definitions Flow examples Augmenting Paths Residual Graph Ford Fulkerson Algorithm Cuts Maxflow-MinCut Theorem

Network Flow Definitions Capacity Source, Sink Capacity Condition Conservation Condition Value of a flow

Flow Example u st v

Flow assignment and the residual graph u st v 15/20 20/20 15/30 0/10 5/10 u st v

Network Flow Definitions Flowgraph: Directed graph with distinguished vertices s (source) and t (sink) Capacities on the edges, c(e) >= 0 Problem, assign flows f(e) to the edges such that: –0 <= f(e) <= c(e) –Flow is conserved at vertices other than s and t Flow conservation: flow going into a vertex equals the flow going out –The flow leaving the source is a large as possible

Flow Example a s d b cf e g h i t

Find a maximum flow a s d b cf e g h i t Value of flow: Construct a maximum flow and indicate the flow value

Find a maximum flow a s d b cf e g h i t

Augmenting Path Algorithm Augmenting path –Vertices v 1,v 2,…,v k v 1 = s, v k = t Possible to add b units of flow between v j and v j+1 for j = 1 … k-1 u st v 10/20 15/20 10/30 0/10 5/10

Find two augmenting paths st 2/5 0/1 3/4 3/3 2/4 1/3 3/3 2/2 3/4 1/3 3/3 2/2 3/3 1/3 2/2 1/3

Residual Graph Flow graph showing the remaining capacity Flow graph G, Residual Graph G R –G: edge e from u to v with capacity c and flow f –G R : edge e’ from u to v with capacity c – f –G R : edge e’’ from v to u with capacity f

Residual Graph u st v 15/20 20/20 15/30 0/10 5/10 u st v

Build the residual graph s d e g h t 3/5 2/4 3/3 1/5 1/1 3/3 2/5 s d e g h t Residual graph:

Augmenting Path Lemma Let P = v 1, v 2, …, v k be a path from s to t with minimum capacity b in the residual graph. b units of flow can be added along the path P in the flow graph. u st v 15/20 20/20 15/30 0/10 5/10 u st v

Proof Add b units of flow along the path P What do we need to verify to show we have a valid flow after we do this? –

Ford-Fulkerson Algorithm (1956) while not done Construct residual graph G R Find an s-t path P in G R with capacity b > 0 Add b units along in G If the sum of the capacities of edges leaving S is at most C, then the algorithm takes at most C iterations