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:

9087695399024
38873043194741
5262758404239
474216587431
7858262946420
6827181327196
74633577844164

Subtract row minima

We subtract the row minimum from each row:

8178604408115(-9)
1968112402822(-19)
0212253353734(-5)
070176147027(-4)
0787555875713(-7)
0766575266590(-6)
392804249629(-35)

Subtract column minima

We subtract the column minimum from each column:

815760200752
19471100229
002229353121
049173746414
057753187510
0556551265977
39701849016
(-21)(-24)(-6)(-13)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

815760200752  x
19471100229  x
002229353121  x
049173746414
057753187510  x
0556551265977
39701849016  x
x

Create additional zeros

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

855760200752
23471100229
402229353121
045133306010
457753187510
0516147225573
43701849016

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

855760200752
23471100229  x
402229353121  x
045133306010
457753187510  x
0516147225573
43701849016  x
xx

Create additional zeros

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

855558180730
25471102229
602229373121
04311310588
657753189510
0495945225371
45701851016

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

855558180730
25471102229  x
602229373121  x
04311310588
657753189510
0495945225371
45701851016  x
xxx

Create additional zeros

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

85444770620
3647110132220
1702229483132
0320200478
646642089400
0384834224271
56701862027

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

85444770620  x
3647110132220  x
1702229483132  x
0320200478  x
646642089400  x
0384834224271  x
56701862027  x

The optimal assignment

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

85444770620
3647110132220
1702229483132
0320200478
646642089400
0384834224271
56701862027

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

9087695399024
38873043194741
5262758404239
474216587431
7858262946420
6827181327196
74633577844164

The optimal value equals 166.