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.

25513237958
82793764329
669245171156
697579296528
18266384863
72024414269

Subtract row minima

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

2008187453(-5)
79760734026(-3)
5581346045(-11)
4147511370(-28)
12200324257(-6)
01317343562(-7)

Subtract column minima

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

2008177453
79760724026
5581345045
4147510370
12200314257
01317333562
(-1)

Cover all zeros with a minimum number of lines

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

2008177453x
79760724026
5581345045x
4147510370x
12200314257
01317333562x
x

Create additional zeros

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

20020177453
67640602814
5581465045
4147630370
080193045
01329333562

Cover all zeros with a minimum number of lines

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

20020177453x
67640602814
5581465045x
4147630370x
080193045
01329333562
xx

Create additional zeros

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

28028177453
6756052206
6381545045
4947710370
000112237
0529252754

Cover all zeros with a minimum number of lines

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

28028177453
6756052206
6381545045x
4947710370x
000112237
0529252754
xxx

Create additional zeros

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

28028116847
6756046140
6987605045
5553770370
00051631
0529192148

Cover all zeros with a minimum number of lines

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

28028116847x
6756046140x
6987605045x
5553770370x
00051631x
0529192148x

The optimal assignment

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

28028116847
6756046140
6987605045
5553770370
00051631
0529192148

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

25513237958
82793764329
669245171156
697579296528
18266384863
72024414269

The total minimum cost is 87.


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