Algorithms for the Assignment and Transportation Problems: Munkres' Algorithm Terminates on Every Real n × n Matrix, and Its Final Starred Zeros Form a Minimum-Sum AssignmentResearch Paper
Motivation
The assignment problem asks how to assign men to jobs, one man per job, so that the total cost (or, equivalently, the total rating) is optimal. It is the simplest combinatorial optimization problem with a nontrivial polynomial-time algorithm, and it appears as a subroutine across operations research: in transportation and network-flow methods, in tracking and data association, in scheduling, and as the relaxation behind branch-and-bound methods for the travelling salesman problem.
The algorithm studied here is the one now usually called the Hungarian method or Kuhn–Munkres algorithm.
- 1931: Kőnig and Egerváry prove the theorem on lines and independent zeros of a matrix that the method rests on.
- 1955: H. W. Kuhn gives the Hungarian method, with finiteness argued for integer matrices through a decreasing integer sum (Kuhn 1955). M. Flood restates it as Steps A–D.
- 1957: J. Munkres gives a fully specified version, in which Step B of Flood's outline (find a minimal set of lines containing all zeros and a maximal set of independent zeros) is carried out by an explicit marking procedure with starred and primed zeros. He proves it correct, shows that the integrality assumption is unnecessary, and bounds the work by a polynomial in (Munkres 1957).
The mission formalizes Munkres' correctness proof for §1 of that paper.
Setting
Let be a real matrix, being the cost of assigning man (row ) to job (column ). A set of entries is independent if no two of them lie in the same line (row or column). An assignment is a permutation , with the man doing job . Its cost is , and is an optimal assignment if this cost is at most that of every permutation . Choosing independent entries of minimum sum is the same as choosing an optimal assignment.
The algorithm. A state of the algorithm holds the current matrix, a set of starred zeros , a set of primed zeros , a set of covered rows and a set of covered columns. An entry is non-covered, once-covered or twice-covered according as it lies in zero, one or two covered lines.
- Preliminaries. Subtract from each row its smallest element, then from each column its smallest entry. Consider the zeros in turn and star each one that has no starred zero in its row or column. Cover the columns containing a .
- Step 1. Prime a non-covered zero. If its row contains no , go to Step 2. Otherwise cover its row and uncover the column of that . When no non-covered zero remains, go to Step 3.
- Step 2. Build the alternating sequence . It starts at the just found. Each is the in the column of , each is the in the row of , and the sequence stops at a with no in its column. Unstar its starred zeros and star its primed zeros. Erase all primes, uncover all rows and cover the columns containing a . Stop if all columns are covered; otherwise return to Step 1.
- Step 3. Let be the smallest non-covered element. Add to each covered row, subtract from each uncovered column, and return to Step 1 with all marks kept.
The quantity , the maximal number of independent zeros of the matrix , measures progress.
Formalization targets
Goal: correctness of the algorithm
For every real matrix :
The four clauses are needed together: optimality at final states alone holds for an algorithm that never stops.
Milestones
- Remark (2): subtracting row constants and column constants does not change the optimal assignments.
- The zeros starred in the Preliminaries are independent.
- At Step 2 the sequence exists, is unique and has distinct elements.
- Step 2 leaves an independent set of starred zeros, larger by one.
- Lines containing all the zeros number at least the maximal number of independent zeros.
- At Step 3 the starred zeros are a maximal independent set and the covered lines a minimal cover.
- At Step 3, ; the transformation subtracts from non-covered entries, adds to twice-covered ones, keeps every and a zero, and .
- If , Step 2 does not occur before the next Step 3, which begins with more covered rows.
- While is constant, Step 3 is applied at most times.
- Every row and column of the matrix always contains a zero.
- Step 3 decreases the sum of the entries by .
Significance
Correctness of the Hungarian method is the basis of a standard algorithm for the assignment problem and, through it, of methods for transportation problems, minimum-cost bipartite matching and weighted bipartite matching. Its refinements remain in practical use. The invariants of the proof are the primal–dual structure of the problem: the row and column constants subtracted along the way form a dual solution, and the starred zeros at the end are a primal solution satisfying complementary slackness.
The result has been proved since 1957 and is in every textbook on combinatorial optimization. A machine-checked version of Munkres' specific procedure, as a transition system with all its free choices, with finiteness for real (not only integer) matrices, is not available on this platform; Mathlib has no assignment algorithm. The mission produces a verified specification of the algorithm, reusable invariants about covers and independent zeros, and a termination argument that does not rely on integrality.
Difficulty
Optimality at termination is short once the invariants are known. The work lies in two places.
First, the invariants hold only along runs. "Each is covered by precisely one line", "no column contains more than one " and "no row contains more than one " fail for arbitrary marked matrices, so they must be carried as an inductive invariant through every move, including the Step 3 transformation, which keeps the primes.
Second, termination. The obvious measure, the sum of the entries, decreases by at each Step 3, but for real entries can be arbitrarily small, so the decreasing sum gives no bound on the number of steps. The page replaces this argument by the stronger result of p. 35 (milestone 8), which holds for real entries. Turning it into a proof that every run of the nondeterministic move relation is finite, including the moves inside Step 1 and Step 2, is the core of the formalization.
Formalization scope
- Matrices and positions. Entries are arbitrary reals, as on p. 35. Positions are
Fin n × Fin n(row, column). - Output orientation. The output permutation follows the published definition
HeldWolfeCrowder_Assignment_Setting:σ ris the row assigned to columnr, the starred positions are , and optimality isIsOptimalAssignment A σwith respect to the original input matrix. - Nondeterminism. The algorithm is an inductive move relation
Step. The order in which the Preliminaries consider the zeros, and the non-covered zero primed in Step 1, are free choices. Every claim holds for every run. - Relational steps. Step 2's sequence and Step 3's are described relationally. Their existence, and , are theorems, not built into the moves.
- Reachable states. Invariants are stated for states reachable from a start state, never for arbitrary states.
- Finiteness. Finiteness of every run is accessibility (
Acc) of each start state for the reversed move relation. - Termination test after the Preliminaries. "If all columns are covered, stop" is also applied when leaving the Preliminaries. The page goes to Step 1 unconditionally there. If the Preliminaries already star zeros, Step 3 would then have no non-covered element.
- Independent zeros. The maximal number of independent zeros is a finite maximum of cardinalities, so it has no junk value.
- Edge case . No positivity of is assumed. For the start state is final.
- Ruled out. A goal stating only optimality at final states, or invariants stated for arbitrary states, would be a trivializing formalization; the goal states termination of every run and absence of stuck states as well.
Not formalized: the operation count of pp. 35–36, whose cost model is informal; the argument that returning to the standard input after Step 3 is unnecessary (pp. 34–35); König's theorem (Remark (1), cited); and §2 on the transportation problem, which is stated without proof.
Welcome contributions: proofs of the milestones, a general library of lines and independent zeros in matrices (reusable for König–Egerváry), and an executable refinement of the move relation.
Selected references
- J. Munkres, Algorithms for the assignment and transportation problems, J. Soc. Indust. Appl. Math. 5 (1957), 32–38. https://doi.org/10.1137/0105003
- H. W. Kuhn, The Hungarian method for the assignment problem, Naval Research Logistics Quarterly 2 (1955), 83–97. https://doi.org/10.1002/nav.3800020109
- M. Held, P. Wolfe, H. P. Crowder, Validation of subgradient optimization, Mathematical Programming 6 (1974), 62–88. https://doi.org/10.1007/BF01580223 (source of the published assignment-cost definitions reused here)