Minimum Weight Perfect Matching - IP
Minimum Weight Perfect Matching - IP
Theorem 1.5 (Hall 1935) Given a bipartite graph G = (V, E) with bipartition A, B (V =
A ∪ B), G has a matching of size |A| if and only if for every S ⊆ A we have |N (S)| ≥ |S|,
where N (S) = {b ∈ B : ∃a ∈ S with (a, b) ∈ E}.
Clearly, the condition given in Hall’s theorem is necessary; its sufficiency can be derived
from König’s theorem.
Exercise 1-8. Consider a bipartite graph G = (V, E) with bipartition (A, B). For X ⊆ A,
define def(X) = |X| − |N (X)| where N (X) = {b ∈ B : ∃a ∈ X with (a, b) ∈ E}. Let
1.Generalize Hall’s theorem by showing that the maximum size of a matching in a bipar-
tite graph G equals |A| − def max .
2.For any 2 subsets X, Y ⊆ A, show that
the input (i.e. the number of bits needed to represent the input). Munkres’ analysis even
shows that the algorithm is strongly polynomial, and this means that the running time is
polynomial in the number of numbers involved (i.e. does not depend on the size of the costs
cij ). In this algorithm, the number of operations is upper bounded by O(n3 ) where n = |V |.
The algorithm is often called the Hungarian method, as it relies on ideas developed by
Hungarians, and especially König and Egerváry. In 2006, it was discovered that the method
had actually been discovered in the 19th century by Jacobi and this was posthumously pub-
lished in 1890 in Latin, see http://www.lix.polytechnique.fr/∼ollivier/JACOBI/jacobiEngl.htm.
We start by giving a formulation of the problem as an integer program, i.e. an optimiza-
tion problem in which the variables are restricted to integer values and the constraints and
the objective function are linear as a function of these variables. We first need to associate
a point to every matching. For this purpose, given a matching M , let its incidence vector
be x where xij = 1 if (i, j) ∈ M and 0 otherwise. One can formulate the minimum weight
perfect matching problem as follows:
X
Min cij xij
i,j
subject to:
X
xij = 1 i∈A
j
X
xij = 1 j∈B
i
xij ≥ 0 i ∈ A, j ∈ B
xij integer i ∈ A, j ∈ B.
This is not a linear program, but a so-called integer program. Notice that any solution to
this integer program corresponds to a matching and therefore this is a valid formulation of
the minimum weight perfect matching problem in bipartite graphs.
Consider now the linear program (P ) obtained by dropping the integrality constraints:
X
Min cij xij
i,j
subject to:
X
(P ) xij = 1 i∈A
j
X
xij = 1 j∈B
i
xij ≥ 0 i ∈ A, j ∈ B.
This is the linear programming relaxation of the above integer program. In a linear pro-
gram, the variables can take fractional values and therefore there are many feasible solutions
to the set of constraints above which do not correspond to matchings. But we only care
1. Lecture notes on bipartite matching February 4th, 2015 8
about the optimum solutions. The set of feasible solutions to the constraints in (P ) forms a
bounded polyhedron or polytope, and when we optimize a linear constraint over a polytope,
the optimum will be attained at one of the “corners” or extreme points of the polytope. An
extreme point x of a set Q is an element x ∈ Q which cannot be written as λy + (1 − λ)z
with 0 < λ < 1, y, z ∈ Q with y 6= z. (This will be formalized and discussed in greater depth
in the chapter on polyhedral combinatorics.)
In general, even if all the coefficients of the constraint matrix in a linear program are either
0 or 1, the extreme points of a linear program are not guaranteed to have all coordinates
integral (this is of no surprise since the general integer programming problem is NP-hard,
while linear programming is polynomially solvable). As a result, in general, there is no
guarantee that the value ZIP of an integer program is equal to the value ZLP of its LP
relaxation. However, since the integer program is more constrained than the relaxation, we
always have that ZIP ≥ ZLP , implying that ZLP is a lower bound on ZIP for a minimization
problem. Moreover, if an optimum solution to a linear programming relaxation is integral
(in our case, that would imply it is the incidence vector of a perfect matching) then it must
also be an optimum solution to the integer program.
However, in the case of the perfect matching problem, the constraint matrix has a very
special form and one can show the following very important result.
Theorem 1.6 Any extreme point of (P ) is a 0-1 vector and, hence, is the incidence vector
of a perfect matching.
such that ui + vj ≤ cij for all i ∈ A and j ∈ B. Then for any perfect matching M , we have
that X X X
cij ≥ ui + vj . (1)
(i,j)∈M i∈A j∈B
P P
Thus, i∈A ui + j∈B vj is a lower bound on the cost of the minimum cost perfect matching
(for bipartite graphs). To get the best lower bound, we would like to maximize this quantity,
and therefore we obtain another linear program
X X
Max ui + vj
i∈A j∈B
subject to:
(D) ui + vj ≤ cij i ∈ A, j ∈ B.
The constraints can be interpreted as wij ≥ 0 where wij = cij − ui − vj . This is a linear
program, call it (D). So far, we have shown that this linear program (D) provides a lower
bound on the cost of any perfect matching, but we can even prove that it provides a lower
bound on the value of any solution to the linear program (P ). Indeed consider any x ∈ P .
We have
XX XX
cij xij ≥ (ui + vj )xij
i∈A j∈B i∈A j∈B
! !
X X X X
= ui xij + vj xij
i∈A j∈B j∈B i∈A
X X
= ui + vj ,
i∈A j∈B
because of the constraints that x satisfy. (D) is the dual linear program in the sense of linear
programming duality.
In summary, so far, we know that
" #
X X X X
min cij ≥ min cij xij ≥ max ui + vj .
perfect matchings M (i,j)∈M x∈P
(i,j)
(u,v)∈D
i∈A j∈B
If, for any instance, we could always find a feasible solution u, v to (D) and a perfect matching
M such that we have equality in (1) (i.e. the cost of the perfect matching is equal to the
value of the dual solution) then we would know that we have equality throughout, that the
matching found is optimum, and that furthermore, the incidence vector of the matching M
is optimum for the linear program (P ). Given a solution u, v to the dual, a perfect matching
M would satisfy equality if it contains only edges (i, j) such that wij = cij − ui − vj = 0.
This is what is referred to as complementary slackness. However, for a given u, v, we may
not be able to find a perfect matching among the edges with wij = 0.
1. Lecture notes on bipartite matching February 4th, 2015 10
and
vj i∈B−L
vj =
vj − δ j ∈ B ∩ L
One easily check that this dual solution is feasible, in the sense that the corresponding vector
w satisfies wij ≥ 0 for all i and j. What is the value of the new dual solution? The difference
between the values of the new dual solution and the old dual solution is equal to:
n
δ(|A ∩ L| − |B ∩ L|) = δ(|A ∩ L| + |A − L| − |A − L| − |B ∩ L|) = δ( − |C ∗ |),
2
where A has size n/2 and C ∗ is the optimum vertex cover for the bipartite graph with edge
set E. But by assumption |C ∗ | < n2 , implying that the value of the dual solution strictly
increases.
One repeats this procedure until the algorithm terminates. At that point, we have
an incidence vector of a perfect matching and also a dual feasible solution which satisfy
complementary slackness. They must therefore be optimal and this proves the existence of
1. Lecture notes on bipartite matching February 4th, 2015 11
an integral optimum solution to (P ). Since, by carefully choosing the cost function, one can
make any extreme point be the unique optimum solution to the linear program (this will
be formally proved in the polyhedral chapter), this shows that any extreme point is integral
and hence this proves Theorem 1.6.
Of course, as some of the readers might have noticed, the proof is not complete yet since
one needs to prove that the algorithm indeed terminates. This can be proved by noticing
that at least one more vertex of B must be reachable from an exposed vertex of A (and no
vertex of B becomes unreachable), since an edge e = (i, j) with i ∈ (A ∩ L) and j ∈ B − L
now has wij = 0 by our choice of δ. This also gives an estimate of the number of iterations.
In at most n/2 iterations, all vertices of B are reachable or the matching found has increased
by at least one unit. Therefore, after O(n2 ) iterations, the matching found is perfect. The
overall running time of the algorithm is thus O(n4 ) since it takes O(n2 ) to compute the set L
in each iteration. By looking more closely at how vertices get labelled between two increases
of the size of the matching, one can reduce the running time analysis to O(n3 ).
Exercise 1-11. Check that the running time of the algorithm is indeed O(n3 ).
Example: Consider the instance given by the following cost matrix defined on a bipartite
graph with 5 vertices on each side of the bipartition:
0 2 7 2 3
1 3 9 3 3
1 3 3 1 2
4 0 1 0 2
0 0 3 0 0
Assume that uT = (2, 3, 0, −2, 0) and v T = (−2, 0, 3, 0, 0). The set E of edges with
wij = 0 corresponds exactly to the set of edges in Figure 1.1. The maximum cardinality
matching algorithm finds the matching (1, 9), (2, 6), (3, 8) and (5, 7), and the set of labelled
vertices is {3, 4, 8}. We compute δ as
δ= min wij = 1
i∈{3,4},j∈{6,7,9,10}
corresponding to the edge (3, 9). The new vectors u and v are uT = (2, 3, 1, −1, 0) and
v T = (−2, 0, 2, 0, 0). The value of the dual solution has increased from 4 units to 5. The
corresponding set E now has a perfect matching, namely (1, 6), (2, 7), (3, 9), (4, 8) and (5, 10)
of cost 5. Both the matching and the dual solution are optimal.
Exercises
Exercise 1-12. Consider a bipartite graph G = (V, E) in which every vertex has degree
k (a so-called k-regular bipartite graph). Prove that such a graph always has a perfect
matching in two different ways: