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:

99270246672982
294355276288191
1655796023245646
3838507196825741
2472569923281519
79990288286512
164033257965254
1443917048435377

Subtract row minima

We subtract the row minimum from each row:

97068044652780(-2)
250314872247787(-4)
0396344784030(-16)
0012335844193(-38)
957418481304(-15)
59788086266310(-2)
123629217561210(-4)
029775634293963(-14)

Subtract column minima

We subtract the column minimum from each column:

97056037572780
250194865167787
0395144004030
000335136193
95729841504
59776079186310
123617216853210
029655627213963
(-12)(-7)(-8)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

97056037572780
250194865167787
0395144004030  x
000335136193  x
95729841504  x
59776079186310
123617216853210  x
029655627213963  x
xx

Create additional zeros

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

92051032522275
200144860117282
0445149004030
050385136193
96229891504
0977107413585
124117266853210
034656127213963

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

92051032522275
200144860117282
0445149004030  x
050385136193  x
96229891504  x
0977107413585
124117266853210  x
034656127213963
xxx

Create additional zeros

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

92046027471770
2009485566777
5495154004030
5100435136193
146729941504
097660698530
174617316853210
034606122163458

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

92046027471770
2009485566777
5495154004030  x
5100435136193  x
146729941504  x
097660698530
174617316853210
034606122163458
xxxx

Create additional zeros

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

92040021411170
2003484906177
11555160004036
11160495136199
20732910015010
097600632470
174611316247150
034546116102858

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

92040021411170  x
2003484906177  x
11555160004036  x
11160495136199  x
20732910015010  x
097600632470  x
174611316247150  x
034546116102858  x

The optimal assignment

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

92040021411170
2003484906177
11555160004036
11160495136199
20732910015010
097600632470
174611316247150
034546116102858

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

99270246672982
294355276288191
1655796023245646
3838507196825741
2472569923281519
79990288286512
164033257965254
1443917048435377

The optimal value equals 138.