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:

295692162039993
9116205995792329
857829541531591
445078159844923
378645406294450
383067876375974
5046525926463962
6021401458649049

Subtract row minima

We subtract the row minimum from each row:

20478371130084(-9)
7504437963713(-16)
807324491026086(-5)
35416968935014(-9)
318039340233844(-6)
302259068295166(-8)
242026330201336(-26)
46726044507635(-14)

Subtract column minima

We subtract the column minimum from each column:

0477971110071
550043794370
60732049106073
1541656891501
11803534033831
10225506895153
4202233001323
26722044307622
(-20)(-4)(-20)(-13)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

0477971110071  x
550043794370  x
60732049106073
1541656891501
11803534033831  x
10225506895153
4202233001323  x
26722044307622
xx

Create additional zeros

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

0477981110171
550044794380
5972194995072
1440646881400
11803535033931
9215406785152
4202234001423
25621043297621

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

0477981110171  x
550044794380  x
5972194995072  x
1440646881400  x
11803535033931  x
9215406785152
4202234001423  x
25621043297621
x

Create additional zeros

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

04779141110171
550050794380
5972195595072
14406412881400
11803541033931
3154806124546
4202240001423
19015037237015

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

04779141110171  x
550050794380  x
5972195595072  x
14406412881400  x
11803541033931  x
3154806124546  x
4202240001423  x
19015037237015  x

The optimal assignment

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

04779141110171
550050794380
5972195595072
14406412881400
11803541033931
3154806124546
4202240001423
19015037237015

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

295692162039993
9116205995792329
857829541531591
445078159844923
378645406294450
383067876375974
5046525926463962
6021401458649049

The optimal value equals 158.