You are on page 1of 3

Advanced Algorithms Course.

Lecture Notes. Part 7

Minimum Cost Perfect Matchings in Bipartite Graphs


Let G = (V, E) be a bipartite graph such that V = XY , |X| = |Y | = n, and
edges exist only between X and Y . Every edge e has a cost ce . We assume
that all n2 possible edges exist, because non-edges may be represented as
edges with huge cost. A perfect matching is a set of n pairwise disjoint edges.
We want a perfect matching with minimum cost. A typical application is
the assignment of n jobs to n agents (workers, machines, etc.). This time we
want to have all jobs done simultaneously. But different agents have different
abilities, therefore an assignment may be suitable or not so suitable, and this
is modelled by the edge costs.
We cannot simply reduce this problem to Maximum Flow, but still there
is a fast algorithm that closely follows the ideas of Ford and Fulkerson. We
solve the problem incrementally: Given a minimum-cost matching M with
i edges, we will compute a minimum-cost matching with i + 1 edges. For
i = 0, the empty set is trivially a matching with i edges and minimum cost,
thus we have an induction base. We are done as soon as i = n.
A node is called unmatched if it does not belong to any edge of M . Let
us define the residual graph GM as follows. We insert a source s and a sink
t, edges (s, x) for all unmatched x X, and edges (y, t) for all unmatched
y Y . All these edges have cost 0. The original edges in E with nodes
x X and y Y are oriented as follows: If e / M then GM contains
e = (x, y) with cost ce . If e M then GM contains e = (y, x) with cost ce .
(No mistake, these costs are negative.)
Now, if a directed s t path P exists in GM , we obtain a matching with
i+1 edges: Just change the status of all edges in E P . (Status means, being
in M or not.) Observe that the cost of the matching changes exactly by the
cost of P , this was the reason for defining these negative costs. Moreover, if

1
we have the choice among several such augmenting paths P , we select one
with minimum cost.
This was the whole algorithm. But since the selection rule for augment-
ing paths is a greedy rule, we have to prove that the final result will be
correct. We also need to discuss how we can find a minimum-cost path
efficiently: Due to the presence of negative edge costs, this is not just the
standard shortest-path problem. The correctness proof is rather compli-
cated, but it will also help us to implement the selection step efficiently.
First we need the following equivalence. Let M be any perfect matching.
Then M has minimum cost if and only if GM has no negative cycles (i.e.,
directed cycles with negative total cost).
To prove this equivalence, assume that C is a negative cycle in GM .
Then we can use C to improve the cost of M , just by changing the status
of all edges in C. Conversely, assume M is not minimum. We have to
show that GM contains a negative cycle. Since M is not minimal, there is
a cheaper perfect matching M 0 . Consider the symmetric difference D :=
(M \ M 0 ) (M \ M 0 ). It is not hard to see that D is a set of node-disjoint
directed cycles in GM . The total cost of D is negative, hence some of these
cycles must be negative.
When we increase the size i of M step by step, it would be nice to do
that in such a way that GM never gets negative cycles, because then we are
sure that the final M is minimum. In fact, we can acomplish this property
by introducing prices!
Every node v pays a price p(v) for being matched. We call the prices
compatible if the following is satisfied: p(x) = 0 for all unmatched x X,
p(x) + ce p(y) 0 for all edges e = (x, y), and p(x) + ce p(y) = 0 for
all edges e = (x, y) M . For every edge e = (v, w) in GM we define the
reduced cost by p(v) + ce p(w), where ce is the edge cost in GM . For
edges e = (y, x) this actually means p(y) ce p(x) since the cost of such
edges in GM is ce . Note that, for compatible prices, the reduced costs are
always nonnegative.
Now it is easy to show: If compatible prices exist for M , then GM has no
negative cycles. For the proof, just consider any cycle in GM . The cost of
the cycle equals the sum of costs of its edges. But it also equals the sum of
reduced costs of edges, because the positive and negative price terms at the
nodes cancel out around the cycle. And the reduced costs are nonnegative.
Another consequence of the nonnegative reduced costs is that we can
compute an st path with minimum reduced costs by any standard-shortest

2
path algorithm: In particular, we may use Dijkstras algorithm to find a
minimum reduced-cost path from s to every node y Y , in O(mn log n)
time. The real cost of any s y path is simply the reduced cost plus p(y),
since the price terms of all inner nodes of the path cancel out. Thus we
can find a minimum-cost s t path efficiently, by trying every y Y as
candidate for the second last node.
It remains to show that, by choosing a minimum-cost path P in each step,
we keep the prices compatible. Then the algorithm is correct. (Why?)
Initially, for i = 0, we do have compatible prices: Since M = , we set
p(x) = 0 for x X, and p(y) is the minimum cost of an edge incident with
y Y.
In any later step, let M be a matching with compatible prices p. We
obtain a matching M 0 by augmentation along some minimum-cost st path
P . Now we have to construct compatible prices for M 0 . Let d(v) denote
the distance from s to any node v, where the lengths of edges are their
reduced costs in GM . We claim that p0 (v) := p(v) + d(v) gives compatible
prices. Just check the conditions. We have p0 (x) = 0 for all x X yet
unmatched by M 0 , since we had p(x) = 0 before, and d(x) = 0. Next
consider any e = (x, y) M . Since (y, x) is the only edge in GM entering
x, it follows d(x) = d(y) + p(y) ce p(x), thus p0 (x) + ce p0 (y) = 0 as
desired. Next consider any (x, y) M 0 \ M . Such an edge must be on P ,
hence d(y) = d(x) + p(x) + ce p(y), and p0 (x) + ce p0 (y) = 0 as desired.
Finally consider any (x, y) / M M 0 . Here the triangle inequality yields
d(y) d(x) + p(x) + ce p(y), hence p0 (x) + ce p0 (y) 0 as desired.

You might also like