Skip to content

Commit 78f1df9

Browse files
authored
Chapter 9 revised.
1 parent 6293e6a commit 78f1df9

File tree

1 file changed

+94
-86
lines changed

1 file changed

+94
-86
lines changed

Chapters/Chapter9/chapter9.md

Lines changed: 94 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,94 @@
1-
## Matchings (Independent Edge Sets)
2-
In graph theory, a matching or independent edge set in an undirected graph is a set of edges without common vertices.
3-
The term matching is the more popular one, but it shouldn't be confused with another meaning of graph matching, namely computing the similarity of graphs (graph isomorphism).
4-
5-
Matchings are used in various applications such as network design, job assignments, and scheduling.
6-
More specifically, matching strategies are very useful in flow network algorithms such as the Edmonds-Karp algorithm that is also in our library.
7-
8-
### Some definitions and small examples
9-
The **cardinality** of a matching is the number of its edges. Figure *@maximal@* shows 3 matchings of cardinality 1, 2 and 2 (from left to right).
10-
11-
![Examples of maximal matchings. (Source: Wikimedia)](figures/Maximal-matching.pdf width=50&label=maximal)
12-
13-
A matching is **maximal** if it cannot be expanded to another matching by addition of any edge in the graph.
14-
The matchings in Figure *@maximal@* are maximal.
15-
16-
Moreover, a **maximum**(-cardinality) matching has the largest possible cardinality among all matchings in a graph.
17-
For each of the matchings in Figure *@maximal@*, Figure *@maximum@* shows a maximum matching example with cardinality 2, 3 and 2 respectively.
18-
19-
![Examples of maximum matchings. (Source: Wikimedia)](figures/Maximum-matching.pdf width=50&label=maximum)
20-
21-
We note from these examples that a maximum matching is always maximal, but the converse does not always hold.
22-
23-
A **maximum-weight** matching in a weighted graph is a matching with the largest sum of weights.
24-
Similarly, a **minimum-weight** matching has the smallest sum of weights.
25-
26-
### A greedy algorithm for matching
27-
The algorithm for graph matching implemented in this library is a simple greedy algorithm with time complexity of $O(|E|log(|V|))$.
28-
The class ```AIGraphMatchingAlgorithm``` can be instantiated to find an **approximation** either of the maximum-weight, the minimum-weight or the maximum-cardinality matching.
29-
30-
For instance, the pseudocode to greedily find a matching of large weight is the following one:
31-
```
32-
M ← Empty list that will contain the matching edges
33-
E ← Set of all edges
34-
remove all loops (edges joining a vertex to itself) from E
35-
36-
while E is not empty do
37-
let e be the edge in E with the highest weight
38-
add e to M
39-
remove e and all edges incident to e from E
40-
```
41-
For finding a matching of small weight, we use exactly the same algorithm except that we have to order the edges in descending weight instead of ascending.
42-
This is the same principle we already met for the Kruskal's algorithm.
43-
44-
In any case, the greedy graph matching algorithm finds a maximal matching but it doesn't always find the optimal solution, in contrast to more expensive matching algorithms like the Hungarian Maximum Matching Algorithm, the Blossom Algorithm or the Hopcroft–Karp Algorithm.
45-
Nevertheless, it can be proven that it is a 2-approximation (greedy result >= 1/2 optimal result).
46-
47-
To see that the result is not always optimal, consider the two matching versions of the weighted graph with four nodes and three edges in Figure *@epsilon@*.
48-
49-
![Counterexample: The greedy algorithm is not optimal.](figures/epsilon.pdf width=50&label=epsilon)
50-
51-
The greedy algorithm for maximum-weight would first take weight 1+epsilon and then stop (Figure *@epsilon@* top), missing the optimal weight sum 1+1 (Figure *@epsilon@* bottom).
52-
53-
### Stable matchings
54-
Maximality and minimality are not the only interesting optimal matching problems.
55-
Another goal for optimal matching is stability, based on mutual preferences between two contender groups such as men and women or students and colleges.
56-
57-
Our library implements the classical Gale-Shapely algorithm that solves the important Stable Matching Problem (aka Stable Marriage Problem).
58-
To simplify, the problem considers two groups A and B of equal size n and conceives a complete **bipartite** graph with their possible relations.
59-
Each group member has defined a strict preference ordering over all the members of the other group.
60-
A resulting matching would contain n edges, each one relating a different pair.
61-
62-
A matching is **stable** when there does not exist any pair which both prefer each other to their current partner under the matching.
63-
This leads to a sense of harmony and fairness in the outcome.
64-
65-
Here is the algorithm's pseudocode:
66-
```
67-
Every vertex begins unmatched.
68-
While there is an unmatched vertex in the set A
69-
the next unmatched vertex in A proposes to match with its most preferred B vertex it has not already tried to match with
70-
if the B vertex was unmatched then these vertices are now matched
71-
if the B vertex was matched, it chooses its preferred vertex among the proposed one or the existing match;
72-
depending on the choice, the proposed match wins or vertex A remains unmatched
73-
```
74-
This algorithm with complexity $O(n²)$ finds in any case a stable matching. However, it is extreme and dual in the sense that it generally yields the matching that is best for group A among all stable matchings, and worst (but still stable) for group B.
75-
76-
To run ```AIStableMatchingAlgorithm```, both groups of equal size must be set with the complete preferences of each contender ```AIStableMatchingNode``` in order to obtain the stable matching, a set of ```AIStableMatchingEdge```.
77-
78-
The Stable Matching Problem has extensions in many ways, e.g. with groups of different size or incomplete preference lists.
79-
### Conclusion
80-
Graph matching is a challenging problem, especially in large and complex graphs where scalability and complexity are crucial.
81-
Many graph matching algorithms exist in order to optimize for the parameters necessary dictated by the problem at hand.
82-
Depending on the context, approximation algorithms may be a suitable alternative.
83-
84-
From the practical and theoretical points of view, envisaging the special case of bipartite graphs is very common and fructiferous, notably for matching problems.
85-
86-
Both the greedy and the stable matching algorithm presented here are further examples of using a working list until emptied, like discussed for the topological sorting in this book.
1+
## Matching (Independent Edge Set)
2+
3+
In graph theory, a matching or independent edge set in an undirected graph is a set of edges without common vertices. The term matching is the more popular one, but it shouldn't be confused with another meaning of graph matching, namely computing the similarity of graphs (graph isomorphism).
4+
5+
Matchings are used in various applications such as network design, job assignments, and scheduling.
6+
7+
### Some definitions and small examples
8+
9+
The **cardinality** of a matching is the number of its edges. Figure *@maximal@* shows three matchings of cardinality $1$, $2$ and $2$ (from left to right).
10+
11+
![Examples of maximal matchings. (source: Wikimedia)](figures/Maximal-matching.pdf width=50&label=maximal)
12+
13+
A matching is **maximal** if it cannot be expanded to another matching by addition of any edge in the graph.
14+
The matchings in Figure *@maximal@* are maximal.
15+
16+
Moreover, a **maximum**(-cardinality) matching has the largest possible cardinality among all matchings in a graph.
17+
For each of the matchings in Figure *@maximal@*, Figure *@maximum@* shows a maximum matching example with cardinality $2$, $3$ and $2$ respectively.
18+
19+
![Examples of maximum matchings. (source: Wikimedia)](figures/Maximum-matching.pdf width=50&label=maximum)
20+
21+
We note from these examples that a maximum matching is always maximal, but the converse does not always hold.
22+
23+
A **maximum-weight** matching in a weighted graph is a matching with the largest sum of weights.
24+
Similarly, a **minimum-weight** matching has the smallest sum of weights.
25+
26+
### A greedy algorithm for matching
27+
28+
The algorithm for graph matching implemented in this library is a simple greedy algorithm with time complexity of $O(E * log(V))$.
29+
The class ```AIGraphMatchingAlgorithm``` can be instantiated to find an **approximation** either of the maximum-weight, the minimum-weight or the maximum-cardinality matching.
30+
31+
For instance, the pseudocode to greedily find a matching of large weight is the following one:
32+
33+
```
34+
M ← Empty list that will contain the matching edges
35+
E ← Set of all edges
36+
remove all loops (edges joining a node to itself) from E
37+
38+
while E is not empty do
39+
let e be the edge in E with the highest weight
40+
add e to M
41+
remove e and all edges incident to e from E
42+
```
43+
44+
For finding a matching of small weight, we use exactly the same algorithm except that we have to order the edges in descending weight instead of ascending.
45+
This is the same principle we already met for Kruskal's algorithm.
46+
47+
In any case, the greedy graph matching algorithm finds a maximal matching but it doesn't always find the optimal solution, in contrast to more expensive matching algorithms like the Hungarian Maximum Matching Algorithm, the Blossom Algorithm or the Hopcroft–Karp Algorithm.
48+
Nevertheless, it can be proven that it is a 2-approximation (greedy result $\geq \frac{1}{2}$ optimal result).
49+
50+
To see that the result is not always optimal, consider the two matching versions of the weighted graph with four nodes and three edges in Figure *@epsilon@*.
51+
52+
![Counterexample: The greedy algorithm is not optimal.](figures/epsilon.pdf width=50&label=epsilon)
53+
54+
The greedy algorithm for maximum-weight would first take weight $1+ \epsilon$ and then stop (top matching in Figure *@epsilon@*), missing the optimal weight sum $1+1$ (bottom matching in Figure *@epsilon@*) .
55+
56+
### Stable matchings
57+
58+
Maximality and minimality are not the only interesting optimal matching problems.
59+
Another goal for optimal matching is stability, based on mutual preferences between two contender groups such as men and women or students and colleges.
60+
61+
Our library implements the classical Gale-Shapely algorithm that solves the important Stable Matching Problem (aka Stable Marriage Problem).
62+
To simplify, the problem considers two groups A and B of equal size n and conceives a complete **bipartite** graph with their possible relations.
63+
Each group member has defined a strict preference ordering over all the members of the other group.
64+
A resulting matching would contain n edges, each one relating a different pair.
65+
66+
A matching is **stable** when there does not exist any pair which both prefer each other to their current partner under the matching.
67+
This leads to a sense of harmony and fairness in the outcome.
68+
69+
Here is the algorithm's pseudocode:
70+
71+
```
72+
Every node begins unmatched.
73+
While there is an unmatched node in the set A
74+
the next unmatched node in A proposes to match with its most preferred B node it has not already tried to match with
75+
if the B node was unmatched then these nodes are now matched
76+
if the B node was matched, it chooses its preferred node among the proposed one or the existing match;
77+
depending on the choice, the proposed match wins or node A remains unmatched
78+
```
79+
80+
This algorithm with complexity $O(n²)$ finds in any case a stable matching. However, it is extreme and dual in the sense that it generally yields the matching that is best for group A among all stable matchings, and worst (but still stable) for group B.
81+
82+
To run ```AIStableMatchingAlgorithm```, both groups of equal size must be set with the complete preferences of each contender ```AIStableMatchingNode``` in order to obtain the stable matching, a set of ```AIStableMatchingEdge```.
83+
84+
The Stable Matching Problem has extensions in many ways, e.g. with groups of different size or incomplete preference lists.
85+
86+
### Conclusion
87+
88+
Graph matching is a challenging problem, especially in large and complex graphs where scalability and complexity are crucial.
89+
Many graph matching algorithms exist in order to optimize for the parameters necessary dictated by the problem at hand.
90+
Depending on the context, approximation algorithms may be a suitable alternative.
91+
92+
From the practical and theoretical points of view, envisaging the special case of bipartite graphs is very common and fructiferous, notably for matching problems.
93+
94+
Both the greedy and the stable matching algorithm presented here are further examples of using a working list until emptied, like discussed for the topological sorting in this book.

0 commit comments

Comments
 (0)