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:

8689605994
8711744671
1349238636
6465396564
337531352

Subtract row minima

We subtract the row minimum from each row:

27301035(-59)
760633560(-11)
036107323(-13)
252602625(-39)
26046645(-7)

Subtract column minima

We subtract the column minimum from each column:

27301012
760633537
03610730
25260262
26046622
(-23)

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

27301012  x
760633537
03610730  x
25260262  x
26046622
x

Create additional zeros

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

27361012
700572931
04210730
25320262
20040016

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

27361012
700572931
04210730  x
25320262  x
20040016
xx

Create additional zeros

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

26360011
690562930
04310740
25330272
19039015

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

26360011
690562930
04310740  x
25330272
19039015
xxx

Create additional zeros

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

2436009
670562928
04512760
23330270
17039013

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

2436009  x
670562928  x
04512760  x
23330270  x
17039013  x

The optimal assignment

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

2436009
670562928
04512760
23330270
17039013

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

8689605994
8711744671
1349238636
6465396564
337531352

The optimal value equals 161.