Lecture 17: Max Flow Γ Bipartite Matching Tim LaRock larock.t@northeastern.edu bit.ly/cs3000syllabus
Business Homework 5 due Tuesday night 11:59 Boston time No class Monday, per President Aounβs office Class Tuesday and Wednesday next week, no class Thursday Wednesday will include midterm review similar to last time
Last Time: Mechanics of Reductions Input x for Input u for Problem B Problem A SolveA Output y in B(x) Output v in A(u) for Problem B for Problem A In the simplest case, we just call SolveA a single time. In fact we may use SolveA as a subroutine to a more complex reduction.
A = MaxFlow Last Time: Minimum Cut B = MinCut Input x for Input u for Problem B Problem A SolveA Output y in B(x) Output v in A(u) for Problem B for Problem A Input π¦ for B: π» = (π, πΉ, π‘, π’, π + ) Output π§ β πΆ(π¦) : π» = (π, πΉ, π‘, π’, π + ) Input π£ for A: π» = (π, πΉ, π‘, π’, π + ) 1. Take π , compute the residual graph π» 4 2. Find the nodes reachable from π‘ in π» 4 3. Output these nodes Output π€ β π΅(π£) : π» = (π, πΉ, π‘, π’, π + )
Bipartite Matching from Maximum Flow
Bipartite Matching β’ Input: bipartite graph π» = (π, πΉ) with π = π βͺ π π π Models any problem where one type of object is assigned to another type: β’ doctors to hospitals β’ jobs to processors β’ advertisements to websites
Bipartite Matching β’ Input: bipartite graph π» = (π, πΉ) with π = π βͺ π β’ Output: a maximum cardinality matching β’ A matching π β πΉ is a set of edges such that every node π€ is an endpoint of at most one edge in π π π Models any problem where one type of object is assigned to another type: β’ doctors to hospitals β’ jobs to processors β’ advertisements to websites
Bipartite Matching β’ Input: bipartite graph π» = (π, πΉ) with π = π βͺ π β’ Output: a maximum cardinality matching β’ A matching π β πΉ is a set of edges such that every node π€ is an endpoint of at most one edge in π β’ Cardinality = π π π Models any problem where one type of object is assigned to another type: β’ doctors to hospitals β’ jobs to processors β’ advertisements to websites
Bipartite Matching Input x for Input u for Problem B Problem A SolveA Output y in B(x) Output v in A(u) for Problem B for Problem A β’ There is a reduction that uses integer maximum s-t flow to solve maximum bipartite matching. β’ Problem B: maximum bipartite matching (MBM) β’ Problem A: integer maximum s-t flow
Bipartite Matching 1 2 Input x for Input u for Problem B Problem A SolveA Output y in B(x) Output v in A(u) for Problem B for Problem A 3 β’ There is a reduction that uses integer maximum s-t flow to solve maximum bipartite matching. β’ Problem B: maximum bipartite matching (MBM) β’ Problem A: integer maximum s-t flow
Step 1: Transform the Input Input G for Input Gβ for MCBM MAXFLOW π π
Step 1: Transform the Input Input G for Input Gβ for MCBM MAXFLOW π π π π Set all edge capacities to π π = 1
Step 2: Receive the Output Input Gβ for MAXFLOW SolveA Output f for MAXFLOW Red arrow means f(e)=1 Black means f(e) = 0
Step 2: Receive the Output Input Gβ for The matching will be all MAXFLOW of the edges from π to SolveA π with nonzero flow! Output f for MAXFLOW Red arrow means f(e)=1 Black means f(e) = 0
Step 3: Transform the Output Output M for Output f for MCBM MAXFLOW
Reduction Recap β’ Step 1: Transform the Input β’ Given G = (L,R,E), produce Gβ = (V,E,{c(e)},s,t) by... β’ ... orienting edges e from L to R β’ ... adding a node s with edges from s to every node in L β’ ... adding a node t with edges from every not in R to t β’ ... seting all capacities to 1 β’ Step 2: Receive the Output β’ Find an integer maximum s-t flow f in Gβ β’ Step 3: Transform the Output β’ Given an integer s-t flow f(e)β¦ β’ Let M be the set of edges e going from L to R that have f(e)=1
Correctness β’ Need to show: β’ (1) This algorithm returns a matching β’ (2) This matching is a maximum cardinality matching
Correctness β’ This algorithm returns a matching Since the capacity on every edge is 1, by conservation of flow we have: β’ For any node in π , exactly one outgoing edge can have flow β’ For any node in π , exactly one incoming edge can have flow
Correctness β’ Claim: G has a matching of cardinality at least k if and only if Gβ has an s-t flow of value at least k
Correctness β’ Claim: G has a matching of cardinality at least k if and only if Gβ has an s-t flow of value at least k A matching of size π immediately implies a valid flow of value π
Correctness β’ Claim: G has a matching of cardinality at least k if and only if Gβ has an s-t flow of value at least k A flow of value π must have π edges carrying flow from π to π
Correctness β’ Claim: G has a matching of cardinality at least k if and only if Gβ has an s-t flow of value at least k A matching of size π immediately A flow of value π must have π edges implies a valid flow of value π carrying flow from π to π When π is the maximum cardinality matching, there must be a flow, and vice versa!
Running Time β’ Need to analyze the time for: β’ (1) Producing Gβ given G β’ Gβ has π + 2 nodes and π + π edges, so we can construct it in π(π + π) time β’ (2) Finding a maximum flow in Gβ β’ MaxFlow with all capacities 1 can be solved in π(ππ) β’ (3) Producing M given Gβ β’ We can scan the edges of Gβ to find the max flow in π(π + π) time β’ Adding the three together, we have π 2 β (π + π + ππ) = π(ππ)
Running Time β’ Need to analyze the time for: β’ (1) Producing Gβ given G β’ Gβ has π + 2 nodes and π + π edges, so we can construct it in π(π + π) time β’ (2) Finding a maximum flow in Gβ β’ MaxFlow with all capacities 1 can be solved in π(ππ) β’ (3) Producing M given Gβ β’ We can scan the edges of Gβ to find the max flow in π(π + π) time β’ Adding the three together, we have π 2 β (π + π + ππ) = π(ππ)
Running Time β’ Need to analyze the time for: β’ (1) Producing Gβ given G β’ Gβ has π + 2 nodes and π + π edges, so we can construct it in π(π + π) time β’ (2) Finding a maximum flow in Gβ β’ MaxFlow with all capacities 1 can be solved in π(ππ) β’ (3) Producing M given Gβ β’ We can scan the edges of Gβ to find the max flow in π(π + π) time β’ Adding the three together, we have π 2 β (π + π + ππ) = π(ππ)
Running Time β’ Need to analyze the time for: β’ (1) Producing Gβ given G β’ Gβ has π + 2 nodes and π + π edges, so we can construct it in π(π + π) time β’ (2) Finding a maximum flow in Gβ β’ MaxFlow with all capacities 1 can be solved in π(ππ) β’ (3) Producing M given Gβ β’ We can scan the edges of Gβ to find the max flow in π(π + π) time β’ Adding the three together, we have π 2 β (π + π + ππ) = π(ππ)
Running Time β’ Need to analyze the time for: β’ (1) Producing Gβ given G β’ Gβ has π + 2 nodes and π + π edges, so we can construct it in π(π + π) time β’ (2) Finding a maximum flow in Gβ β’ MaxFlow with all capacities 1 can be solved in π(ππ) β’ (3) Producing M given Gβ β’ We can scan the edges of Gβ to find the max flow in π(π + π) time β’ Adding the three together, we have π 2 β (π + π + ππ)
Summary Solving maximum integer s-t flow in a graph with n+2 nodes and m+n edges and c(e) = 1 in time T Solving maximum bipartite matching in a graph with n nodes and m edges in time T + O(m+n) β’ Can solve max bipartite matching in time O(nm) using Ford-Fulkerson β’ Improvement for maximum flow gives improvement for maximum bipartite matching
Wrap-up No class Monday, per President Aounβs office Homework 5 due Tuesday night 11:59 Boston time Class Tuesday and Wednesday next week, no class Thursday Wednesday will include midterm review of some kind Stay safe and enjoy your weekend
Recommend
More recommend