The Maximum Network Flow Problem. CSE 3101 2 Network Flows.

Slides:



Advertisements
Similar presentations
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.
Advertisements

1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
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)
CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007.
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 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.
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
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.
Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
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
Flow Networks Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
Section 2.9 Maximum Flow Problems Minimum Cost Network Flows Shortest Path Problems.
CS774. Markov Random Field : Theory and Application Lecture 13 Kyomin Jung KAIST Oct
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
Announcements Network Flow today, depending on how far we get, we will do String Matching on Wednesday Then Review for Final next Monday This week’s lab.
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.
Announcements Assignment 4: Due Monday, April 5 at Midnight (due to university regulations). Submit solutions to any 2 of the 4 problems. Responsible.
MAX FLOW APPLICATIONS CS302, Spring 2012 David Kauchak.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
Maximum Flow Problem (Thanks to Jim Orlin & MIT OCW)
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.
Chapter 7 April 28 Network Flow.
15.082J and 6.855J March 4, 2003 Introduction to Maximum Flows.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
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.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
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 Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Network flow problem [Adapted from M.Chandy].
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
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
Lecture 22 Network Flow, Part 2
Presentation transcript:

The Maximum Network Flow Problem

CSE Network Flows

CSE Types of Networks Internet Telephone Cell Highways Rail Electrical Power Water Sewer Gas …

CSE Maximum Flow Problem How can we maximize the flow in a network from a source or set of sources to a destination or set of destinations? The problem reportedly rose to prominence in relation to the rail networks of the Soviet Union, during the 1950's. The US wanted to know how quickly the Soviet Union could get supplies through its rail network to its satellite states in Eastern Europe. In addition, the US wanted to know which rails it could destroy most easily to cut off the satellite states from the rest of the Soviet Union. It turned out that these two problems were closely related, and that solving the max flow problem also solves the min cut problem of figuring out the cheapest way to cut off the Soviet Union from its satellites. Source: lbackstrom, The Importance of Algorithms, at

CSE Instance: A Network is a directed graph G Edges represent pipes that carry flow Each edge (u,v) has a maximum capacity c(u,v) A source node s in which flow arrives A sink node t out which flow leaves Goal: Max Flow Network Flow Figure courtesy of J. Edmonds

CSE 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, in units/time. Can think of edges as pipes of different sizes. Want to compute max rate that we can ship material from a designated source to a designated sink.

CSE 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. e.g., c(s,v 1 )=16; c(v 1,s)=0; c(v 2,v 3 )=0

CSE 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: Notes: The skew symmetry condition implies that f(u,u)=0. We show only the positive flows in the flow network.

CSE 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

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

CSE 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

CSE 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.

CSE 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:

CSE Residual Networks The residual capacity of an edge (u,v) in a network with a flow f is given by: The residual network of a graph G induced by a flow f is the graph including only the edges with positive residual capacity, i.e.,

CSE Example of Residual Network Flow Network: Residual Network:

CSE 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.

End of Lecture 14 April 22, 2009

CSE Augmenting Paths Network: Residual Network: Augmenting path The residual capacity of this augmenting path is 4.

CSE Computing Max Flow Classic Method: –Identify augmenting path –Increase flow along that path –Repeat

CSE Ford-Fulkerson Method

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

CSE Cuts of Flow Networks

CSE The Net Flow through a Cut (S,T) f(S,T) = 12 – = 19

CSE The Capacity of a Cut (S,T) c(S,T)= = 26

CSE Augmenting Paths – example Capacity of the cut = maximum possible flow through the cut = = 23 The network has a capacity of at most 23. In this case, the network does have a capacity of 23, because this is a minimum cut. Flow(2) cut

CSE Net Flow of a Network The net flow across any cut is the same and equal to the flow of the network |f|.

CSE Bounding the Network Flow The value of any flow f in a flow network G is bounded from above by the capacity of any cut of G.

CSE 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).

CSE The Basic Ford-Fulkerson Algorithm

CSE Example Original Network augmenting path 4 Resulting Flow = Flow Network

CSE Example Resulting Flow = 4 Flow Network Residual Network Flow Network Resulting Flow = 11 augmenting path

CSE Example Resulting Flow = 11 Flow Network Residual Network Flow Network Resulting Flow = 19 augmenting path

CSE Example Resulting Flow = 19 Flow Network Residual Network Flow Network Resulting Flow = 23 augmenting path

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

CSE Analysis O(E) ?

CSE 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!

CSE 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

CSE Run Ford-Fulkerson on this example Augmenting Path Residual Network

CSE Run Ford-Fulkerson on this example Augmenting Path Residual Network

CSE Run Ford-Fulkerson on this example Repeat 999,999 more times… Can we do better than this?

CSE The Edmonds-Karp Algorithm A small fix to the Ford-Fulkerson algorithm makes it work in polynomial time. Select the augmenting path 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 ).

CSE The Edmonds-Karp Algorithm - example The Edmonds-Karp algorithm halts in only 2 iterations on this graph.

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

An Application of Max Flow: Maximum Bipartite Matching

CSE Maximum Bipartite Matching A bipartite graph is a graph G=(V,E) in which V can be divided into two parts L and R such that every edge in E is between a vertex in L and a vertex in R. e.g. vertices in L represent skilled workers and vertices in R represent jobs. An edge connects workers to jobs they can perform.

CSE A matching in a graph is a subset M of E, such that for all vertices v in V, at most one edge of M is incident on v.

CSE A maximum matching is a matching of maximum cardinality (maximum number of edges). not maximum maximum

CSE A Maximum Matching No matching of cardinality 4, because only one of v and u can be matched. In the workers-jobs example a max-matching provides work for as many people as possible. v u

CSE Solving the Maximum Bipartite Matching Problem Reduce the maximum bipartite matching problem on graph G to the max-flow problem on a corresponding flow network G’. Solve using Ford-Fulkerson method.

CSE Corresponding Flow Network To form the corresponding flow network G' of the bipartite graph G: –Add a source vertex s and edges from s to L. –Direct the edges in E from L to R. –Add a sink vertex t and edges from R to t. –Assign a capacity of 1 to all edges. Claim: max-flow in G’ corresponds to a max-bipartite-matching on G. s L R t G  G’

CSE Solving Bipartite Matching as Max Flow

CSE Does this mean that max |f| = max |M|? Problem: we haven’t shown that the max flow f(u,v) is necessarily integer-valued.

CSE Integrality Theorem If the capacity function c takes on only integral values, then: 1.The maximum flow f produced by the Ford-Fulkerson method has the property that |f| is integer-valued. 2.For all vertices u and v the value f(u,v) of the flow is an integer. So max|M| = max |f|

CSE Example min cut |M| = 3  max flow =|f|= 3

CSE Conclusion Network flow algorithms allow us to find the maximum bipartite matching fairly easily. Similar techniques are applicable in other combinatorial design problems.

CSE Example In a department there are n courses and m instructors. Every instructor has a list of courses he or she can teach. Every instructor can teach at most 3 courses during a year. The goal: find an allocation of courses to the instructors subject to these constraints.