Data Structures & Algorithms Network Flow Richard Newman based on book by R. Sedgewick.

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.
Lecture 5: Network Flow Algorithms Max-Flow Min-Cut Single-Source Shortest-Path (SSSP) Job Sequencing.
Max Flow Problem Given network N=(V,A), two nodes s,t of V, and capacities on the arcs: uij is the capacity on arc (i,j). Find non-negative flow fij for.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Chapter 6 Maximum Flow Problems Flows and Cuts Augmenting Path Algorithm.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
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
Lectures on Network Flows
1 Maximum Flow Networks Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘capacity’ u ij. Goal: Determine the maximum amount.
HW2 Solutions. Problem 1 Construct a bipartite graph where, every family represents a vertex in one partition, and table represents a vertex in another.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
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, 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.
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.
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
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.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
Maximum Flow Problem (Thanks to Jim Orlin & MIT OCW)
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)
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.
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.
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
11/21/02CSE Max Flow CSE Algorithms Max Flow Problems.
Maximum Flow - Anil Kishore Graph Theory Basics. Prerequisites What is a Graph Directed, Weighted graphs How to traverse a graph using – Depth First Search.
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
Contest Algorithms January 2016 Describe the maxflow problem, explain the Ford-Fulkerson, Edmonds-Karp algorithms. Look at the mincut problem, bipartite.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
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
CS4234 Optimiz(s)ation Algorithms
Lectures on Network Flows
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 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
CSE Algorithms Max Flow Problems 11/21/02 CSE Max Flow.
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
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
Maximum Flow Neil Tang 4/8/2008
Lecture 22 Network Flow, Part 2
Presentation transcript:

Data Structures & Algorithms Network Flow Richard Newman based on book by R. Sedgewick

Network Flow Problems Weighted, digraph G, or network May have cost per unit flow for edges May have maximum flow per edge May have max production rates May have required consumption rate per sink

Distribution Problems Merchandise distribution – Sources with production rates – Sinks with consumption rates – Distribution centers Input rate = output rate – Channels with maximum rate and unit cost for distribution

Merchandise distribution Get product to retail locations cheaply Retail Locations Factories Distribution Centers

Transportation Problems Communications – Max total data rate between a source and sink – Cheapest way to move a given amount of data from s to t Traffic flow – Minimize evacuation time – Minimize total cost

Transportation Problem No channel capacity restrictions Get product to retail locations cheaply Demand Supply Channels

Matching Problems Job placement – Interviews + job offers – Maximize number of placements Min-distance point matching – Two sets A and B of N points each – Find set of N segments matching an element from A with one from B that has lowest cost

Matching Problem Maximize placements (matching) Applicant Employer Offers

Cut Problems Network reliability – What is minimum number of lines that must be cut to disconnect two switches? Supply line cutting – What is the minimum supply line destruction required to ensure no troops get supplies?

Cut Problem How few edges must be cut to disrupt delivery May have edge weights also Troops Supplies Delivery paths

Network Flow Problems Generic problems Maxflow – What is maximum flow between s and t? Mincost-flow – What is cheapest cost way to achieve a particular flow?

Network Flow Flow Networks Maxflow Algorithms Maxflow Reductions Mincost Flows Network Simplex Algorithm

Flow Networks Defn 22.1: A network with a single source and a single sink is an s-t network

Flow Networks Defn 22.2: A flow network is an s-t network with positive edge weights, called capacities. A flow in a flow network is a set of non-negative edge weights called edge flows satisfying: No edge flow exceeds capacity In flow = out flow for interior nodes

Flow Network Maximize flow subject to capacity and conservation of flow Refinery Oil Field Pipelines and Valves Is this OK?

Flow Network Can we do better? Refinery Oil Field Pipelines and Valves

Flow Network Are we done? Is this OK? Refinery Oil Field Pipelines and Valves

Flow Network Now are we done? Yep Refinery Oil Field Pipelines and Valves

Flow Network Sum of flows into a node is called inflow Sum of flows out of a node is called outflow Conservation of flow: except for source and sink, inflow = outflow Feasible flow = obeys constraints (max flow and conservation of flow)

Flow Network Set outflow from sink to zero Set inflow to source to zero Outflow of source = inflow of sink This is called network's value

Maximum Flow Given an s-t network, find a flow such that no other flow from s to t has a larger value. A flow like this is called a maxflow. Problem of finding one is called the maxflow problem.

