Bipartite Matchings and Stable Marriage Meghana Nasre Department of - - PowerPoint PPT Presentation

bipartite matchings and stable marriage
SMART_READER_LITE
LIVE PREVIEW

Bipartite Matchings and Stable Marriage Meghana Nasre Department of - - PowerPoint PPT Presentation

Bipartite Matchings and Stable Marriage Meghana Nasre Department of Computer Science and Engineering Indian Institute of Technology, Madras Faculty Development Program SSN College of Engineering, Chennai December 12, 2014 Why matchings?


slide-1
SLIDE 1

Bipartite Matchings and Stable Marriage

Meghana Nasre Department of Computer Science and Engineering Indian Institute of Technology, Madras Faculty Development Program SSN College of Engineering, Chennai December 12, 2014

slide-2
SLIDE 2

Why matchings?

Several real world applications involve assigning:

  • jobs to machines.
  • students to projects.
  • jobs to applicants.
  • roommate to another.
slide-3
SLIDE 3

Outline of Talk

  • Quick introduction to graphs.
  • Matchings in graphs.
  • Bipartite matching algorithm.
  • Stable matchings.
slide-4
SLIDE 4

Introduction to graphs

slide-5
SLIDE 5

Representation and search techniques

G = (V , E).

v1 v2 v3 v6 v5 v4

n = |V | = 6, m = |E| = 8. How large can m be?

slide-6
SLIDE 6

Representation and search techniques

G = (V , E).

v1 v2 v3 v6 v5 v4

n = |V | = 6, m = |E| = 8. How large can m be? Representation:

  • Adjacency Lists – O(m + n) space.
  • Adjacency Matrix – O(n2) space.
slide-7
SLIDE 7

Representation and search techniques

G = (V , E).

v1 v2 v3 v6 v5 v4

n = |V | = 6, m = |E| = 8. How large can m be? Representation:

  • Adjacency Lists – O(m + n) space.
  • Adjacency Matrix – O(n2) space.

Search methods:

  • Breadth First Search.
  • Depth First Search.
slide-8
SLIDE 8

Matching in a graph

slide-9
SLIDE 9

Matching in a graph

A matching M is a set of vertex disjoint edges.

v1 v2 v3 v6 v5 v4

slide-10
SLIDE 10

Matching in a graph

A matching M is a set of vertex disjoint edges.

v1 v2 v3 v6 v5 v4

slide-11
SLIDE 11

Matching in a graph

A matching M is a set of vertex disjoint edges.

v1 v2 v3 v6 v5 v4

  • Goal: compute a maximum sized matching.
  • Question: is the above matching maximum sized?
slide-12
SLIDE 12

Matching in a graph

A matching M is a set of vertex disjoint edges.

v1 v2 v3 v6 v5 v4 v1 v2 v3 v6 v5 v4

slide-13
SLIDE 13

Matching in a graph

A matching M is a set of vertex disjoint edges.

v1 v2 v3 v6 v5 v4 v1 v2 v3 v6 v5 v4

  • Maximal: No more edges can be added to the matching.
slide-14
SLIDE 14

Matching in a graph

A matching M is a set of vertex disjoint edges.

v1 v2 v3 v6 v5 v4 v1 v2 v3 v6 v5 v4

  • Maximal: No more edges can be added to the matching.

Size may not be largest possible.

  • Maximum: Has size as large as possible.

Note that every maximum matching is maximal.

slide-15
SLIDE 15

Alternating paths

A path having alternate matched and unmatched edges.

v1 v2 v3 v6 v5 v4

slide-16
SLIDE 16

Alternating paths

A path having alternate matched and unmatched edges.

v1 v2 v3 v6 v5 v4

  • Is there any other alternating path?
slide-17
SLIDE 17

Alternating paths

A path having alternate matched and unmatched edges.

v1 v2 v3 v6 v5 v4

  • Is there any other alternating path?
  • Which paths are not alternating?
slide-18
SLIDE 18

Augmenting paths

An alternating path starting and ending in free edges.

v1 v2 v3 v6 v5 v4

slide-19
SLIDE 19

Augmenting paths

An alternating path starting and ending in free edges.

v1 v2 v3 v6 v5 v4

  • How are augmenting paths useful?
  • Properties of augmenting paths.
slide-20
SLIDE 20

Using augmenting paths

Berge’s Theorem

  • If aug. path P is present ⇒ size of matching can be increased.
slide-21
SLIDE 21

Using augmenting paths

Berge’s Theorem

  • If aug. path P is present ⇒ size of matching can be increased.
  • M′ = M ⊕ P.

v1 v2 v3 v6 v5 v4

P

