21
1 Weighted Bipartite Matching Lecture 4: Jan 18

1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

Embed Size (px)

Citation preview

Page 1: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

1

Weighted Bipartite Matching

Lecture 4: Jan 18

Page 2: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

2

Weighted Bipartite Matching

Given a weighted bipartite graph,

find a matching with maximum total weight.

Not necessarily a maximum size matching.

A B

Page 3: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

3

Today’s Plan

Three algorithms

• negative cycle algorithm

• primal dual algorithm

• augmenting path algorithm

Applications

Page 4: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

4

First Algorithm

How to know if a given matching M is optimal?

Idea: Imagine there is a larger matching M*

and consider the union of M and M*

Find maximum weight perfect matching

Page 5: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

5

First Algorithm

Orient the edges (edges in M go up, others go down)

edges in M having positive weights, otherwise negative weights

Then M is maximum if and only if there is no negative cycles

Page 6: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

6

First Algorithm

Key: M is maximum no negative cycle

How to find efficiently?

Page 7: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

7

Complexity

At most nW iterations

A negative cycle in time by Floyd Warshall

Total running time

Can choose minimum mean cycle to avoid W

Page 8: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

8

Augmenting Path Algorithm

Orient the edges (edges in M go up, others go down)

edges in M having positive weights, otherwise negative weights

Find a shortest path M-augmenting path at each step

Page 9: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

9

Augmenting Path Algorithm

Theorem: each matching is an optimal k-matching.

Let the current matching be M

Let the shortest M-augmenting path be P

Let N be a matching of size |M|+1

Page 10: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

10

Complexity

At most n iterations

A shortest path in time by Bellman Ford

Total running time

Can be speeded up by using Dijkstra O(m + nlogn)

Kuhn, Hungarian method

Page 11: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

11

Primal Dual Algorithm

What is an upper bound of maximum weighted matching?

What is a generalization of minimum vertex cover?

weighted vertex cover:

Minimum weighted vertex cover >= Maximum weighted matching

Page 12: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

12

Primal Dual Algorithm

Minimum weighted vertex cover >= Maximum weighted matching

Primal Dual

• Maintain a weighted matching M

• Maintain a weighted vertex cover y

• Either increase M or decrease y until they are equal.

Page 13: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

13

Primal Dual Algorithm

Minimum weighted vertex cover >= Maximum weighted matching

1. Consider the subgraph formed by tight edges (the equality subgraph).

2. If there is a tight perfect matching, done.

3. Otherwise, there is a vertex cover.

4. Decrease weighted cover to create more tight edges, and repeat.

Page 14: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

14

Complexity

Augment at most n times, each O(m)

Decrease weighted cover at most m times, each O(m)

Total running time

Egrevary, Hungarian method

Page 15: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

15

Quick Summary

1. First algorithm, negative cycle, useful idea to consider symmetric difference

2. Augmenting path algorithm, useful algorithmic technique

3. Primal dual algorithm, a very general framework

1. Why primal dual?

2. How to come up with weighted vertex cover?

3. Reduction from weighted case to unweighted case

Page 16: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

16

Faster Algorithms

Page 17: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

17

Bonus Question 2

(40%) Find a maximum weighted k-matching which

can be extended to a perfect matching.

Relation to red-blue matching?

Page 18: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

18

Application of Bipartite Matching

Jerry

Marking

Darek TomIsaac

Tutorials Solutions Newsgroup

Job Assignment Problem:

Each person is willing to do a subset of jobs.

Can you find an assignment so that all jobs are taken care of?

• Ad-auction, Google, online matching

• Fingerprint matching

Page 19: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

19

Application of Bipartite Matching

With Hall’s theorem, now you can determine exactly

when a partial chessboard can be filled with dominos.

Page 20: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

20

Application of Bipartite Matching

Latin Square: a nxn square, the goal is to fill the square

with numbers from 1 to n so that:

• Each row contains every number from 1 to n.

• Each column contains every number from 1 to n.

Page 21: 1 Weighted Bipartite Matching Lecture 4: Jan 18. 2 Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight

21

Application of Bipartite Matching

Now suppose you are given a partial Latin Square.

Can you always extend it to a Latin Square?

With Hall’s theorem, you can prove that the answer is yes.