Ford-Fulkerson.

Slides:



Advertisements
Similar presentations
Lecture 5: Network Flow Algorithms Max-Flow Min-Cut Single-Source Shortest-Path (SSSP) Job Sequencing.
Advertisements

§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
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.
Algorithm Design and Analysis (ADA)
MAX FLOW APPLICATIONS CS302, Spring 2013 David Kauchak.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
HW2 Solutions. Problem 1 Construct a bipartite graph where, every family represents a vertex in one partition, and table represents a vertex in another.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Section 4.2 Network Flows By Christina Touhey. The flow out of a equals the flow into z. Algorithm 1.Make vertex a: (0, ). 2.Scan the first vertex and.
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.
Maximum Flow CSC 172 SPRING 2002 LECTURE 27. Flow Networks Digraph Weights, called capacities, on edges Two distinct veticies Source, “s” (no incoming.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Lecture 5: Network Flow Algorithms Single-Source Shortest-Path (SSSP) (Dijkstra's Algorithm) Max Flow - Min Cut (Ford-Fulkerson) Job Sequencing.
MAX FLOW APPLICATIONS CS302, Spring 2012 David Kauchak.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
Honors Track: Competitive Programming & Problem Solving Fun with Graphs II Kevin Verbeek.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
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.
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.
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)
Prim’s MST Djikstra SP. PRIM’s - Minimum Spanning Tree -A spanning tree of a graph is a tree that has all the vertices of the graph connected by some.
Ford-Fulkerson Recap.
Network Flow.
Max-flow, Min-cut Network flow.
Data Structures and Algorithms I
CS4234 Optimiz(s)ation Algorithms
Lecture 16 Bipartite Matching
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
Network Flow.
Eager Prim Dijkstra.
Biconnected Graph Articulation Points
Max-flow, Min-cut Network flow.
CMSC 341 Lecture 24 Max Flow Prof. Neary
Eager Prim Dijkstra.
Network Flow 2016/04/12.
Instructor: Shengyu Zhang
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
Network Flow and Connectivity in Wireless Sensor Networks
Biconnected Graph Articulation Points
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Flow Networks and Bipartite Matching
Fundamental Data Structures and Algorithms
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.
Algorithms (2IL15) – Lecture 7
Network Flow CSE 373 Data Structures.
EE5900 Advanced Embedded System For Smart Infrastructure
離散數學 DISCRETE and COMBINATORIAL MATHEMATICS
Algorithms: Design and Analysis
Network Flow.
Lecture 21 Network Flow, Part 1
Introduction to Maximum Flows
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Maximum Flow Neil Tang 4/8/2008
Introduction to Maximum Flows
Network Flow.
Richard Anderson Lecture 22 Network Flow
Maximum Flow Problems in 2005.
Presentation transcript:

Ford-Fulkerson

Max-flow Maximize the total amount of flow from s to t subject to two constraints Flow on edge e doesn’t exceed capacity(e) For every node v ≠ {s, t}, incoming flow is equal to outgoing flow

Ford-Fulkerson The general idea is simple while (hasAugmentingPath) { public FordFulkerson(FlowNetwork G, int s, int t) { V = G.V(); value = excess(G, t); while (hasAugmentingPath(G, s, t)) { double bottle = Double.POSITIVE_INFINITY; for (int v = t; v != s; v = edgeTo[v].other(v)) { bottle = Math.min(bottle, edgeTo[v].residualCapacityTo(v)); } edgeTo[v].addResidualFlowTo(v, bottle); value += bottle; The general idea is simple while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. }

Ford-Fulkerson The general idea is simple while (hasAugmentingPath) { public FordFulkerson(FlowNetwork G, int s, int t) { V = G.V(); value = excess(G, t); while (hasAugmentingPath(G, s, t)) { double bottle = Double.POSITIVE_INFINITY; for (int v = t; v != s; v = edgeTo[v].other(v)) { bottle = Math.min(bottle, edgeTo[v].residualCapacityTo(v)); } edgeTo[v].addResidualFlowTo(v, bottle); value += bottle; The general idea is simple while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. } To find minimum residual capacity edgeTo: backtrack trace. edgeTo[t] is the last edge on shortest residual s->t path.

Ford-Fulkerson The general idea is simple while (hasAugmentingPath) { public FordFulkerson(FlowNetwork G, int s, int t) { V = G.V(); value = excess(G, t); while (hasAugmentingPath(G, s, t)) { double bottle = Double.POSITIVE_INFINITY; for (int v = t; v != s; v = edgeTo[v].other(v)) { bottle = Math.min(bottle, edgeTo[v].residualCapacityTo(v)); } edgeTo[v].addResidualFlowTo(v, bottle); value += bottle; The general idea is simple while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. } Two remaining problems How to find augmenting path Adjust the residual graph after upating the max flow

Augmenting path Find augmenting path hasAugmentingPath ? t s B C A D Flow = 4 + 7 + 6 = 17 ? Find augmenting path s->A->t [4] s->B->C->t [7] s->D->t [6] hasAugmentingPath ? No: max-flow = 17 Yes: max-flow > 17 t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. }

Augmenting path Find augmenting path hasAugmentingPath ? t s B C A D Flow = 4 + 7 + 6 = 17 ? Find augmenting path s->A->t [4] s->B->C->t [7] s->D->t [6] s->…->t hasAugmentingPath ? Yes: max-flow > 17 But why cannot we find it ? t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. }

Residual graph Residual graph t s B C A D We look for augmenting path on the residual graph G’ At the same time we also update the residual graph G’ At initial time, G’== G t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G public FordFulkerson(FlowNetwork G, int s, int t) { V = G.V(); value = excess(G, t); while (hasAugmentingPath(G, s, t)) { double bottle = Double.POSITIVE_INFINITY; for (int v = t; v != s; v = edgeTo[v].other(v)) { bottle = Math.min(bottle, edgeTo[v].residualCapacityTo(v)); } edgeTo[v].addResidualFlowTo(v, bottle); value += bottle;

Residual graph Method addResidualFlowTo(v, bottle) t s B C A D t s B C s->A->t, bottle=4 For s->A, A->t: decrease capacity of forward edge by 4 while increase capacity of backward edge by 4 s->B->C->t, bottle=7 For s->B, B->C, c->t decrease capacity of forward edge by 7 while increase capacity of backward edge by 7 s->D->t, bottle=6 For s->D, D->t, decrease capacity of forward edge by 7 while increase capacity of backward edge by 7 t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G t s 4 B C A D 6 3 2 7 G’ We show both forward and backward edge here, yet you only store one edge in the implementation.

Residual graph Method addResidualFlowTo(v, bottle) t s B C A D t s B C We found a new augmenting path! Method addResidualFlowTo(v, bottle) s->D->C->B->A->t is an augmenting path, bottle=2 For s->D, D->C, B->A, A->t, decrease capacity of forward edge by 2 while increase capacity of backward edge by 2 For C->B, increase capacity of forward edge by 2 while decrease capacity of backward edge by 2 Forward edge, backward edge On the path of s->D->C->B->A->t, C->B is a backward edge, while all others are forward edges t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G t s 4 B C A D 6 3 2 7 G’ We show both forward and backward edge here, yet you only store one edge in the implementation.

Residual graph Method addResidualFlowTo(v, bottle) t s B C A D A s B C We found a new augmenting path! MaxFlow=17+2=19 Method addResidualFlowTo(v, bottle) s->D->C->B->A->t is an augmenting path, bottle=2 For s->D, D->C, B->A, A->t, decrease capacity of forward edge by 2 while increase capacity of backward edge by 2 For C->B, increase capacity of forward edge by 2 while decrease capacity of backward edge by 2 Forward edge, backward edge On the path of s->D->C->B->A->t, C->B is a backward edge, while all others are forward edges t s 4 B C A D 6 3 2 7 G’ A 4 6 2 2 4 5 s B C t 7 5 2 2 6 2 8 D G’ We show both forward and backward edge here, yet you only store one edge in the implementation.

Residual graph Method addResidualFlowTo(v, bottle) A t s B C A D s B C We found a new augmenting path! MaxFlow=17+2=19 Method addResidualFlowTo(v, bottle) s->D->C->B->A->t is an augmenting path, bottle=2 Understand backward edge C->B Backward edge C->B tries to `fork` the previous path S->B->C->t, thus pump extra flows into the graph A t s 4|4 B C A D 7|7 8|10 6|10 0|2 2|2 5|10 6|6 G 4 6 2 2 4 5 s B C t 7 5 2 2 6 2 8 D G’ We show both forward and backward edge here, yet you only store one edge in the implementation.

Ford-Fulkerson The general idea is simple while (hasAugmentingPath) { public FordFulkerson(FlowNetwork G, int s, int t) { V = G.V(); value = excess(G, t); while (hasAugmentingPath(G, s, t)) { double bottle = Double.POSITIVE_INFINITY; for (int v = t; v != s; v = edgeTo[v].other(v)) { bottle = Math.min(bottle, edgeTo[v].residualCapacityTo(v)); } edgeTo[v].addResidualFlowTo(v, bottle); value += bottle; The general idea is simple while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. } Two remaining problems How to find augmenting path Adjust the residual graph after upating the max flow

Ford-Fulkerson Method hasAugmentingPath(FlowNetwork G, int s, int t) t For each edge in the residual graph G’, the summation of backward and forward edges capacity equals to the capacity of the edge in G Thus we need to store only one copy, the capacity of the other could be calculated using subtraction E.g., cap(D->S)=10-cap(S->D) t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G t s 4 B C A D 6 3 2 7 G’ FlowEdge.java public double residualCapacityTo(int vertex) { if (vertex == v) return flow; // backward edge else if (vertex == w) return capacity - flow; // forward edge }

Ford-Fulkerson Method hasAugmentingPath(FlowNetwork G, int s, int t) t FlowNetwork.java public void addEdge(FlowEdge e) { int v = e.from(); int w = e.to(); adj[v].add(e); adj[w].add(e); E++; } Explaination: Vertex B is connected to edge B->C Vertex C is also connected to edge B->C This ensures that vertices are connected by both forward edge and backward edge t s 4|4 B C A D 7|7 6|10 4|10 0|2 7|10 6|6 G t s 4 B C A D 6 3 2 7 G’ FlowEdge e is defined to be from v to w

Ford-Fulkerson Method hasAugmentingPath(FlowNetwork G, int s, int t) t private boolean hasAugmentingPath(FlowNetwork G, int s, int t) { edgeTo = new FlowEdge[G.V()]; marked = new boolean[G.V()]; Queue<Integer> queue = new Queue<Integer>(); queue.enqueue(s); marked[s] = true; while (!queue.isEmpty() && !marked[t]) { int v = queue.dequeue(); for (FlowEdge e : G.adj(v)) { int w = e.other(v); if (e.residualCapacityTo(w) > 0) { if (!marked[w]) { edgeTo[w] = e; marked[w] = true; queue.enqueue(w); } return marked[t]; t s 4 B C A D 6 3 2 7 G’ For example, residualCapacity from B to C is 3, yet from C to B is 7 From s, we could not visit A since there is no residual Capacity

Ford-Fulkerson The general idea is simple while (hasAugmentingPath) { public FordFulkerson(FlowNetwork G, int s, int t) { V = G.V(); value = excess(G, t); while (hasAugmentingPath(G, s, t)) { double bottle = Double.POSITIVE_INFINITY; for (int v = t; v != s; v = edgeTo[v].other(v)) { bottle = Math.min(bottle, edgeTo[v].residualCapacityTo(v)); } edgeTo[v].addResidualFlowTo(v, bottle); value += bottle; The general idea is simple while (hasAugmentingPath) { augment the the current max flow by the minimum residual capacity on the augmenting path. } Two remaining problems How to find augmenting path Adjust the residual graph after upating the max flow

Ford-Fulkerson Method addResidualFlowTo(v, bottle) t s B C A D t s B C s->D->C->B->A->t is an augmenting path, bottle=2 For s->D, D->C, B->A, A->t, decrease capacity of forward edge by 2 while increase capacity of backward edge by 2 For C->B, increase capacity of forward edge by 2 while decrease capacity of backward edge by 2 Forward edge, backward edge On the path of s->D->C->B->A->t, C->B is a backward edge, while all others are forward edges Ford-Fulkerson Method addResidualFlowTo(v, bottle) t s 4 B C A D 8 6 5 2 7 t s 4 B C A D 6 3 2 7 G’ public void addResidualFlowTo(int vertex, double delta) { if (vertex == v) flow -= delta; // backward edge else if (vertex == w) flow += delta; // forward edge } Edge are defined to be from v to w