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:

368311378071919913
43198983533949383
739235614194165164
228249851456423
1726948558675468
90352308650778774
907033712158962593
408471769830342850
633710246423581887

Subtract row minima

We subtract the row minimum from each row:

2572026696080882(-11)
42097973432939282(-1)
57761945257803548(-16)
026229649436201(-2)
0716847457665367(-1)
87049278347748471(-3)
6949125003775472(-21)
125643487026022(-28)
5327014541348877(-10)

Subtract column minima

We subtract the column minimum from each column:

2572012695880881
42097833430939281
57761931257603547
026228249416200
0716833455665366
87049138345748470
6949123603575471
125643347006021
532700541148876
(-14)(-2)(-1)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

2572012695880881  x
42097833430939281
57761931257603547  x
026228249416200  x
0716833455665366  x
87049138345748470
6949123603575471  x
125643347006021  x
532700541148876  x
x

Create additional zeros

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

2585012695880881
29084702117807968
57891931257603547
039228249416200
0846833455665366
7403607032617157
6962123603575471
126943347006021
534000541148876

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

2585012695880881
29084702117807968
57891931257603547  x
039228249416200  x
0846833455665366  x
7403607032617157
6962123603575471  x
126943347006021  x
534000541148876
xxx

Create additional zeros

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

2485012685779870
28084702016797867
57902032257603547
040238349416200
0856934455665366
7303606931607056
6963133703575471
127044357006021
524000531047775

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

2485012685779870  x
28084702016797867  x
57902032257603547  x
040238349416200  x
0856934455665366  x
7303606931607056  x
6963133703575471  x
127044357006021  x
524000531047775  x

The optimal assignment

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

2485012685779870
28084702016797867
57902032257603547
040238349416200
0856934455665366
7303606931607056
6963133703575471
127044357006021
524000531047775

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

368311378071919913
43198983533949383
739235614194165164
228249851456423
1726948558675468
90352308650778774
907033712158962593
408471769830342850
633710246423581887

The optimal value equals 124.