Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).

Slides:



Advertisements
Similar presentations
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Advertisements

Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
Chapter 25: All-Pairs Shortest-Paths
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)
CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007.
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 
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
1 The Max Flow Problem. 2 Flow networks Flow networks are the problem instances of the max flow problem. A flow network is given by 1) a directed graph.
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
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)
CSC 2300 Data Structures & Algorithms April 17, 2007 Chapter 9. Graph Algorithms.
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.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
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
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
1 Advanced Algorithms All-pairs SPs DP algorithm Floyd-Warshall alg.
Shortest Paths Definitions Single Source Algorithms
Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching.
All-Pairs Shortest Paths
Maximum flow Algorithms and Networks. A&N: Maximum flow2 Today Maximum flow problem Variants Applications Briefly: Ford-Fulkerson; min cut max flow theorem.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 5 Tuesday, 10/7/08 Graph Algorithms: Part 2.
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.
1 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f p output f Runs in time O(|f max | |E|) where f.
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.
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
Flow Networks Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut.
Maximum Flow Chapter 26.
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
All-pairs Shortest Paths. p2. The structure of a shortest path: All subpaths of a shortest path are shortest paths. p : a shortest path from vertex i.
Maximum Flow. p2. Maximum Flow A flow network G=(V, E) is a DIRECTED graph where each has a nonnegative capacity u.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows.
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.
All-Pairs Shortest Paths
Algorithm Design and Analysis (ADA)
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Flow Networks Ching-Chen Huang Hsi-Yue Hsiao. CONTENTS Network flows on directed acyclic graphs Ford-fulkerson Algorithms -Residual networks.
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
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
The Maximum Network Flow Problem
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Network flow problem [Adapted from M.Chandy].
Network Flows and Matching (Supplementary)
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Flow Networks Topics Flow Networks Residual networks
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
Text Book: Introduction to algorithms By C L R S
Presentation transcript:

Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).

COSC 3101NJ. Elder All-Pairs Shortest Paths

Given a directed graph G = (V, E), weight function w : E → R, |V| = n. Assume no negative weight cycles. Goal: create an n × n matrix of shortest-path distances δ(u, v). Could run BELLMAN-FORD once from each vertex: O(V 2 E)—which is O(V 4 ) if the graph is dense (E =  (V2)). If no negative-weight edges, could run Dijkstra’s algorithm once from each vertex: O(V E lg V) with binary heap—O(V 3 lg V) if dense, We’ll see how to do in O(V 3 ) in all cases, with no fancy data structure.

All Pairs Shortest Path – Floyd-Warshall Algorithm Dynamic programming approach. Use optimal substructure of shortest paths: Any subpath of a shortest path is a shortest path. Create a 3-dimensional table: Let d ij (k) –shortest path weight of any path from i to j where all intermediate vertices are from the set {1,2, …, k}. Ultimately, we would like to know the values of d ij (n).

Computing d ij (k) Base condition: d ij (0) = ? d ij (0) = w ij. For k>0: Let p= be a shortest path from vertex i to vertex j with all intermediate vertices in {1,2, …, k}. If k is not an intermediate vertex, then all intermediate vertices are in {1,2, …, k-1}. If k is an intermediate vertex, then p is composed of 2 shortest subpaths drawn from {1,2, …, k-1}.

Recursive Formulation for d ij (k)

Algorithm Running time = ? O(n 3 ). Memory required = ? O(n 2 ) (if we drop the superscripts).

Example

Step 1

Step 2

Step 3

Step 4

Step 5

All-Pairs Shortest Path: Johnson’s Algorithm Idea: If the graph is sparse (|E|<<|V| 2 ), it pays to run Dijkstra’s algorithm once from each vertex. O(VE log V) using binary heap, O(V 2 log V + V E) using Fibonacci heap. But Dijkstra’s algorithm does not handle negative edges. Johnson’s Algorithm: reweight edges to form equivalent graph with non-negative edges. Floyd-Warshall still has advantages: very simple implementation no fancy data structures small constant.

COSC 3101NJ. Elder The Maximum Network Flow Problem

The Problem Use a graph to model material that flows through conduits. Each edge represents one conduit, and has a capacity, which is an upper bound on the flow rate = units/time. Can think of edges as pipes of different sizes. But flows don’t have to be of liquids. Want to compute max rate that we can ship material from a designated source to a designated sink.

What is a Flow Network? Each edge (u,v) has a nonnegative capacity c(u,v). If (u,v) is not in E, assume c(u,v)=0. We have a source s, and a sink t. Assume that every vertex v in V is on some path from s to t. c(s,v 1 )=16; c(v 1,s)=0; c(v 2,v 3 )=0

What is a Flow in a Network? For each edge (u,v), the flow f(u,v) is a real-valued function that must satisfy 3 conditions: Note that skew symmetry condition implies that f(u,u)=0.

