Teaching / Algorithm Design / Network Flow III
Interactive lesson · Chapter 7 · Network Flow
Network Flow III: the assignment problem
Matching asks whether everyone can be paired. The assignment problem asks for the cheapest pairing. The idea that solves it is beautiful: put a price on every node, so that finding the next best change becomes a shortest-path problem with no negative edges.
For Algorithm Design (FTU, undergraduate). This page goes with the lecture slides 07 Network Flow III by Kevin Wayne. It builds on Part II (bipartite matching and alternating paths).
Sections: 1 The problem · 2 Prices change nothing · 3 Successive shortest paths · 4 Summary
1 · The problem (slides 3–9)
Pick the cheapest assignment
Given n workers X, n jobs Y, and a cost c(x, y) for giving job y to worker x, find a perfect matching of minimum total cost. Pick exactly one cell in every row and every column below. Can you beat every other assignment? There are n! of them.
2 · The key idea (slides 14–17)
Prices change nothing
Add a constant p(x) to every cost in row x. Every perfect matching uses exactly one cell of that row, so every matching gets p(x) more expensive: the best matching does not change. The same holds for subtracting a constant p(y) from a column. The reduced cost is cp(x,y) = p(x) + c(x,y) − p(y). Change the prices below: the numbers move, the optimal cells (outlined) never do. Prices are compatible with a matching M when cp ≥ 0 everywhere and = 0 on M: then M has cost 0 under cp, and nothing can be cheaper, so M is optimal.
3 · The algorithm (slides 12–34)
Successive shortest paths
Start with an empty matching and all prices 0. Repeat n times: find the cheapest alternating path from an unmatched x to an unmatched y, augment along it, then add each node’s distance to its price. Because the prices stay compatible, every edge has a non-negative reduced cost, so plain Dijkstra finds the path. The table on the right shows the reduced costs cp; the small grey number is the original cost. Edges with reduced cost 0 (tight) are free to use. It uses the problem you chose above.
Bipartite graph p = price · d = distance from the unmatched x
Reduced costs cp small grey = original c
4 · Summary (slides 34–40)
What to remember
- Invariant. The algorithm always holds a matching M and prices p that are compatible with it. Each iteration keeps this true (Lemmas 1–3), and at the end M is perfect, so it is optimal.
- Running time. n iterations, each a dense Dijkstra in O(n²): O(n³) in total. Trying all n! assignments is hopeless for n = 20.
- Where it comes from. It is max flow again: augmenting paths in the residual network, but always the cheapest one. Its history includes Kuhn’s Hungarian method (1955), named after the Hungarian mathematicians Kőnig and Egerváry (slides 35–40).
- Used for assigning tasks to workers, matching objects between frames, scheduling, and in a more general form for kidney exchange (slides 3–9).
Questions to explore
- Greedy. In section 1, always take the cheapest available cell row by row. Is it optimal? Use the lecture example.
- Equal costs. Make every cost 0 except a few. What does the algorithm do, and how does it relate to bipartite matching?
- Tight edges. After each iteration, which edges are tight? Why is every matched edge tight?
- Re-matching. Find an iteration whose path has a dashed (removed) edge. Why can a later worker take a job from an earlier one?