CS/COE 1501 cs.pitt.edu/~bill/1501/ Network Flow

Similar documents
Jessica Su (some parts copied from CLRS / last quarter s notes)

Maximum Flow. Flow Networks. Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms. Example Flow Network

6.4 Maximum Flow. overview Ford-Fulkerson implementations applications

Network flows and Menger s theorem

Network Design and Optimization course

Cuts, Connectivity, and Flow

Tutorial for Algorithm s Theory Problem Set 5. January 17, 2013

Lecture 3: Graphs and flows

CSC 8301 Design & Analysis of Algorithms: Linear Programming

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

Maximum Flow Algorithms

Source. Sink. Chapter 10: Iterative Programming Maximum Flow Problem. CmSc250 Intro to Algorithms

Minimum Spanning Tree (undirected graph)

CSE 5311 Notes 9: Maximum Flows

CS261: Problem Set #1

Maximum flows & Maximum Matchings

Network Flows. 1. Flows deal with network models where edges have capacity constraints. 2. Shortest paths deal with edge costs.

COMP4128 Programming Challenges

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

and 6.855J March 6, Maximum Flows 2

LECTURES 3 and 4: Flows and Matchings

Graphs. Edges may be directed (from u to v) or undirected. Undirected edge eqvt to pair of directed edges

Copyright 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin Introduction to the Design & Analysis of Algorithms, 2 nd ed., Ch.

GRAPH DECOMPOSITION BASED ON DEGREE CONSTRAINTS. March 3, 2016

s-t Graph Cuts for Binary Energy Minimization

( ) 1 B. 1. Suppose f x

COT 6936: Topics in Algorithms! Giri Narasimhan. ECS 254A / EC 2443; Phone: x3748

Computational Methods in IS Research Fall Graph Algorithms Network Flow Problems

Problem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel.

Lecture 3: Totally Unimodularity and Network Flows

Today. Maximum flow. Maximum flow. Problem

Weekly Assignment nr.4

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

Bipartite Matching & the Hungarian Method

CS 310 Advanced Data Structures and Algorithms

Lecture 10,11: General Matching Polytope, Maximum Flow. 1 Perfect Matching and Matching Polytope on General Graphs

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

Discussion 11 APT REVIEWS AND GRAPH ALGORITHMS

Question Points Score TOTAL 55 TOTAL (Calibrated) 50

CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Syllabus. simple: no multi-edges undirected edges in-/out-/degree /0: absent 1: present (strongly) connected component subgraph, induced graph

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

Mystery Algorithm! ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v )

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Graphs & Digraphs Tuesday, November 06, 2007

Problem Set 7 Solutions

CSE 417 Network Flows (pt 4) Min Cost Flows

Network Flow. November 23, CMPE 250 Graphs- Network Flow November 23, / 31

Solution for Homework set 3

Minimum Spanning Trees

1 Bipartite maximum matching

Lecture 11: Maximum flow and minimum cut

Week 12: Minimum Spanning trees and Shortest Paths

Homework 3 Solutions

Notes for Lecture 20

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Graphs and Network Flows IE411. Lecture 13. Dr. Ted Ralphs

Lecture 20: Other Algorithms on Graphs. Undirected Trees. Spanning Trees

Outline: Finish uncapacitated simplex method Negative cost cycle algorithm The max-flow problem Max-flow min-cut theorem

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748

CSE 417 Network Flows (pt 3) Modeling with Min Cuts

n 2 ( ) ( ) + n is in Θ n logn

( ) n 3. n 2 ( ) D. Ο

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

22 Elementary Graph Algorithms. There are two standard ways to represent a

(Re)Introduction to Graphs and Some Algorithms

CHAPTER 13 GRAPH ALGORITHMS

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Your data structure should implement all operations in logarithmic time (or better) as a function of the size of the queue.

COMP 251 Winter 2017 Online quizzes with answers

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Algorithm Circle Extra Lecture: Solving the Assignment Problem with Network Flow

Solving problems on graph algorithms

Agenda. Graph Representation DFS BFS Dijkstra A* Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp

CS Algorithms and Complexity

Introduction to Algorithms. Lecture 11

CMSC 132: Object-Oriented Programming II. Shortest Paths

CS/COE

Final Exam. Jonathan Turner 5/12/2010. CS 542 Advanced Data Structures and Algorithms

Minimum Cost Edge Disjoint Paths

Test points UTA Student ID #

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

1 Introduction. 2 The Generic Push-Relabel Algorithm. Improvements on the Push-Relabel Method: Excess Scaling. 2.1 Definitions CMSC 29700

Minimum Spanning Trees

Matching Theory. Figure 1: Is this graph bipartite?

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

Lecture and notes by: Sarah Fletcher and Michael Xu November 3rd, Multicommodity Flow

Shortest Path Problem

CS261: Problem Set #2

Graph Traversals. Ric Glassey

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Redes de Computadores. Shortest Paths in Networks

Linear Programming. Course review MS-E2140. v. 1.1

GRAPH THEORY and APPLICATIONS. Matchings

22 Elementary Graph Algorithms. There are two standard ways to represent a

csci 210: Data Structures Graph Traversals

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

Lesson 2 7 Graph Partitioning

Transcription:

CS/COE 1501 cs.pitt.edu/~bill/1501/ Network Flow

Defining network flow Consider a directed, weighted graph G(V, E) Weights are applied to edges to state their capacity c(u, w) is the capacity of edge (u, w) if there is no edge from u to w, c(u, w) = 0 Consider two vertices, a source s and a sink t Let s determine the maximum flow that can run from s to t in the graph G 2

