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:
83 | 58 | 91 | 39 | 16 | 12 |
30 | 33 | 72 | 33 | 70 | 77 |
12 | 12 | 6 | 1 | 5 | 3 |
79 | 75 | 79 | 91 | 16 | 57 |
58 | 84 | 8 | 31 | 18 | 75 |
44 | 70 | 99 | 82 | 65 | 75 |
Subtract row minima
We subtract the row minimum from each row:
71 | 46 | 79 | 27 | 4 | 0 | (-12) |
0 | 3 | 42 | 3 | 40 | 47 | (-30) |
11 | 11 | 5 | 0 | 4 | 2 | (-1) |
63 | 59 | 63 | 75 | 0 | 41 | (-16) |
50 | 76 | 0 | 23 | 10 | 67 | (-8) |
0 | 26 | 55 | 38 | 21 | 31 | (-44) |
Subtract column minima
We subtract the column minimum from each column:
71 | 43 | 79 | 27 | 4 | 0 |
0 | 0 | 42 | 3 | 40 | 47 |
11 | 8 | 5 | 0 | 4 | 2 |
63 | 56 | 63 | 75 | 0 | 41 |
50 | 73 | 0 | 23 | 10 | 67 |
0 | 23 | 55 | 38 | 21 | 31 |
(-3) |
Cover all zeros with a minimum number of lines
There are 6 lines required to cover all zeros:
71 | 43 | 79 | 27 | 4 | 0 | x |
0 | 0 | 42 | 3 | 40 | 47 | x |
11 | 8 | 5 | 0 | 4 | 2 | x |
63 | 56 | 63 | 75 | 0 | 41 | x |
50 | 73 | 0 | 23 | 10 | 67 | x |
0 | 23 | 55 | 38 | 21 | 31 | x |
The optimal assignment
Because there are 6 lines required, the zeros cover an optimal assignment:
71 | 43 | 79 | 27 | 4 | 0 |
0 | 0 | 42 | 3 | 40 | 47 |
11 | 8 | 5 | 0 | 4 | 2 |
63 | 56 | 63 | 75 | 0 | 41 |
50 | 73 | 0 | 23 | 10 | 67 |
0 | 23 | 55 | 38 | 21 | 31 |
This corresponds to the following optimal assignment in the original cost matrix:
83 | 58 | 91 | 39 | 16 | 12 |
30 | 33 | 72 | 33 | 70 | 77 |
12 | 12 | 6 | 1 | 5 | 3 |
79 | 75 | 79 | 91 | 16 | 57 |
58 | 84 | 8 | 31 | 18 | 75 |
44 | 70 | 99 | 82 | 65 | 75 |
The optimal value equals 114.
HungarianAlgorithm.com © 2013-2023