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:
61 | 16 | 1 | 9 | 88 |
46 | 50 | 92 | 2 | 51 |
37 | 48 | 39 | 96 | 29 |
69 | 37 | 85 | 65 | 17 |
57 | 6 | 22 | 23 | 70 |
Subtract row minima
We subtract the row minimum from each row:
60 | 15 | 0 | 8 | 87 | (-1) |
44 | 48 | 90 | 0 | 49 | (-2) |
8 | 19 | 10 | 67 | 0 | (-29) |
52 | 20 | 68 | 48 | 0 | (-17) |
51 | 0 | 16 | 17 | 64 | (-6) |
Subtract column minima
We subtract the column minimum from each column:
52 | 15 | 0 | 8 | 87 |
36 | 48 | 90 | 0 | 49 |
0 | 19 | 10 | 67 | 0 |
44 | 20 | 68 | 48 | 0 |
43 | 0 | 16 | 17 | 64 |
(-8) |
Cover all zeros with a minimum number of lines
There are 5 lines required to cover all zeros:
52 | 15 | 0 | 8 | 87 | x |
36 | 48 | 90 | 0 | 49 | x |
0 | 19 | 10 | 67 | 0 | x |
44 | 20 | 68 | 48 | 0 | x |
43 | 0 | 16 | 17 | 64 | x |
The optimal assignment
Because there are 5 lines required, the zeros cover an optimal assignment:
52 | 15 | 0 | 8 | 87 |
36 | 48 | 90 | 0 | 49 |
0 | 19 | 10 | 67 | 0 |
44 | 20 | 68 | 48 | 0 |
43 | 0 | 16 | 17 | 64 |
This corresponds to the following optimal assignment in the original cost matrix:
61 | 16 | 1 | 9 | 88 |
46 | 50 | 92 | 2 | 51 |
37 | 48 | 39 | 96 | 29 |
69 | 37 | 85 | 65 | 17 |
57 | 6 | 22 | 23 | 70 |
The optimal value equals 63.
HungarianAlgorithm.com © 2013-2024