Augmenting Path Maximum Flow First algorithm like this due to Ford and Fulkerson Iteratively: Find a feasible path from s to t Find the max residual capacity on it Saturate the path by adding flow along it equal to the minimum residual capacity

Ford-Fulkerson Find path with capacity left: Find minimum residual capacity: Add flow to saturate: t s New flow

Ford-Fulkerson Find path with capacity left: Find minimum residual capacity: Add flow to saturate: t s Saturated edge, flow Unsaturated flow

Ford-Fulkerson Find path with capacity left: Wait a doggone second... Consider flow in one direction as capacity in reverse direction! t s There are none! “Reverse edge”

Ford-Fulkerson What is “residual capacity” of 3-1? Find path with capacity left: What is the minimum RC on this path? Add flow to saturate t s (the flow) “Reverse edge”

Ford-Fulkerson Find path with capacity left: We are done t s There is none

Ford-Fulkerson Removing saturated edges partitions the network t s

Ford-Fulkerson Removing saturated edges partitions the network Source s is in one part, t is in another Note: cut is subset of saturated edges t s

s-t Cut Defn. 22.3: An s-t cut is a cut that places node s in one of its sets and node t in the other. Its capacity is the sum of its edge weights. The flow across an s-t cut is the sum of the flows across its s-t edges, less the sum of the flows across its t-s edges.

MinCut Problem Given an s-t network, find an s-t cut such that the capacity of no other cut is smaller. We call this a mincut. Maxflow-mincut theorem – min cut capacity and maxflow value are equal

Residual Network Given flow network G and a flow F, the residual network R for the flow has the same nodes, and one or two edges in R for each edge in the original: for edge (v,w) in G, let f be the flow and c be the capacity. If f 0 include (w,v) with capacity f.

Residual Network If flow is 0, then the original edge with original capacity is used For positive flows, decrease capacity by the flow (unless the residual capacity is zero – the edge is saturated – remove the edge) For positive flows, add a reverse directed edge with the flow as its capacity (can reduce flow that much).

Flow Network with Flow Make reverse edges with capacity = flow Decrease capacity by flow on forward edges t s Flow Reverse edges

Residual Network t s Saturated edge Residual capacity Reverse edges Make reverse edges with capacity = flow Decrease capacity by flow on forward edges Remove edges with zero residual capacity (saturated edges)

Residual Network t s Residual capacity Reverse edges Residual network remains Note that reverse edge to s or from t don’t help, so can be omitted in practice

Variants on Ford-Fulkerson Shortest Augmenting Path Measured by number of edges Build “layer graph” – like BFS Which nodes can be reached by 1 edge, then by 2 edges, etc. Stop when t is reached and add flow to saturate edge on path to t

Variants on Ford-Fulkerson Maximum Flow Augmenting Path Measured by max flow along path Pick edges that give max flow to next layer Take max of (min flow along path to predecessor u, capacity (u,v)) to find max flow to v through u at that layer

Ford-Fulkerson Complexity Prop. 22.6: Let M be the maximum edge capacity in G. The number of augmenting paths needed by any implementation of F-F is at most VM. Every AP adds at least one unit of flow to every cut; any cut has at most V edges; hence the algorithm must terminate after VM passes since any cut must be saturated by then.

Ford-Fulkerson Complexity Cor: The time required to find a maxflow is O(VEM), which is O(V 2 M) for sparse networks. Linear (in edges) graph search per pass. Need extra lg V factor if using priority queue fringe implementation Actual performance is quite good

Ford-Fulkerson Complexity Prop. 22.7: The number of augmenting paths needed in the shortest augmenting path F-F algo is at most VE/2.

Ford-Fulkerson Complexity The length of the APs monotone non- decreasing. Every AP has a critical edge that is saturated in its pass. Each time edge e is the critical edge, the AP must be at least 2 hops longer. The longest path has < V edges

Ford-Fulkerson Complexity Prop (again): The number of augmenting paths needed in the shortest augmenting path F-F algo is at most VE/2. Cor: The time required to find a maxflow in a sparse network is O(V 3 ) O(E) time per pass, VE/2 passes, and if G is sparse, E is O(V).

Ford-Fulkerson Complexity Prop. 22.8: The number of augmenting paths needed in the maximal augmenting path F-F algo is at most 2E lg M. Cor: The time required to find a maxflow in a sparse network is O(V 2 lg M lg V)

Pre-flow Algorithms Push flow into nodes, then out

Network Flow Flow Networks Maxflow Algorithms Maxflow Reductions Mincost Flows Network Simplex Algorithm

