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:

49849948077342
7919372831374164
778366155811310
7864786853726762
472746292204091
32675446597251
1097371151305181
1287132616444628

Subtract row minima

We subtract the row minimum from each row:

19546917774039(-3)
60018912182245(-19)
7177055497574(-6)
25112515019149(-53)
452544270183889(-2)
10655244577049(-2)
08727141204171(-10)
0751144323416(-12)

Subtract column minima

We subtract the column minimum from each column:

19546907756035
6001881202241
7177054495770
2511251401145
45254426003885
10655144397045
0872704124167
0751134143412
(-1)(-18)(-4)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

19546907756035  x
6001881202241
7177054495770  x
2511251401145
45254426003885
10655144397045
0872704124167  x
0751134143412  x
xxx

Create additional zeros

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

19646907857035
5901771202140
7178054505870
2411241301134
44254325003784
00645044396944
0882704234167
0761135153412

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

19646907857035  x
5901771202140
7178054505870  x
2411241301134
44254325003784
00645044396944
0882704234167  x
0761135153412
xxxx

Create additional zeros

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

29746907958035
5901661202039
7279054515970
2411231201123
44254224003683
00634944396843
1892704344167
0760125153311

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

29746907958035  x
5901661202039  x
7279054515970  x
2411231201123  x
44254224003683  x
00634944396843  x
1892704344167  x
0760125153311  x

The optimal assignment

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

29746907958035
5901661202039
7279054515970
2411231201123
44254224003683
00634944396843
1892704344167
0760125153311

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

49849948077342
7919372831374164
778366155811310
7864786853726762
472746292204091
32675446597251
1097371151305181
1287132616444628

The optimal value equals 132.