Logo HungarianAlgorithm.com

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



Solution

This is the cost matrix.

5960957197580666
8980729234883906720
36602591619198353
1068912838294280214
1852175030756961191
8522161824166353651
11325644113548162954
10848998725075135124
9421246661834783090
80997765647366699761

Subtract row minima

For each row, the minimum element is subtracted from all elements in that row.

5455452142075161(-5)
8677698904580876417(-3)
35592480609088252(-1)
664872434253876170(-4)
1751164929746860090(-1)
8421151723065343550(-1)
02145330243751843(-11)
074798862406534114(-10)
8613165853026702282(-8)
193816431258360(-61)

Subtract column minima

For each column, the minimum element is subtracted from all elements in that column.

5442048142072161
8664658504580846417
35462040609058252
651832034253873170
1738124529746857090
848111323065313550
0841290243721843
061758462406504114
860125453026672282
192512031255360
(-13)(-4)(-4)(-3)

Cover all zeros with a minimum number of lines

A total of 9 lines are required to cover all zeros.

5442048142072161x
8664658504580846417
35462040609058252
651832034253873170x
1738124529746857090x
848111323065313550x
0841290243721843x
061758462406504114x
860125453026672282x
192512031255360x
x

Create additional zeros

The number of lines is smaller than 10. The smallest uncovered element is 4. We subtract this value from all uncovered elements and add it to all elements covered twice.

5442048182072161
8260618104176806013
31421600568617848
651832038253873170
1738124533746857090
848111327065313550
0841294243721843
061758466406504114
860125457026672282
192512071255360

Cover all zeros with a minimum number of lines

A total of 9 lines are required to cover all zeros.

5442048182072161x
8260618104176806013
31421600568617848
651832038253873170
1738124533746857090x
848111327065313550x
0841294243721843x
061758466406504114x
860125457026672282x
192512071255360
xxx

Create additional zeros

The number of lines is smaller than 10. The smallest uncovered element is 1. We subtract this value from all uncovered elements and add it to all elements covered twice.

5442049192072162
8159608104075795913
30411500558507748
550822038243772160
1738124634746857091
848111428065313551
0841305243721844
061758567406504115
860125558026672283
182411071144350

Cover all zeros with a minimum number of lines

A total of 9 lines are required to cover all zeros.

5442049192072162x
8159608104075795913
30411500558507748
550822038243772160
1738124634746857091x
848111428065313551x
0841305243721844
061758567406504115
860125558026672283x
182411071144350
xxxxx

Create additional zeros

The number of lines is smaller than 10. The smallest uncovered element is 4. We subtract this value from all uncovered elements and add it to all elements covered twice.

5842053232076166
8155568103671795513
30371100518107348
546782038203372120
2138125038746861095
888111832065353555
0437305203321444
057718567366103715
900125962026712287
1820707704310

Cover all zeros with a minimum number of lines

A total of 10 lines are required to cover all zeros.

5842053232076166x
8155568103671795513x
30371100518107348x
546782038203372120x
2138125038746861095x
888111832065353555x
0437305203321444x
057718567366103715x
900125962026712287x
1820707704310x

The optimal assignment

Because there are 10 lines required, an optimal assignment exists among the zeros.

5842053232076166
8155568103671795513
30371100518107348
546782038203372120
2138125038746861095
888111832065353555
0437305203321444
057718567366103715
900125962026712287
1820707704310

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

5960957197580666
8980729234883906720
36602591619198353
1068912838294280214
1852175030756961191
8522161824166353651
11325644113548162954
10848998725075135124
9421246661834783090
80997765647366699761

The total minimum cost is 138.


HungarianAlgorithm.com © 2026. All rights reserved.
Part of Echion, KvK 50713795, BTW NL001446762B10.