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.

4889946540
475682605
24329575
1888905336
136057733

Subtract row minima

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

84954250(-40)
425177550(-5)
19274070(-5)
070723518(-18)
105754700(-3)

Subtract column minima

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

82250250
422473550
1900070
043683518
103050700
(-27)(-4)

Cover all zeros with a minimum number of lines

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

82250250
422473550
1900070x
043683518x
103050700
x

Create additional zeros

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

01442170
341665470
1900078
043683526
22242620

Cover all zeros with a minimum number of lines

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

01442170
341665470
1900078x
043683526
22242620
xx

Create additional zeros

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

002830
34251330
3300092
029542126
2828480

Cover all zeros with a minimum number of lines

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

002830x
34251330
3300092x
029542126x
2828480
x

Create additional zeros

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

002832
32049310
3300094
029542128
0626460

Cover all zeros with a minimum number of lines

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

002832
32049310
3300094x
029542128
0626460
xxx

Create additional zeros

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

002502
32046280
3630097
029511828
0623430

Cover all zeros with a minimum number of lines

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

002502x
32046280x
3630097x
029511828x
0623430x

The optimal assignment

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

002502
32046280
3630097
029511828
0623430

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

4889946540
475682605
24329575
1888905336
136057733

The total minimum cost is 151.


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