Fill in the cost matrix of an assignment problem and click on 'Solve'. The optimal assignment will be determined and a step by step explanation of the hungarian algorithm will be given.
Fill in the cost matrix (random cost matrix):
Size: 3x3 4x4 5x5 6x6 7x7 8x8 9x9 10x10
This is the original cost matrix:
75 | 48 | 11 | 15 |
93 | 97 | 55 | 76 |
91 | 4 | 51 | 20 |
82 | 89 | 33 | 72 |
Subtract row minima
We subtract the row minimum from each row:
64 | 37 | 0 | 4 | (-11) |
38 | 42 | 0 | 21 | (-55) |
87 | 0 | 47 | 16 | (-4) |
49 | 56 | 0 | 39 | (-33) |
Subtract column minima
We subtract the column minimum from each column:
26 | 37 | 0 | 0 |
0 | 42 | 0 | 17 |
49 | 0 | 47 | 12 |
11 | 56 | 0 | 35 |
(-38) | (-4) |
Cover all zeros with a minimum number of lines
There are 4 lines required to cover all zeros:
26 | 37 | 0 | 0 | x |
0 | 42 | 0 | 17 | x |
49 | 0 | 47 | 12 | x |
11 | 56 | 0 | 35 | x |
The optimal assignment
Because there are 4 lines required, the zeros cover an optimal assignment:
26 | 37 | 0 | 0 |
0 | 42 | 0 | 17 |
49 | 0 | 47 | 12 |
11 | 56 | 0 | 35 |
This corresponds to the following optimal assignment in the original cost matrix:
75 | 48 | 11 | 15 |
93 | 97 | 55 | 76 |
91 | 4 | 51 | 20 |
82 | 89 | 33 | 72 |
The optimal value equals 145.
HungarianAlgorithm.com © 2013-2024