v1 v2 v3 v6 v5 v4

P augment M with P M M’

slide-22
SLIDE 22

Using augmenting paths

Berge’s Theorem

  • If no aug. path w.r.t. M ⇒ M is maximum.

Proof (by contradiction)

  • Suppose M does not admit any aug. path and still it is not

maximum.

  • Some other matching M′ is maximum.
slide-23
SLIDE 23

Using augmenting paths

Berge’s Theorem

  • If no aug. path w.r.t. M ⇒ M is maximum.

Proof (by contradiction)

  • Suppose M does not admit any aug. path and still it is not

maximum.

  • Some other matching M′ is maximum.
  • Consider M ⊕ M′.
  • Construct an aug. path w.r.t. M.
slide-24
SLIDE 24

Maximum matching algorithm

Given G = (V , E), compute a maximum sized matching.

slide-25
SLIDE 25

Maximum matching algorithm

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.
slide-26
SLIDE 26

Maximum matching algorithm

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Two questions that need to be always asked:

  • 1. Correctness?
  • 2. Complexity/ Running time?
slide-27
SLIDE 27

Maximum matching algorithm

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Two questions that need to be always asked:

  • 1. Correctness?
  • 2. Complexity/ Running time?

How to efficiently compute an augmenting path?

slide-28
SLIDE 28

Bipartite matching algorithm

slide-29
SLIDE 29

Bipartite graphs

G = (A ∪ B, E).

A B

Equivalent statements

  • Vertices can be partitioned into 2 disjoint sets.
  • G is bipartite iff G does not have any odd cycle.
  • Graph is 2 colorable iff it is bipartite.
slide-30
SLIDE 30

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5

slide-31
SLIDE 31

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5

  • Aug. paths w.r.t. M:
  • a1, b2.
  • a5, b5.
slide-32
SLIDE 32

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5

  • Aug. paths w.r.t. M:
  • a1, b2.
  • a5, b5.
  • a4, b3, a2, b4.
slide-33
SLIDE 33

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5

  • Aug. paths w.r.t. M:
  • a1, b2.
  • a5, b5.
  • a4, b3, a2, b4.

Finding aug. paths – reachability in a modified graph.

slide-34
SLIDE 34

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 s t

slide-35
SLIDE 35

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 s t

  • Add dummy nodes s and t.
  • Add edges from s to unmatched vertices in A.
  • Add edges from unmatched vertices in B to t.
  • Matched edges: B → A.
  • Unmatched edges: A → B.
slide-36
SLIDE 36

Finding aug. path in bipartite graphs

A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 A B a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 s t

  • Aug. path in G w.r.t. M is a simple directed s to t path in G ′.
slide-37
SLIDE 37

Maximum matching in bipartite graph

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Running time?

slide-38
SLIDE 38

Maximum matching in bipartite graph

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Running time?

  • 1. How many iterations?
slide-39
SLIDE 39

Maximum matching in bipartite graph

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Running time?

  • 1. How many iterations? at most n/2.
slide-40
SLIDE 40

Maximum matching in bipartite graph

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Running time?

  • 1. How many iterations? at most n/2.
  • 2. How long does each iteration take?
slide-41
SLIDE 41

Maximum matching in bipartite graph

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Running time?

  • 1. How many iterations? at most n/2.
  • 2. How long does each iteration take? at most O(m + n).
slide-42
SLIDE 42

Maximum matching in bipartite graph

Given G = (V , E), compute a maximum sized matching. Iterative Improvement

  • Initialize M to be empty.
  • while there exists an aug. path P w.r.t. M
  • M = M ⊕ P.
  • return M.

Running time?

  • 1. How many iterations? at most n/2.
  • 2. How long does each iteration take? at most O(m + n).
  • 3. Total running time: O(mn).
slide-43
SLIDE 43

Efficient algorithms

  • The best known for both bipartite and general graphs is

O(√nm) time algorithms.

  • Algorithms on general graphs are significantly involved.
slide-44
SLIDE 44

Efficient algorithms

  • The best known for both bipartite and general graphs is

O(√nm) time algorithms.

  • Algorithms on general graphs are significantly involved.

Edmond’s Blossom Shrinking algorithm. (Also the paper where the notion of polynomial time being efficient was formalized).

  • Weighted matchings can also be done in polynomial time.
  • Beautiful theory of Linear Programming Duality involved.
slide-45
SLIDE 45

Stable matching problem

slide-46
SLIDE 46

A bit of history..

  • Introduced by Gale and Shapley in 1962 while studying college

admissions.

  • Bipartite matching problem with preferences.
  • Arises in several places like TA-allocation, project allocation.
  • Classical setting: marriage between n men and n women.
