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:
44 | 6 | 80 | 39 | 28 |
58 | 74 | 80 | 69 | 76 |
3 | 60 | 63 | 55 | 98 |
72 | 97 | 2 | 63 | 62 |
46 | 73 | 90 | 40 | 84 |
Subtract row minima
We subtract the row minimum from each row:
38 | 0 | 74 | 33 | 22 | (-6) |
0 | 16 | 22 | 11 | 18 | (-58) |
0 | 57 | 60 | 52 | 95 | (-3) |
70 | 95 | 0 | 61 | 60 | (-2) |
6 | 33 | 50 | 0 | 44 | (-40) |
Subtract column minima
We subtract the column minimum from each column:
38 | 0 | 74 | 33 | 4 |
0 | 16 | 22 | 11 | 0 |
0 | 57 | 60 | 52 | 77 |
70 | 95 | 0 | 61 | 42 |
6 | 33 | 50 | 0 | 26 |
(-18) |
Cover all zeros with a minimum number of lines
There are 5 lines required to cover all zeros:
38 | 0 | 74 | 33 | 4 | x |
0 | 16 | 22 | 11 | 0 | x |
0 | 57 | 60 | 52 | 77 | x |
70 | 95 | 0 | 61 | 42 | x |
6 | 33 | 50 | 0 | 26 | x |
The optimal assignment
Because there are 5 lines required, the zeros cover an optimal assignment:
38 | 0 | 74 | 33 | 4 |
0 | 16 | 22 | 11 | 0 |
0 | 57 | 60 | 52 | 77 |
70 | 95 | 0 | 61 | 42 |
6 | 33 | 50 | 0 | 26 |
This corresponds to the following optimal assignment in the original cost matrix:
44 | 6 | 80 | 39 | 28 |
58 | 74 | 80 | 69 | 76 |
3 | 60 | 63 | 55 | 98 |
72 | 97 | 2 | 63 | 62 |
46 | 73 | 90 | 40 | 84 |
The optimal value equals 127.
HungarianAlgorithm.com © 2013-2025