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:

159684544
337450120
59817766
742355038
832338812

Subtract row minima

We subtract the row minimum from each row:

109179039(-5)
327349019(-1)
52110059(-7)
035284331(-7)
75153004(-8)

Subtract column minima

We subtract the column minimum from each column:

109069035
327239015
5200055
034184327
75142000
(-1)(-10)(-4)

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

109069035
327239015
5200055  x
034184327  x
75142000  x
x

Create additional zeros

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

08059025
22622905
52001055
034185327
751420100

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

08059025
22622905
52001055  x
034185327
751420100  x
xx

Create additional zeros

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

07554020
22572400
57001555
029135322
801420150

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

07554020
22572400
57001555  x
029135322
801420150
xxx

Create additional zeros

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

06241020
22441100
70002868
01605322
8017150

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

06241020  x
22441100  x
70002868  x
01605322  x
8017150  x

The optimal assignment

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

06241020
22441100
70002868
01605322
8017150

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

159684544
337450120
59817766
742355038
832338812

The optimal value equals 71.