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:
17 | 58 | 46 | 25 | 44 |
27 | 70 | 99 | 52 | 45 |
5 | 34 | 15 | 63 | 15 |
63 | 93 | 72 | 25 | 13 |
74 | 16 | 93 | 82 | 83 |
Subtract row minima
We subtract the row minimum from each row:
0 | 41 | 29 | 8 | 27 | (-17) |
0 | 43 | 72 | 25 | 18 | (-27) |
0 | 29 | 10 | 58 | 10 | (-5) |
50 | 80 | 59 | 12 | 0 | (-13) |
58 | 0 | 77 | 66 | 67 | (-16) |
Subtract column minima
We subtract the column minimum from each column:
0 | 41 | 19 | 0 | 27 |
0 | 43 | 62 | 17 | 18 |
0 | 29 | 0 | 50 | 10 |
50 | 80 | 49 | 4 | 0 |
58 | 0 | 67 | 58 | 67 |
(-10) | (-8) |
Cover all zeros with a minimum number of lines
There are 5 lines required to cover all zeros:
0 | 41 | 19 | 0 | 27 | x |
0 | 43 | 62 | 17 | 18 | x |
0 | 29 | 0 | 50 | 10 | x |
50 | 80 | 49 | 4 | 0 | x |
58 | 0 | 67 | 58 | 67 | x |
The optimal assignment
Because there are 5 lines required, the zeros cover an optimal assignment:
0 | 41 | 19 | 0 | 27 |
0 | 43 | 62 | 17 | 18 |
0 | 29 | 0 | 50 | 10 |
50 | 80 | 49 | 4 | 0 |
58 | 0 | 67 | 58 | 67 |
This corresponds to the following optimal assignment in the original cost matrix:
17 | 58 | 46 | 25 | 44 |
27 | 70 | 99 | 52 | 45 |
5 | 34 | 15 | 63 | 15 |
63 | 93 | 72 | 25 | 13 |
74 | 16 | 93 | 82 | 83 |
The optimal value equals 96.
HungarianAlgorithm.com © 2013-2024