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:

829137644939
81841504563
98118172323
868268951040
788131297044
845710366091

Subtract row minima

We subtract the row minimum from each row:

4554027122(-37)
80830494462(-1)
903091515(-8)
76725885030(-10)
4952204115(-29)
74470265081(-10)

Subtract column minima

We subtract the column minimum from each column:

051027120
35800494460
450091513
31695885028
449204113
29440265079
(-45)(-3)(-2)

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

051027120  x
35800494460
450091513  x
31695885028  x
449204113  x
29440265079
x

Create additional zeros

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

0512627120
9540231834
4502691513
31698485028
4492804113
318002453

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

0512627120  x
9540231834
4502691513  x
31698485028  x
4492804113
318002453
xx

Create additional zeros

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

0512930120
6510231531
45029121513
31698788028
1462803810
015002150

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

0512930120  x
6510231531  x
45029121513  x
31698788028  x
1462803810  x
015002150  x

The optimal assignment

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

0512930120
6510231531
45029121513
31698788028
1462803810
015002150

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

829137644939
81841504563
98118172323
868268951040
788131297044
845710366091

The optimal value equals 174.