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.

1531932744839
7943362856156
1432682847942
6683025795167
88163531238860
57694758673929
2738604526795

Subtract row minima

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

622023653930(-9)
7640059825853(-3)
1028642407538(-4)
0622419734561(-6)
720191577244(-16)
2840182938100(-29)
2031533819088(-7)

Subtract column minima

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

62208653930
7640044825853
102864907538
062244734561
72019077244
2840181438100
2031532319088
(-15)

Cover all zeros with a minimum number of lines

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

62208653930
7640044825853
102864907538x
062244734561x
72019077244x
2840181438100x
2031532319088x
x

Create additional zeros

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

01602593324
7034038765247
102870907538
062304734561
72025077244
2840241438100
2031592319088

Cover all zeros with a minimum number of lines

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

01602593324
7034038765247
102870907538x
062304734561
72025077244x
2840241438100x
2031592319088x
xx

Create additional zeros

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

01400573122
7032036745045
122872907538
060302714359
74027077244
3040261438100
2231612319088

Cover all zeros with a minimum number of lines

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

01400573122x
7032036745045x
122872907538x
060302714359x
74027077244x
3040261438100x
2231612319088x

The optimal assignment

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

01400573122
7032036745045
122872907538
060302714359
74027077244
3040261438100
2231612319088

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

1531932744839
7943362856156
1432682847942
6683025795167
88163531238860
57694758673929
2738604526795

The total minimum cost is 97.


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