Solve an assignment problem online

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

Don't show the steps of the Hungarian algorithm
Maximize the total cost

This is the original cost matrix:

18781045858285448
62454157648028236
92269287659169856
405069655755265688
10432561631887140
39739087238374410
39203074439136697
342984545415861980
31223394452386155

Subtract row minima

We subtract the row minimum from each row:

1070237777404640(-8)
60433955627808034(-2)
86208681598563790(-6)
14244339312903062(-26)
9422460621786039(-1)
3771888503635428(-2)
3011216534045788(-9)
1914693939071465(-15)
29021374250365953(-2)

Subtract column minima

We subtract the column minimum from each column:

17000777404640
51433718627808034
77208444598563790
524412312903062
0422223621786039
2871864803635428
2111192834045788
101467239071465
2001904250365953
(-9)(-2)(-37)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

17000777404640  x
51433718627808034
77208444598563790  x
524412312903062
0422223621786039  x
2871864803635428  x
2111192834045788
101467239071465
2001904250365953  x
xx

Create additional zeros

The number of lines is smaller than 9. The smallest uncovered number is 2. We subtract this number from all uncovered elements and add it to all elements that are covered twice:

17000777624640
49413516607807832
77208444598765790
322390292902860
0422223621988039
2871864803837428
199172632045586
81265037071263
2001904252385953

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

17000777624640  x
49413516607807832
77208444598765790  x
322390292902860
0422223621988039  x
2871864803837428  x
199172632045586
81265037071263
2001904252385953  x
xxx

Create additional zeros

The number of lines is smaller than 9. The smallest uncovered number is 2. We subtract this number from all uncovered elements and add it to all elements that are covered twice:

17002777844640
47393316587807630
77208446598967790
120370272902658
0422225622190039
2871865004039428
177152630045384
61063035071061
2001924254405953

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

17002777844640  x
47393316587807630  x
77208446598967790  x
120370272902658  x
0422225622190039  x
2871865004039428  x
177152630045384  x
61063035071061  x
2001924254405953  x

The optimal assignment

Because there are 9 lines required, the zeros cover an optimal assignment:

17002777844640
47393316587807630
77208446598967790
120370272902658
0422225622190039
2871865004039428
177152630045384
61063035071061
2001924254405953

This corresponds to the following optimal assignment in the original cost matrix:

18781045858285448
62454157648028236
92269287659169856
405069655755265688
10432561631887140
39739087238374410
39203074439136697
342984545415861980
31223394452386155

The optimal value equals 125.