slide-47
SLIDE 47

Setting

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “optimal”.

slide-48
SLIDE 48

Setting

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “optimal”.

m1 m2 m3 w1 w2 w3

Question: Is this a good matching?

slide-49
SLIDE 49

Setting

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “optimal”.

m1 m2 m3 w1 w2 w3

Question: Is this a good matching? pair (m2, w2) is bad!

slide-50
SLIDE 50

Setting

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

slide-51
SLIDE 51

Setting

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

m1 m2 m3 w1 w2 w3

unstable.

m1 m2 m3 w1 w2 w3

stable.

slide-52
SLIDE 52

Setting

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

m1 m2 m3 w1 w2 w3

unstable.

m1 m2 m3 w1 w2 w3

stable. unstable pair: A pair (m, w) not matched to each other, both of which prefer each other to their current partners in M.

slide-53
SLIDE 53

Stable marriage problem

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance?
slide-54
SLIDE 54

Stable marriage problem

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance?
  • Is stable marriage unique?
slide-55
SLIDE 55

Stable marriage problem

Input: m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance?
  • Is stable marriage unique?
  • Can it be computed efficiently?
slide-56
SLIDE 56

Stable marriage problem

Remarkable result of Gale and Shapley m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance?
slide-57
SLIDE 57

Stable marriage problem

Remarkable result of Gale and Shapley m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance? Yes, always!
  • Is stable marriage unique?
slide-58
SLIDE 58

Stable marriage problem

Remarkable result of Gale and Shapley m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance? Yes, always!
  • Is stable marriage unique? No, there is a range of stable

matchings; can be unique in some cases.

  • Can it be computed efficiently?
slide-59
SLIDE 59

Stable marriage problem

Remarkable result of Gale and Shapley m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2 Goal: To compute a matching that is “stable”.

  • Does a stable marriage exist in any instance? Yes, always!
  • Is stable marriage unique? No, there is a range of stable

matchings; can be unique in some cases.

  • Can it be computed efficiently? Yes, in O(n2) time.
slide-60
SLIDE 60

Stable marriage algorithm

m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2

  • set all men and women as unengaged.
  • while there exists an unengaged man m
  • 1. m proposes to the most preferred woman w to whom he has

not yet proposed.

  • 2. w accepts if either she is unengaged or she is engaged to m′

and w prefers m to m′.

slide-61
SLIDE 61

Stable marriage algorithm

m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2

  • set all men and women as unengaged.
  • while there exists an unengaged man m
  • 1. m proposes to the most preferred woman w to whom he has

not yet proposed.

  • 2. w accepts if either she is unengaged or she is engaged to m′

and w prefers m to m′.

Questions:

  • Does the algorithm even terminate?
slide-62
SLIDE 62

Stable marriage algorithm

m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2

  • set all men and women as unengaged.
  • while there exists an unengaged man m
  • 1. m proposes to the most preferred woman w to whom he has

not yet proposed.

  • 2. w accepts if either she is unengaged or she is engaged to m′

and w prefers m to m′.

Questions:

  • Does the algorithm even terminate?
  • Why does it output a stable marriage?
slide-63
SLIDE 63

Stable marriage algorithm

m1 : w1, w2, w3 m2 : w2, w3, w1 m3 : w3, w1, w2 w1 : m3, m2, m1 w2 : m2, m1, m3 w3 : m1, m3, m2

  • set all men and women as unengaged.
  • while there exists an unengaged man m
  • 1. m proposes to the most preferred woman w to whom he has

not yet proposed.

  • 2. w accepts if either she is unengaged or she is engaged to m′

and w prefers m to m′.

Questions:

  • Does the algorithm even terminate?
  • Why does it output a stable marriage?
  • How does the ordering of men in the while loop matter?
slide-64
SLIDE 64

Stable marriage algorithm

  • A surprisingly simple algorithm that is guaranteed to produce

a stable matching.

  • A rich structure underlying the problem.
slide-65
SLIDE 65

Stable marriage algorithm

  • A surprisingly simple algorithm that is guaranteed to produce

a stable matching.

  • A rich structure underlying the problem.

Has been dealt in two books – one by Irving and Gusfield and a recent one by Manlove.

  • National Residency Matching program – one of the most

important applications amongst several others.

  • Pioneering work by Roth and Shapley won the 2012 Nobel

prize for Economics.

slide-66
SLIDE 66

Summary

  • Matchings, definitions, augmenting/alternating paths.
  • A template for finding matchings by iterative improvement.
  • An efficient algorithm in the bipartite case.
  • Stable marriage algorithm and properties.
slide-67
SLIDE 67

Thank You!