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.

4758792453369470
119797624538678
9322112873626763
958265589616069
258145311116588
8522624831994095
75193926780184
4650422524866168

Subtract row minima

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

233455029127046(-24)
59191563932072(-6)
821101762515652(-11)
870184781535261(-8)
2278420886285(-3)
63040269771873(-22)
73173706578162(-2)
22261810623744(-24)

Subtract column minima

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

18345502947044
09191563924070
771101762435650
820184781455259
1778420806283
58040269691871
68173706570160
17261810543742
(-5)(-8)(-2)

Cover all zeros with a minimum number of lines

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

18345502947044x
09191563924070x
771101762435650x
820184781455259
1778420806283x
58040269691871
68173706570160x
17261810543742x
x

Create additional zeros

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

18435502947044
010091563924070
772001762435650
73093872364350
1787420806283
4903117060962
68263706570160
17351810543742

Cover all zeros with a minimum number of lines

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

18435502947044x
010091563924070x
772001762435650x
73093872364350
1787420806283x
4903117060962
68263706570160x
17351810543742
xx

Create additional zeros

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

18445503047044
010191564024070
772101763435650
72083772354249
1788420906283
4803016059861
68273706670160
16351700533641

Cover all zeros with a minimum number of lines

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

18445503047044
010191564024070x
772101763435650x
72083772354249
1788420906283x
4803016059861
68273706670160x
16351700533641
xxx

Create additional zeros

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

14445103006640
010591604424070
772502167435650
68043772313845
17924241306283
4402616055457
68313747070160
12351300493237

Cover all zeros with a minimum number of lines

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

14445103006640
010591604424070x
772502167435650x
68043772313845
17924241306283
4402616055457
68313747070160x
12351300493237
xxxx

Create additional zeros

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

10444703006236
010991644828070
772902571475650
64003772313441
13923841305879
4002216055053
68353787474160
835900492833

Cover all zeros with a minimum number of lines

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

10444703006236x
010991644828070x
772902571475650x
64003772313441x
13923841305879x
4002216055053x
68353787474160x
835900492833x

The optimal assignment

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

10444703006236
010991644828070
772902571475650
64003772313441
13923841305879
4002216055053
68353787474160
835900492833

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

4758792453369470
119797624538678
9322112873626763
958265589616069
258145311116588
8522624831994095
75193926780184
4650422524866168

The total minimum cost is 133.


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