Lecture 17: Max Flow Bipartite Matching Tim LaRock - - PowerPoint PPT Presentation

lecture 17 max flow bipartite matching
SMART_READER_LITE
LIVE PREVIEW

Lecture 17: Max Flow Bipartite Matching Tim LaRock - - PowerPoint PPT Presentation

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 Aouns office Class Tuesday and Wednesday next


slide-1
SLIDE 1

Lecture 17: Max Flow à Bipartite Matching

Tim LaRock larock.t@northeastern.edu bit.ly/cs3000syllabus

slide-2
SLIDE 2
slide-3
SLIDE 3

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

slide-4
SLIDE 4

Last Time: Mechanics of Reductions

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) 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.

slide-5
SLIDE 5

Last Time: Minimum Cut

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

A = MaxFlow B = MinCut

Input 𝑦 for B: 𝐻 = (𝑊, 𝐹, 𝑡, 𝑢, 𝑑+ ) Input 𝑣 for A: 𝐻 = (𝑊, 𝐹, 𝑡, 𝑢, 𝑑+ ) Output 𝑤 ∈ 𝐵(𝑣): 𝐻 = (𝑊, 𝐹, 𝑡, 𝑢, 𝑑+ ) Output 𝑧 ∈ 𝐶(𝑦): 𝐻 = (𝑊, 𝐹, 𝑡, 𝑢, 𝑑+ )

  • 1. Take 𝑔, compute the residual graph 𝐻4
  • 2. Find the nodes reachable from 𝑡 in 𝐻4
  • 3. Output these nodes
slide-6
SLIDE 6

Bipartite Matching from Maximum Flow

slide-7
SLIDE 7

Bipartite Matching

  • Input: bipartite graph 𝐻 = (𝑊, 𝐹) with 𝑊 = 𝑀 ∪ 𝑆

Models any problem where one type

  • f object is assigned to another type:
  • doctors to hospitals
  • jobs to processors
  • advertisements to websites

𝑀 𝑆

slide-8
SLIDE 8

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

  • f object is assigned to another type:
  • doctors to hospitals
  • jobs to processors
  • advertisements to websites

𝑀 𝑆

slide-9
SLIDE 9

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

  • f object is assigned to another type:
  • doctors to hospitals
  • jobs to processors
  • advertisements to websites

𝑀 𝑆

slide-10
SLIDE 10

Bipartite Matching

  • 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

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

slide-11
SLIDE 11

Bipartite Matching

  • 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

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

1 2 3

slide-12
SLIDE 12

Step 1: Transform the Input

Input G for MCBM Input G’ for MAXFLOW

𝑀 𝑆

slide-13
SLIDE 13

Step 1: Transform the Input

Input G for MCBM Input G’ for MAXFLOW

𝑀 𝑆 𝑀 𝑆

Set all edge capacities to 𝑑 𝑓 = 1

slide-14
SLIDE 14

Step 2: Receive the Output

SolveA

Input G’ for MAXFLOW Output f for MAXFLOW

Red arrow means f(e)=1 Black means f(e) = 0

slide-15
SLIDE 15

Step 2: Receive the Output

SolveA

Input G’ for MAXFLOW Output f for MAXFLOW

Red arrow means f(e)=1 Black means f(e) = 0 The matching will be all

  • f the edges from 𝑀 to

𝑆 with nonzero flow!

slide-16
SLIDE 16

Step 3: Transform the Output

Output M for MCBM Output f for MAXFLOW

slide-17
SLIDE 17

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
slide-18
SLIDE 18

Correctness

  • Need to show:
  • (1) This algorithm returns a matching
  • (2) This matching is a maximum cardinality matching
slide-19
SLIDE 19

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
slide-20
SLIDE 20

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

slide-21
SLIDE 21

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 𝑙

slide-22
SLIDE 22

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 𝑆

slide-23
SLIDE 23

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 𝑆 A matching of size 𝑙 immediately implies a valid flow of value 𝑙

When 𝑙 is the maximum cardinality matching, there must be a flow, and vice versa!

slide-24
SLIDE 24

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 ⋅ (𝑜 + 𝑛 + 𝑜𝑛) = 𝑃(𝑜𝑛)

slide-25
SLIDE 25

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 ⋅ (𝑜 + 𝑛 + 𝑜𝑛) = 𝑃(𝑜𝑛)

slide-26
SLIDE 26

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 ⋅ (𝑜 + 𝑛 + 𝑜𝑛) = 𝑃(𝑜𝑛)

slide-27
SLIDE 27

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 ⋅ (𝑜 + 𝑛 + 𝑜𝑛) = 𝑃(𝑜𝑛)

slide-28
SLIDE 28

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 ⋅ (𝑜 + 𝑛 + 𝑜𝑛)

slide-29
SLIDE 29

Summary

  • Can solve max bipartite matching in time O(nm)

using Ford-Fulkerson

  • Improvement for maximum flow gives improvement

for maximum bipartite matching 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)

slide-30
SLIDE 30

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