Hungarian Algorithm II
KM(Kuhn–Munkres) Algorithm
Introduction
There are three workers: Paul, Dave, and Chris. One of them has to clean the bathroom, another sweep the floors and the third washes the windows, but they each demand different pay for the various tasks. The problem is to find the lowest-cost way to assign the jobs.
Clean Bathroom | Sweep floors | Wash windows | |
---|---|---|---|
Paul | $2 | $3 | $3 |
Dave | $3 | $2 | $3 |
Chris | $3 | $3 | $2 |
The Hungarian method, when applied to the above table, would give the minimum cost: this is 6 dollars, achieved by having Paul clean the bathroom(2 dollars), Dave sweep the floors(2 dollars), and Chris wash the windows(2 dollars).
There are two ways to formulate the problem: as a matrix or as a bipartite graph. The problem is easier to describe if we formulate it with a bipartite graph.
We have a complete bipartite graph
Prerequisite
Complete Bipartite Graph
From wikipedia, a complete bipartite graph is a special kind of bipartite graph whose vertices can be partitioned into two subsets

Complete Matching
The definition comes from the book by Narsingh Deo:
In a bipartite graph with vertex partition
- Every complete matching is maximum matching.
- Maximum matching may not necessary to be complete matching.
- However complete matching equals to maximum matching in complete bipartite graph
Note that, complete matching becomes perfect matching if

Vertex Labelling
For each vertex we assign some number called a label
In other words, the sum of the labels of the vertices on both sides of a given edge are greater than or equal to the weight of that edge.
Equality Subgraph
Let assume
If in
Then we call

KM(Kuhn–Munkres) Algorithm
KM(Kuhn–Munkres) algorithm provides the connection between equality subgraphs and maximum-weighted matching:
is an equality subgraph of bipartite graph . If
is a complete matching in , then is a maximum-weighted matching in .
KM(Kuhn–Munkres) algorithm has following steps:
Initialize feasible vertex labelling, where
and .Try to find complete(maximum) matching
by using Hungarian algorithm in the equality subgraph.If
does not exist, then update the vertex labelling to include others edges. The idea is to iterate augment path and add all visited vertices on each side into sets and , then update the vertex labelling:Repeat step 2 and step 3, until we find complete matching.
The key idea of KM(Kuhn–Munkres) algorithm is to utilize Hungarian algorithm while maintaining equality subgraphs. If you are not familiar with Hungarian algorithm, you can review my previous post.
Proof
Let’s assume
Remember that the vertices remain perfectly feasible during calculation, so that the sum of the edge weights always equals to the sum of all vertices labelling value:
$$ W(M^{}) = \sum_{e \in M^{}} W(e) = \sum_{ v \in V(G) } L(v) $$
Then we can proof that:
Thus the problem of finding an optimal assignment is reduced to the problem of finding a feasible vertex labelling whose equality subgraph contains a complete matching.
Example
So first of all, the vertex labelling on left side equals to the maximum weights from connected edges, and right side is 0 at the beginning.

OK, so the equality subgraph looks like:

And obviously, we are able to match vertex
Let’s go back to the original graph, and we can easily get the minimal delta value is:

After update:

Then what’s the new equality subgraph looks like?

Again, we notice that there are 2 matches:
Similarly,

After update

New equality subgraph:

We trying to find augment path from A3 -> B3 -> A1 -> B1 -> A2, but failed because it ends up with a matched vertex

Updating

And from the graph above, we should notice that it includes all edges from the original graph. We will find the final maximum-weighted matching if we can find the complete matching from current graph!

We apply Hungarian algorithm one more time, and the final complete matching will be:
Application Experience
Kuhn-Munkres algorithm deals with the maximum-weighted matching problem, what if I need to calculate minimal-weighted matching?
What if I want to calculate the maximum-product-weighted matching?
What if the graph is not Complete Bipartite Graph? Answer: assign missing edges as weights of 0.