View
10.950
Download
4
Category
Tags:
Preview:
DESCRIPTION
In graph theory, a matching is a subset of a graph's edges such hat no two edges meet the same vertex. A matching is maximum if no other matching contains more edges. A trivial solution (exhaustive search) to the problem of finding a maximum matching has exponential complexity. We illustrate polynomial time solutions to the problem that were published between 1965 and 1991.
Citation preview
Maximum Matching in General Graphs
Ahmad Khayyat
Department of Electrical & Computer Engineering
ahmad.khayyat@ece.queensu.ca
Course ProjectCISC 879 — Algorithms and Applications
Queen’s University
November 19, 2008
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 1
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Outline
1 Introduction
2 Paths, Trees and Flowers
3 Efficient Implementation of Edmonds’ Algorithm
4 Reachability Problem Approach
5 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 2
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Outline
1 IntroductionTerminologyBerge’s TheoremBipartite Matching
2 Paths, Trees and Flowers
3 Efficient Implementation of Edmonds’ Algorithm
4 Reachability Problem Approach
5 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 3
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Terminology
Maximum Matching
G = (V,E) is a finite undirected graph: n = |V |,m = |E|.A matching M in G, (G,M), is a subset of its edges suchthat no two meet the same vertex.
M is a maximum matching if no other matching in Gcontains more edges than M .
A maximum matching is not necessarily unique.
Given (G,M), a vertex is exposed if it meets no edge in M .
M
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 4
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Terminology
Augmenting Paths
An alternating path in (G,M) is a simple path whose edgesare alternately in M and not in M .
An augmenting path is an alternating path whose ends aredistinct exposed vertices.
v1 v2 v3
v4v5v6
v1 v2 v3
v4v5v6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 5
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Berge’s Theorem
Berge’s Theorem
Berge’s Theorem (1957)
A matched graph (G,M) has an augmenting path if and only if Mis not maximum.
v1 v2 v3
v4v5v6
v1 v2 v3
v4v5v6
Unique?
An Exponential Algorithm:Exhaustively search for an augmenting path starting from anexposed vertex.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 6
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Bipartite Matching
Bipartite Graphs
A bipartite graph G = (A,B,E) is a graph whose vertices canbe divided into two disjoint sets A and B such that everyedge connects a vertex in A to one in B.
Equivalently, it is a graph with no odd cycles.
1 A
C
D
E
B
4
3
2
5
1
2
3
A
B
4
5
D
C
E
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 7
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Bipartite Matching
Bipartite Graph Maximum Matching
O(nm)
for all v ∈ A, v is exposed doSearch for simple alternating paths starting at vif path P ends at an exposed vertex u ∈ B thenP is an augmenting path {Update M}
end ifend forCurrent M is maximum {No more augmenting paths}
1
2
3
A
B
4
5
D
C
E
1
2
3
A
B
4
5
D
C
E
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 8
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Bipartite Matching
Bipartite Graph Maximum Matching
O(nm)
for all v ∈ A, v is exposed doSearch for simple alternating paths starting at vif path P ends at an exposed vertex u ∈ B thenP is an augmenting path {Update M}
end ifend forCurrent M is maximum {No more augmenting paths}
1
2
3
A
B
4
5
D
C
E
1
2
3
A
B
4
5
D
C
E
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 8
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Bipartite Matching
Non-Bipartite Matching
Problem: Odd cycles . . .
1 2 3
4
5
6
1 2 3
46
5
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 9
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Outline
1 Introduction
2 Paths, Trees and FlowersBlossomsThe Algorithm
3 Efficient Implementation of Edmonds’ Algorithm
4 Reachability Problem Approach
5 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 10
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Blossoms
Blossoms
Blossoms
A blossom B in (G,M) is an odd cycle with a unique exposedvertex (the base) in M ∩B.
1 2 3
4
5
6
1 2 3
46
5
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 11
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Blossoms
Edmonds’ Blossoms Lemma
Blossoms Lemma
Let G′ and M ′ be obtained by contracting a blossom B in (G,M)to a single vertex.The matching M of G is maximum iff M ′ is maximum in G′.
1 2 3
4
5
6
1 2 B 6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 12
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Blossoms
Detecting Blossoms
Performing the alternating path search of the bipartitematching algorithm (starting from an exposed vertex):
ë Label vertices at even distance from the root as “outer”;ë Label vertices at odd distance from the root as “inner”.
If two outer vertices are found adjacent, we have a blossom.
1 2 3
4
5
6O I O
I
O
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 13
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Edmonds’ Algorithm (1965)
O(n2)O(n3)
for all v ∈ V , v is exposed doSearch for simple alternating paths starting at v
Shrink any found blossomsif path P ends at an exposed vertex thenP is an augmenting path {Update M}
else if no augmenting paths found thenIgnore v in future searches
end ifend forCurrent M is maximum {No more augmenting paths}
Complexity: O(n4)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 14
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10 9
8
5 6
7
B1B2
O I O I
O
I
O
OO
I
O
OI
B1 = 5, 6, 7B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10 9
8
5 6
7
B1B2
O I O I
O
I
O
OO
I
O
OI
B1 = 5, 6, 7B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10 9
8
5 6
7
B1
B2
O I O I
O
I
O
O
O
I
O
OI
B1 = 5, 6, 7
B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10 9
8
5 6
7
B1
B2
O I O I
O
I
O
O
O
I
O
OI
B1 = 5, 6, 7
B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10
9
8
5 6
7
B1
B2
O I O I
O
I
O
OO
I
O
OI
B1 = 5, 6, 7B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10
9
8
5 6
7
B1
B2
O I O I
O
I
O
OO
I
O
OI
B1 = 5, 6, 7B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4
|M | = 5
1 2 3 4
10 9
8
5 6
7
B1
B2
O I O I
O
I
O
OO
I
O
OI
B1 = 5, 6, 7B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Example
|M | = 4 |M | = 5
1 2 3 4
10 9
8
5 6
7
B1B2
O I O I
O
I
O
OO
I
O
OI
B1 = 5, 6, 7B2 = B1, 8, 9 = 5, 6, 7, 8, 9
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 15
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Outline
1 Introduction
2 Paths, Trees and Flowers
3 Efficient Implementation of Edmonds’ AlgorithmData StructuresThe AlgorithmPerformance
4 Reachability Problem Approach
5 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 16
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Data Structures
Three Arrays
u is an exposed vertex.
A vertex v is outer if there is a path P (v) = (v, v1, . . . , u),where vv1 ∈M .
1 MATE: Specifies a matching. An entry for each vertex:
ë vw ∈M ⇒ MATE (v) = w and MATE (w) = v.
2 LABEL: Provides a type and a value:
LABEL(v) ≥ 0 → v is outer
LABEL(u) → start label, P (u) = (u)
1 ≤ LABEL(v) ≤ n → vertex label
n+ 1 ≤ LABEL(v) ≤ n+ 2m → edge label
3 START (v) = the first non-outer vertex in P (v).
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 17
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Gabow’s Algorithm (1976)
O(n)
O(1)O(n)
O(n)O(n)
O(n)O(1)
for all u ∈ V, u is exposed dowhile ∃ an edge xy, x is outer AND
no augmenting path found doif y is exposed, y 6= u then
(y, x, . . . , u) is an augmenting pathelse if y is outer then
Assign edge labels to P (x) and P (y)else if MATE (y) is non-outer then
Assign a vertex label to MATE (y)end if
end whileend for
Complexity: O(n3)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 18
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Gabow’s Algorithm (1976)
O(n)
O(1)O(n)
O(n)O(n)
O(n)O(1)
for all u ∈ V, u is exposed dowhile ∃ an edge xy, x is outer AND
no augmenting path found doif y is exposed, y 6= u then
(y, x, . . . , u) is an augmenting pathelse if y is outer then
Assign edge labels to P (x) and P (y)else if MATE (y) is non-outer then
Assign a vertex label to MATE (y)end if
end whileend for
Complexity: O(n3)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 18
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Performance
Experimental Performance
Using an implementation in Algol W on the IBM 360/165
Worst-case graphs:
ë Efficient Implementation: run times proportional to n2.8.ë Edmond: run times proportional to n3.5.
Random graphs: times one order of magnitude faster thanworst-case graphs.
Space used is 5n+ 4m.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 19
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Outline
1 Introduction
2 Paths, Trees and Flowers
3 Efficient Implementation of Edmonds’ Algorithm
4 Reachability Problem ApproachReachability and GraphsThe Algorithm
5 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 20
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Reachability and Graphs
The Reachability Problem in Bipartite Graphs
Construction:
Bipartite graph + Matching → Directed graphG = (A,B,E) + M → G′ = (V ′, E′)
ë V ′ = V ∪ {s, t}ë ∀ xy ∈M,x ∈ A, y ∈ B → (x, y) ∈ E′ e ∈M ⇒ e : A→ B
ë ∀ xy /∈M,x ∈ A, y ∈ B → (y, x) ∈ E′ e /∈M ⇒ e : B → A
ë ∀ b ∈ B, b is exposed → add (s, b) to E′
ë ∀ a ∈ A, a is exposed → add (a, t) to E′
A1
A2
B1
B2
=⇒
A1
A2
B1
B2
t s
An augmenting path in G ⇔ A simple path from s to t in G′.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 21
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Reachability and Graphs
The Reachability Problem in Bipartite Graphs
Construction:
Bipartite graph + Matching → Directed graphG = (A,B,E) + M → G′ = (V ′, E′)
ë V ′ = V ∪ {s, t}ë ∀ xy ∈M,x ∈ A, y ∈ B → (x, y) ∈ E′ e ∈M ⇒ e : A→ B
ë ∀ xy /∈M,x ∈ A, y ∈ B → (y, x) ∈ E′ e /∈M ⇒ e : B → A
ë ∀ b ∈ B, b is exposed → add (s, b) to E′
ë ∀ a ∈ A, a is exposed → add (a, t) to E′
A1
A2
B1
B2
=⇒
A1
A2
B1
B2
t s
An augmenting path in G ⇔ A simple path from s to t in G′.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 21
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Reachability and Graphs
The Reachability Problem in General GraphsConstruction
For each v ∈ V , we introduce two nodes vA and vB
V ′ = {vA, vB|v ∈ V } ∪ {s, t} s, t /∈ V, s 6= t
e ∈M ⇒ e : A→ B, e /∈M ⇒ e : B → A
E′ = {(xA, yB), (yA, xB) | (x, y) ∈M}∪ {(xB, yA), (yB, xA) | (x, y) /∈M}∪ {(s, xB) |x is exposed} ∪ {(xA, t) |x is exposed}
1 2
4 3
=⇒1A
1B
2A
2B
3A
3B
4A
4B
s
t
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 22
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Reachability and Graphs
The Reachability Problem in General GraphsStrongly Simple Paths
A path P in G′ is strongly simple if:
P is simple.vA ∈ P ⇒ vB /∈ P .
Theorem
There is an augmenting path in G if and only if there is a stronglysimple path from s to t in G′.
1 2
4 3
=⇒1A
1B
2A
2B
3A
3B
4A
4B
s
t
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 23
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Reachability and Graphs
Solving the Reachability Problem
Solution: A strongly simple path from s to t in G′:
Depth-First Search (DFS) for t starting at s.
DFS finds simple paths.
We need to find strongly simple paths only.
We use a Modified Depth-First Search (MDFS) algorithm.
Example:
1 2
4 3
=⇒1A
1B
2A
2B
3A
3B
4A
4B
s
t
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 24
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Reachability and Graphs
Solving the Reachability Problem
Solution: A strongly simple path from s to t in G′:
Depth-First Search (DFS) for t starting at s.
DFS finds simple paths.
We need to find strongly simple paths only.
We use a Modified Depth-First Search (MDFS) algorithm.
Example:
1 2
4 3
=⇒1A
1B
2A
2B
3A
3B
4A
4B
s
t
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 24
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Data Structures
Stack K
ë TOP(K): the last vertex added to the stack K.ë Vertices in K form the current path.ë In each step, the MDFS algorithm considers an edge
(TOP(K), v), v ∈ V ′.
List L(vA)ë To get a strongly simple path, vA and vB cannot be in K
simultaneously (we may ignore a vertex, temporarily).ë List L(vA) keeps track of such vertices.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 25
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
Hopcroft and Karp Algorithm for Bipartite Graphs (1973)
Step 1: M ← φ
Step 2: Let l(M) be the length of a shortest augmenting path of MFind a maximal set of paths {Q1, Q2, . . . , Qt} such that:
2.1 For each i, Qi is an augmenting path of M , |Qi| = l(M),Qi are vertex-disjoint.
2.2 Halt if no such paths exists.
Step 3: M ←M ⊕Q1 ⊕Q2 ⊕ · · · ⊕Qt; Go to 1.
Hopcroft and Karp Theorem
If the cardinality of a maximum matching is s, then this algorithmconstructs a maximum matching within 2b
√sc+ 2 executions of
Step 2.
Step 2 complexity: O(m)⇒ Overall complexity: O(√nm)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 26
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
The Algorithm
An O(√
nm) Algorithm for General Graphs
Blum describes an O(m) implementation of Step 2 for generalgraphs, using a Modified Breadth-First Search (MBFS).
Blum’s Step 2 Algorithm:
Step 1: Using MBFS, compute G′
Step 2: Using MDFS, compute a maximal set of strongly simple pathsfrom s to t in G′.
Blum’s Theorm
A maximum matching in a general graph can be found in timeO(√nm) and space O(m+ n).
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 27
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Outline
1 Introduction
2 Paths, Trees and Flowers
3 Efficient Implementation of Edmonds’ Algorithm
4 Reachability Problem Approach
5 ConclusionSummaryQuestions
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 28
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Summary
Summary
1965
Edmonds
O(n4)
1976
Gabow’sIm
plementation
O(n3)
1980
Micali &
Vazirani
O(n2.5)
1989
Vazirani’sProof
1990
Blum
O(n2.5)
1991
Gabow
O(n2.5)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 29
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Summary
References
Jack EdmondsPaths, Trees, and FlowersCanadian Journal of Mathematics, 17:449–467, 1965.
http://www.cs.berkeley.edu/~christos/classics/edmonds.ps
Harold N. GabowAn Efficient Implementation of Edmonds’ Algorithm forMaximum Matching on GraphsJournal of the ACM (JACM), 23(2):221–234, 1976.
Norbert BlumA New Approach to Maximum Matching in General GraphsLecture Notes in Computer Science: Automata, Languages and Programming,
443::586–597, Springer Berlin / Heidelberg, 1990.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 30
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Summary
Thank You
Thank You!
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 31
Introduction Paths, Trees and Flowers Efficient Implementation Reachability Approach Conclusion
Questions
Questions
???
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Maximum Matching in General Graphs • 32
Recommended