Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Discrete Optimization (WI4227) 2018–2019

Topics: Matching theory (II): Minimum cost perfect matching


Book: Chapter 5.3

Minimum cost perfect matching


Given a graph G = (V, E) and a cost function c on the edges, we want to find a perfect matching in G of
minimum cost. The algorithm is similar to the Blossom shrinking algorithm for finding a maximum size
matching. One main difference is, that during the algorithm we both shrink and un-shrink. We therefore
keep a nested family Ω of odd subsets of V , corresponding to the blossoms that are shrunk.

Primal-dual idea
Consider the following linear program with variables xe for the edges.

min cT x (1)
s.t. x(δ(v)) = 1 ∀v ∈ V
x(δ(U )) ≥ 1 ∀U ⊆ V odd, |U | ≥ 3
x≥0

The inequalities x(δ(U )) ≥ 1 are called blossom inequalities. Since for every perfect matching M , its
indicence vector 1M is a feasible solution, this linear program gives a lower bound on the minimum cost
of a perfect matching. We will later see that equality holds. In the bipartite case, the blossom inequalities
can even be left out.
The dual linear program has a variable yU for every odd subset U ⊆ V and reads
X
max yU (2)
U
X
s.t. yU ≤ c(e) ∀e ∈ E
U :e∈δ(U )

yU ≥ 0 ∀U with |U | ≥ 3

Here U runs over all odd subsets of V .


During the algorithm, we keep a dual feasible solution of a very special form: we use only sets U
in a nested family Ω, so yU = 0 for all sets U not in Ω. Writing out the complementary slackness
conditions in terms of a perfect matching M and a dual feasible solution (Ω, y), we get
X
c(M ) ≥ yU
U ∈Ω

with equality if and only if


• M is a subset of the set of tight edges:
 X
E= := e ∈ E : c(e) = yU ,
U |e∈δ(U )

• |M ∩ δ(U )| ≤ 1 for every U with |U | ≥ 3 and yU > 0.


It is not a priori clear that such a perfect matching M and such a pair (Ω, y) exist as they are primal
and dual feasible solutions of a very special form. However, the algorithm will find such pair in the end,
showing that (??) and (??) always have optimal solutions coming from a perfect matching resp. a vector
y with as support a nested family.

1
The algorithm
The algorithm is Primal-Dual: during the algorithm, we keep a feasible dual solution (Ω, y) and a primal
solution (matching M ) that is not feasible (not perfect), but does satisfy the complementary slackness
conditions. As soon as our primal solution M becomes a perfect matching, it will be primal feasible and
hence a minimum cost perfect matching due to the complementary slackness conditions. So our dual
solution guides our matching augmentation to a minimum cost perfect matching.
To simplify things, we assume that we have nonnegative costs: c ≥ 0. This is without loss of generality
as we may increase all costs by the same amount without changing the problem. During the algorithm we
have the following objects:
• Nested family Ω of odd size subsets of V , including all singletons
• Dual feasible solution y that is zero for sets that are not in Ω
• E= is the set of tight edges with respect to (Ω, y)
• G0 := (V, E= )/Ω is obtained from (V, E= ) by shrinking the maximal sets in Ω
• A matching M 0 in G0
• An M 0 -alternating forest F in G0
• For each U ∈ Ω of size ≥ 3, we remember a spanning circuit CU of the graph obtained from (V, E= )
by restricting to U and then contracting all sets in Ω that are strictly contained in U . These circuits
are the blossoms that are shrunk. We need them when unshrinking pseudo-nodes.
Initialisation. When we start the algorithm we take Ω = {{v} | v ∈ V }, y ≡ 0. So E= = {e ∈ E | c(e) =
0} and G0 = (V, E= ). We take M 0 := ∅ and F := ∅.
Iteration. We are working in the shunk graph G0 = (E= , V )/Ω. Recall that a node v is called odd/even
if there is an M 0 -alternating path in the forest F from an exposed node to v of odd/even length. We look
for an edge e joining an even node to a node that is not odd. We have four cases to consider.
Case I. If e joins even nodes from different components of F , then we find an M 0 -augmenting path.
Augment M 0 , reset F := M 0 .
If M 0 is a perfect matching, unshrinking pseudo-nodes gives an optimal perfect matching in G.
STOP.
Case II. If e joins an even node to a node that is neither even nor odd, then we can extend the forest F .
Case III. If e joins even nodes of the same component of F , then we create a blossom C.
We shrink C: Let U be the set of nodes of G that occur in one of the (pseudo-)nodes in C. Add U
to Ω, set yU := 0 and set M 0 := M 0 /C, F := F/C. Observe that U becomes an even pseudo-node
in F/C. We also remember the circuit CU := C for later unshrinking.
Case IV. If no such edge e exists, we modify the dual solution y.
We add  ≥ 0 to yU for all U that are even (pseudo-)nodes of G0 , and subtract  for the U that are
odd (pseudo)nodes of G0 . We do not alter yU for other sets U .
We choose  as large as possible, under the condition that y remains a dual feasible solution. That
means that one of the following happens.
(a) Some yU becomes zero for a U corresponding to an odd pseudo-node in G0 . In that case we
remove U from Ω and unshrink CU , adjusting G0 , M 0 , F .
(b) Some edge of G becomes tight and is added to E= (and hence to G0 ).
(c)  can be taken arbitrarily large. In this case no perfect matching exists. STOP.
Remark 1. To keep track of edges becoming tight, it is useful to define the reduced cost
X
ce := ce − {yU : e ∈ δ(U )}.

So ce ≥ 0 for every edge e, and equality holds if edge e is tight. In the book they keep track of the reduced
costs and update them in each iteration.

2
Running time
The number of matching augmentations is O(n), where n := |V |.
The number of iterations between each two augmentations is O(n). Indeed, let neven be the number of
nodes of G that are in an even (pseudo-)node of G0 . It is easy to see that in any forest-augmentation
the number neven strictly increases as one (pseudo)node becomes even. In a shrinking step, the number
neven also strictly increases since the new pseudonode is even. In an unshrinking step, the number neven is
increased or remains the same since we only unshrink odd pseudo nodes. This implies that there are O(n)
forest-augmentation and shrinking steps. Since a set is unshrunk only if it was previously shrunk, also the
number of shrinking steps is O(n). Finally, each step in case IV(b) is followed by another type of step, so
there are only O(n) of those.
Since each iteration can (with some care) be performed in time O(m), we obtain an O(n2 m) algorithm.

An example
In the graph below the costs are written along the edges. The bold edges (in red) form a perfect
matching M . The dual solution is given by the values at the nodes and at the sets {a, b, c}, {f, g, i}, and
{a, b, c, d, f, g, h, i, j}. The non-tight edges are dashed.

abcdf ghij| 12

abc| 21 f gj| 72
2 5
a| 32 h|0 g| 23
1
1 6 2
1
b| − 2 3 0 3
1
3 5 2
c| 32 i|0 j| 23 f | 12
6 9

d|4

11 10
10

e| 11
2

We have:

c(M ) = 1 + 2 + 5 + 2 + 10 = 20
X
3 −1 3 11 1 3 3 1 7 1
yU = 2 + 2 + 2 +4+ 2 + 2 + 2 +0+0+ 2 + 2 + 2 + 2 = 20
U

showing that both are optimal. Also observe that (as expected) M uses only tight edges and |δ(U )∩M | = 1
for the three non-singleton sets U with yU > 0.
A step by step execution of the blossom algorithm leading to this solution can be found on Brightspace.

Exercises
CH 5.3: 5.25, 5.27, 5.31, 5.35

You might also like