Flow Let the f(u, w) be the amount of flow being carried along the edge (u, w) Some rules on the flow running through an edge: (u, w) E f(u, w) <= c(u, w) u (V - {s,t}) (Σ w V f(w, u) - Σ w V f(u, w)) = 0 An edge (u, w) is considered saturated if f(u, w) = c(u, w) 3

Ford Fulkerson Let all edges in G have an allocated flow of 0 Residual capacity of edge (u, w) is c(u, w) - f(u, w) While there is path p from s to t in G s.t. all edges in p have some residual capacity (i.e., (u, w) p f(u, w) < c(u, w)): (Such a path is called an augmenting path) Compute the residual capacity of each edge in p Find the edge with the minimum residual capacity in p We ll call this residual capacity new_flow Increment the flow on all edges in p by new_flow 4

Ford Fulkerson example 5 /5 s 510 /10 5 A /10 510 B /10 t 5 /5 5

Another Ford Fulkerson example /5 s 10 /10 10 A /10 10 B /10 t /5 6

Expanding on residual capacity To find the max flow we will have need to consider rerouting flow we had previously allocated This means, when finding an augmenting path, we will need to look not only at the edges of G, but also at backwards edges that allow such re-routing For each edge (u, w) E, a backwards edge (w, u) must be considered during pathfinding if f(u, w) > 0 The capacity of a backwards edge (w, u) is equal to f(u, w) 7

The residual graph We will perform searches for an augmenting path not on G, but on a residual graph built using the current state of flow allocation on G The residual graph is made up of: V An edge for each (u, w) E where f(u, w) < c(u, w) (u, w) s mirror in the residual graph will have 0 flow and a capacity of c(u, w) f(u, w) A backwards edge for each (u, w) E where f(u, w) > 0 (u, w) s backwards edge has a capacity of f(u, w) All backwards edges have 0 flow 8

Residual graph example 0 /5 5 /5 s 10 /10 A 10 5 /10 B 10 /10 0 /10 0 /10/ 5 0 /10 t 5 /5 0 /5 9

Another example A 12 /1000 1 /1000 s 10 /1 t 1 /1000 12 B /1000 10

Edmonds Karp How the augmenting path is chosen affects the performance of the search for max flow Edmonds and Karp proposed a shortest path heuristic for Ford Fulkerson Use BFS to find augmenting paths 11

Another example A 1000 /1000 1000 /1000 s /1 t 1000 /1000 1000 /1000 B 12

But our flow graph is weighted... Edmonds-Karp only uses BFS Used to find spanning trees and shortest paths for unweighted graphs Why do we not use some measure of priority to find augmenting paths? 13

Implementation concerns Representing the graph: Similar to a directed graph Can store an adjacency list of directed edges Actually, more than simply directed edges Flow edges 14

Flow edge implementation For each edge, we need to store: Start point, the from vertex End point, the to vertex Capacity Flow Residual capacities For forwards and backwards edges 15

FlowEdge.java public class FlowEdge { private final int v; // from private final int w; // to private final double capacity; // capacity private double flow; // flow public double residualcapacityto(int vertex) { if (vertex == v) return flow; else if (vertex == w) return capacity - flow; else throw new IllegalArgumentException("Illegal endpoint"); } } 16

BFS search for an augmenting path (pseudocode) edgeto = [ V ] marked = [ V ] Queue q q.enqueue(s) marked[s] = true while!q.isempty(): v = q.dequeue() for each (v, w) in AdjList[v]: if residualcapacity(v, w) > 0: if!marked[w]: edgeto[w] = e; marked[w] = true; q.enqueue(w); Each FlowEdge object is stored in the adjacency list twice: Once for its forward edge Once for its backwards edge 17

An example to review A 1 /1 13 /3 2 /7 s C 25 /5 t 3 /7 3 /9 B 18

Let s separate the graph An st-cut on G is a set of edges in G that, if removed, will partition the vertices of G into two disjoint sets One contains s One contains t May be many st-cuts for a given graph Let s focus on finding the minimum st-cut The st-cut with the smallest total capacity (sum of capacities) May not be unique 19

How do we find the min st-cut? We could examine residual graphs Specifically, try and allocate flow in the graph until we get to a residual graph with no existing augmenting paths A set of saturated edges will make a minimum st-cut Recall: (u,w) is saturated if f(u,w) = c(u,w) 20

Min cut example A 1 /1 13 /3 2 /7 s C 25 /5 t 3 /7 3 /9 B 21

Max flow == min cut A special case of duality i.e., you can look at an optimization problem from two angles In this case to find the maximum flow or minimum cut In general, dual problems do not necessarily have equal solutions The differences between the solutions to the two related problems is referred to as the duality gap If the duality gap = 0, strong duality holds Max flow/min cut uphold strong duality If the duality gap > 0, weak duality holds 22

Determining a minimum st-cut First, run Ford Fulkerson to produce a residual graph with no further augmenting paths The last attempt to find an augmenting path will visit every vertex reachable from s Saturated edges with only one endpoint in this set comprise a minimum st-cut 23

Determining the min cut A 1 /1 3 /3 2 /7 s C 5 /5 t 3 /7 B 3 /9 Min Cut 24

Will max flow/min cut always be near s/t? A F /1000 /1000 /1000 /1000 s /1000 /1000 /1 /1000 /1000 B D E G t /1000 /1000 /1000 /1000 C H 25

Max flow / min cut on unweighted graphs Is it possible? How would we measure the Max flow / min cut? What would an algorithm to solve this problem look like? 26

Unweighted network flow A F s B E t C D 27