Maxflow in General Networks Maximize the total outflow from sources in a network. (Zero by convention if no sources or sinks) Multiple sources Multiple sinks Still need feasible flows!

Maxflow in General Networks Prop : The maxflow in general networks is equivalent to the maxflow problem for general networks. The general case subsumes the special case of s-t networks. Add dummy source connected to all sources and dummy sink to all sinks by high-capacity edges

Vertex-capacity Constraints Given a flow network, find a maxflow satisfying additional constraints that the flow through each node v must not exceed the capacity of that node.

Vertex-capacity Constraints Prop : The maxflow with node capacity problem is equivalent to maxflow problem. Setting node capacity high subsumes the special case of s-t networks. Node capacity can be set to max of in-capacity and out-capacity (sum of in- and out-edge capacities, resp.)

Vertex-capacity Constraints Prop : The maxflow with node capacity problem is equivalent to maxflow problem. Split each node into in-part and out- part, with all in-edge to in-part and all out-edge from out-part Make edge from in-part to out-part with edge capacity = node capacity in original problem

Maxflow in Acyclic Networks Maximize the total outflow from sources in an acyclic network. Seems like it might be easier But NO! Easy transformation from any network to acyclic network V nodes -> 2V + 2 nodes E edges -> E + 3V edges

Maxflow in General Networks Prop : The maxflow in acyclic networks is equivalent to the maxflow problem for general networks. The construction allows a mincut in original to reveal a mincut in the transformed version, and vice versa, with transformed cut values. p427

Maxflow in Undirected Networks Prop : The maxflow in undirected networks reduces to the maxflow problem for s-t networks. Just make two directed edges in the s-t network for every edge in the undirected network Make both edge capacities equal to the corresponding edge capacity in the undirected network

Maxflow in Undirected Networks Note that we did not say equivalent! It remains possible that finding maxflows in undirected networks is easier than finding them in directed networks.

Feasible Flow Given a flow network G, assign a weight to each node, interpreted as supply if positive, and demand if negative. A flow is feasible if it obeys flow constraints AND if the difference between the outflow sum and inflow sum for each node v = v’s weight Finding a feasible flow is FF problem

Feasible Flow Prop : The feasible flow problem reduces to maxflow Make flow network with V more nodes. For supply nodes, make the new node a source with edge weight the same as the node weight For demand nodes make the new node a sink with edge capacity = -weight

Feasible Flow Prop : The feasible flow problem reduces to maxflow Feasible flow exists in original network iff maxflow in constructed flow network saturates all edges between sources and companions and all edges between sinks and companions

Max-cardinality Bipartite Matching Given a bipartite graph G, find a set of edges of maximum cardinality such that each vertex is connected to at most one other vertex. A.k.a. Bipartite Matching Problem Direct solution by trying all possibilities results in combinatorial explosion!

Max-cardinality Bipartite Matching Prop : Bipartite matching reduces to the maxflow problem. Make edges directed from set A to set B nodes Add two dummy nodes s and t Add edges from s to each node in A Add edges from each node in B to t Assign capacity 1 to all edges

Edge-Connectivity Prop : The minimum number of edges whose removal disconnects two nodes in a digraph is equal to the number of edge-disjoint paths between the two nodes. Define a flow network with the same nodes and edges, with capacities all 1. The capacity of any s-t cut is equal to the cut’s cardinality

Connectivity Problems Edge connectivity Node connectivity Digraphs Undirected graphs Hence 4 problems Can do reductions….

Edge-Connectivity Prop : The time required to determine the edge-connectivity of an undirected graph G is O(E 2 ) Compute min cut in corresponding s-t network with unit capacity edges. Edge connectivity for G is the minimum over all s-t pairs Note we only have to use a minimal degree vertex as s – faster

Flow Network Now are we done? Yep Refinery Oil Field Pipelines and Valves

Network Flow Flow Networks Maxflow Algorithms Maxflow Reductions Mincost Flows Network Simplex Algorithm

Mincost Flows Flow network has cost also associated with each edge Defn 22.8: Flow cost of an edge is the product of the flow and the edge cost. The cost of a flow is the sum of the flow costs of that flow’s edges.

Mincost Flows Mincost Maxflow Find maxflow with minimum flow cost Mincost Feasible Flow Find feasible flow with minimum cost Prop 22.22: The mincost feasible flow and the mincost maxflow problems are equivalent.

Network Flow Flow Networks Maxflow Algorithms Maxflow Reductions Mincost Flows Network Simplex Algorithm