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.

21970167566399638
647531892862515013
52463757991628763
699291558130691140
634876334030844295
40945451932987887
592024231284345
273895217729651495
157242231446152586

Subtract row minima

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

01768147364379436(-2)
51621876154938370(-13)
4539305092921056(-7)
58818044701958029(-11)
3318463100541265(-30)
33874744862280810(-7)
581923220274234(-1)
1324817631551081(-14)
15828903211172(-14)

Subtract column minima

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

0050117364369436
5145073154937370
4522124792920056
58646241701957029
331280100531265
33702941862279810
5825190274134
137634631550081
14110603201172
(-17)(-18)(-3)(-1)

Cover all zeros with a minimum number of lines

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

0050117364369436x
5145073154937370x
4522124792920056
58646241701957029
331280100531265x
33702941862279810x
5825190274134x
137634631550081
14110603201172x
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.

0050117364369836
5145073154937410
411884388516052
54605837661553025
331280100531665
33702941862279850
5825190274174
93590591146077
14110603201572

Cover all zeros with a minimum number of lines

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

0050117364369836x
5145073154937410x
411884388516052
54605837661553025
331280100531665x
33702941862279850x
5825190274174x
93590591146077x
14110603201572x
x

Create additional zeros

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

00501173643610336
5145073154937460
361333883011047
49555332611048020
331280100532165
33702941862279900
58251902741124
93590591146577
14110603202072

Cover all zeros with a minimum number of lines

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

00501173643610336x
5145073154937460x
361333883011047
49555332611048020
331280100532165
33702941862279900x
58251902741124x
93590591146577
14110603202072x
xxx

Create additional zeros

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

00501273653610436
5145074155037470
351223882010046
48545232601047019
32027090522164
33702942862379910
58252002841134
82580581145576
14110703302172

Cover all zeros with a minimum number of lines

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

00501273653610436x
5145074155037470x
351223882010046x
48545232601047019x
32027090522164x
33702942862379910x
58252002841134x
82580581145576x
14110703302172x

The optimal assignment

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

00501273653610436
5145074155037470
351223882010046
48545232601047019
32027090522164
33702942862379910
58252002841134
82580581145576
14110703302172

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

21970167566399638
647531892862515013
52463757991628763
699291558130691140
634876334030844295
40945451932987887
592024231284345
273895217729651495
157242231446152586

The total minimum cost is 152.


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