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.

8435585212911315
9855732181467975
2325534751981191
55714997264297
1349443046301720
8731701529817468
4467606769264092
257691495854437

Subtract row minima

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

7223464007913(-12)
773452060255854(-21)
121442364087080(-11)
53694795242095(-2)
0363117331747(-13)
721655014665953(-15)
184134414301466(-26)
207186445303932(-5)

Subtract column minima

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

729154007910
772021060255851
12011364087077
53551695242092
022017331744
72224014665950
18273414301463
205755445303929
(-14)(-31)(-3)

Cover all zeros with a minimum number of lines

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

729154007910x
772021060255851
12011364087077x
53551695242092x
022017331744x
72224014665950
18273414301463
205755445303929
xx

Create additional zeros

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

729154208110
751819058255649
12011384089077
53551697244092
022019331944
70022012665748
16251414101261
185553445103727

Cover all zeros with a minimum number of lines

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

729154208110x
751819058255649
12011384089077
53551697244092
022019331944x
70022012665748
16251414101261
185553445103727
xxxx

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.

7210154308220
741818057255648
11010383989076
52551597234091
023020332054
69021011665747
15250414001260
175552445003726

Cover all zeros with a minimum number of lines

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

7210154308220x
741818057255648
11010383989076
52551597234091
023020332054x
69021011665747
15250414001260x
175552445003726x
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.

7214154708260
701814053215644
706383585072
48551197190087
027024332094
6501707625743
15290454001660
175952485004126

Cover all zeros with a minimum number of lines

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

7214154708260x
701814053215644
706383585072
48551197190087
027024332094x
6501707625743
15290454001660x
175952485004126
xxxx

Create additional zeros

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

72201553088120
64188047215638
100382985066
4255597130081
0330303326154
5901101625737
15350514062260
115946484404120

Cover all zeros with a minimum number of lines

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

72201553088120x
64188047215638
100382985066
4255597130081
0330303326154x
5901101625737
15350514062260
115946484404120
xxxxx

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.

72211654089130
63188046215637
000382885065
4155597120080
0341313327164
5801100625736
14350513962259
105946484304119

Cover all zeros with a minimum number of lines

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

72211654089130x
63188046215637x
000382885065x
4155597120080x
0341313327164x
5801100625736x
14350513962259x
105946484304119x

The optimal assignment

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

72211654089130
63188046215637
000382885065
4155597120080
0341313327164
5801100625736
14350513962259
105946484304119

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

8435585212911315
9855732181467975
2325534751981191
55714997264297
1349443046301720
8731701529817468
4467606769264092
257691495854437

The total minimum cost is 170.


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