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.

174271289879375
82247893576668628
413523191549549598
941335153830247251
2635736357880892
13267449359694314
54361877619542812
719894904355707480
731370878543708460

Subtract row minima

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

073170279778274(-1)
73156902667577719(-9)
262084034398083(-15)
8102222517115938(-13)
2433714337678870(-2)
9227008955653910(-4)
52341675599340790(-2)
28555147012273137(-43)
60057747230577147(-13)

Subtract column minima

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

073070278567074
73156802655467519
262074022287883
81021225505738
2433704336467850
9226908943543710
52341575598129770
2855504700162937
60056747218466947
(-1)(-12)(-11)(-2)

Cover all zeros with a minimum number of lines

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

073070278567074x
73156802655467519
262074022287883x
81021225505738x
2433704336467850
9226908943543710
52341575598129770
2855504700162937x
60056747218466947x
xx

Create additional zeros

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

073079278567083
6465901746376619
2620713022287892
810211125505747
1524614245558760
0136008034452810
4325675507220680
2855505600162946
60056837218466956

Cover all zeros with a minimum number of lines

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

073079278567083x
6465901746376619x
2620713022287892x
810211125505747x
1524614245558760
0136008034452810x
4325675507220680
2855505600162946x
60056837218466956x
x

Create additional zeros

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

073079278567087
6465901746376623
2620713022287896
810211125505751
1120570205154720
0136008034452814
3921271466816640
2855505600162950
60056837218466960

Cover all zeros with a minimum number of lines

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

073079278567087x
6465901746376623
2620713022287896x
810211125505751x
1120570205154720
0136008034452814x
3921271466816640
2855505600162950x
60056837218466960x
xx

Create additional zeros

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

073081278567089
6245701544356423
2620715022287898
810211325505753
918550184952700
0136028034452816
3719071446614620
2855505800162952
60056857218466962

Cover all zeros with a minimum number of lines

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

073081278567089x
6245701544356423x
2620715022287898x
810211325505753x
918550184952700x
0136028034452816x
3719071446614620x
2855505800162952x
60056857218466962x

The optimal assignment

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

073081278567089
6245701544356423
2620715022287898
810211325505753
918550184952700
0136028034452816
3719071446614620
2855505800162952
60056857218466962

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

174271289879375
82247893576668628
413523191549549598
941335153830247251
2635736357880892
13267449359694314
54361877619542812
719894904355707480
731370878543708460

The total minimum cost is 152.


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