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

Don't show the steps of the Hungarian algorithm
Maximize the total cost

This is the original cost matrix:

601268947869742953
321150963723287221
843942206941456289
532464334469149282
41194799075541513
64426980225756416
3513307337544642
92513277698477058
577948433986631520

Subtract row minima

We subtract the row minimum from each row:

48056826657621741(-12)
21039852612176110(-11)
64192204921254269(-20)
39105019305507868(-14)
079075867150119(-4)
59376475175205911(-5)
0210277034514339(-3)
89480247395446755(-3)
4264332824714805(-15)

Subtract column minima

We subtract the column minimum from each column:

48056824945621736
21039859017615
6419220329254264
39105019134307863
079075695950114
593764750400596
0210275322514334
89480245683446750
426433287594800
(-17)(-12)(-5)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

48056824945621736  x
21039859017615  x
6419220329254264  x
39105019134307863  x
079075695950114
593764750400596  x
0210275322514334
89480245683446750  x
426433287594800  x
x

Create additional zeros

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

50056824945621736
23039859017615
6619220329254264
41105019134307863
05887367574892
613764750400596
008255120494132
91480245683446750
446433287594800

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

50056824945621736
23039859017615  x
6619220329254264  x
41105019134307863  x
05887367574892
613764750400596  x
008255120494132
91480245683446750  x
446433287594800  x
xx

Create additional zeros

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

50054804743601534
25239859017615
6821220329254264
43125019134307863
05867165554670
633964750400596
006234918473930
93500245683446750
466633287594800

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

50054804743601534  x
25239859017615  x
6821220329254264  x
43125019134307863  x
05867165554670  x
633964750400596  x
006234918473930  x
93500245683446750  x
466633287594800  x

The optimal assignment

Because there are 9 lines required, the zeros cover an optimal assignment:

50054804743601534
25239859017615
6821220329254264
43125019134307863
05867165554670
633964750400596
006234918473930
93500245683446750
466633287594800

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

601268947869742953
321150963723287221
843942206941456289
532464334469149282
41194799075541513
64426980225756416
3513307337544642
92513277698477058
577948433986631520

The optimal value equals 125.