Example of a Flow: f(v 2, v 1 ) = 1, c(v 2, v 1 ) = 4. f(v 1, v 2 ) = -1, c(v 1, v 2 ) = 10. f(v 3, s) + f(v 3, v 1 ) + f(v 3, v 2 ) + f(v 3, v 4 ) + f(v 3, t) = 0 + (-12) (-7) + 15 = 0 flow capacity

The Value of a flow The value of a flow is given by This it the total flow leaving s = the total flow arriving in t.

Example: |f| = f(s, v 1 ) + f(s, v 2 ) + f(s, v 3 ) + f(s, v 4 ) + f(s, t) = = 19 |f|= f(s, t) + f(v 1, t) + f(v 2, t) + f(v 3, t) + f(v 4, t) = = 19

A flow in a network We assume that there is only flow in one direction at a time. Sending 7 trucks from Edmonton to Calgary and 3 trucks from Calgary to Edmonton has the same net effect as sending 4 trucks from Edmonton to Calgary.

Multiple Sources Network We have several sources and several targets. Want to maximize the total flow from all sources to all targets. Reduce to max-flow by creating a supersource and a supersink:

The Ford-Fulkerson Method Try to improve the flow, until we reach the maximum. The residual capacity of the network with a flow f is given by: Always nonnegative (why?)

Example of residual capacities Network: Residual Network: Augmenting path

The residual network The edges of the residual network are the edges on which the residual capacity is positive.

Augmenting Paths An augmenting path p is a simple path from s to t on the residual network. We can put more flow from s to t through p. We call the maximum capacity by which we can increase the flow on p the residual capacity of p.

Augmenting Paths - example The residual capacity of p = 4. Can improve the flow along p by 4.

Ford-Fulkerson Method

Example Flow(1) Residual(1) Flow(2) Residual(2) No more augmenting paths  max flow attained.

Augmenting Paths – example The maximum possible flow through the cut = = 23 The network has a capacity of at most 23. This is called a minimum cut. Flow(2)

Cuts of Flow Networks A cut in a network is a partition of V into S and T=V-S so that s is in S and t is in T.

The net flow through a cut (S,T) f(S,T) = 12 – = 19

The capacity of (S,T) c(S,T)= = 26

Lemma 26.5 For any cut (S,T), the net flow across (S,T) is f(S,T)=|f|.

Corollary 26.6 The value of any flow f in a flow network G is bounded from above by the capacity of any cut of G.

Theorem 26.7 (Max-flow min-cut theorem) If f is a flow in a flow network G=(V,E), with source s and sink t, then the following conditions are equivalent: 1. f is a maximum flow in G. 2. The residual network G f contains no augmented paths. 3. |f| = c(S,T) for some cut (S,T) (a min-cut).

The Basic Ford-Fulkerson Algorithm

Example Resulting Flow = Original Network augmenting path 4

Example Resulting Flow = 4 Residual Network augmenting path

Example Residual Network Resulting Flow = 11

Example Resulting Flow = 11 Residual Network augmenting path

Example Residual Network Resulting Flow = 19

Example Resulting Flow = 19 Residual Network augmenting path

Example Residual Network Resulting Flow = 23

Residual Network Example Resulting Flow = 23 No augmenting path: Maxflow=23

Analysis O(E)

Analysis If capacities are all integer, then each augmenting path raises |f| by ≥ 1. If max flow is f*, then need ≤ |f*| iterations ⇒ time is O(E|f*|). Note that this running time is not polynomial in input size. It depends on |f*|, which is not a function of |V| or |E|. If capacities are rational, can scale them to integers. If irrational, FORD-FULKERSON might never terminate!

The basic Ford-Fulkerson Algorithm With time O ( E |f*|), the algorithm is not polynomial. This problem is real: Ford-Fulkerson may perform very badly if we are unlucky: |f*|=2,000,000

Run Ford-Fulkerson on this example Augmenting Path Residual Network

Run Ford-Fulkerson on this example Augmenting Path Residual Network

Run Ford-Fulkerson on this example Repeat 999,999 more times…

The Edmonds-Karp Algorithm A small fix to the Ford-Fulkerson algorithm makes it work in polynomial time. Specify how to compute the path in line 4.

The Edmonds-Karp Algorithm Compute the path in line 4 using breadth-first search on residual network. The augmenting path p is the shortest path from s to t in the residual network (treating all edge weights as 1). Runs in time O(V E 2 ).

The Edmonds-Karp Algorithm - example Edmonds-Karp’s algorithm runs only 2 iterations on this graph.

Further Improvements Push-relabel algorithm ([CLRS, 26.4]) – O(V 2 E). The relabel-to-front algorithm ([CLRS, 26.5) – O(V 3 ).