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.

4535885941
53224288
469969655
928684443
8094471940

Subtract row minima

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

10053246(-35)
45143400(-8)
409309049(-6)
888280039(-4)
617528021(-19)

Subtract column minima

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

0053246
35143400
309309049
788280039
517528021
(-10)

Cover all zeros with a minimum number of lines

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

0053246x
35143400x
309309049x
788280039
517528021
x

Create additional zeros

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

0053456
351434210
3093011149
576159018
3054700

Cover all zeros with a minimum number of lines

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

0053456x
351434210
3093011149x
576159018
3054700
xx

Create additional zeros

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

00535213
28727210
3093011856
505452018
2347000

Cover all zeros with a minimum number of lines

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

00535213x
28727210
3093011856
505452018
2347000
xxx

Create additional zeros

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

00605920
21027210
2386011856
434752018
1640000

Cover all zeros with a minimum number of lines

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

00605920x
21027210x
2386011856x
434752018x
1640000x

The optimal assignment

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

00605920
21027210
2386011856
434752018
1640000

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

4535885941
53224288
469969655
928684443
8094471940

The total minimum cost is 117.


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