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:

726237855832488
218812539641867
842991822485277
212743822459281
635288353227393
4065254092583688
479124270841219
8699406386599021

Subtract row minima

We subtract the row minimum from each row:

695934825502185(-3)
14815468934790(-7)
820971620465075(-2)
192541802257079(-2)
604985322924360(-3)
154001567331163(-25)
458904068821017(-2)
657819426538690(-21)

Subtract column minima

We subtract the column minimum from each column:

555934673502185
0815316934790
6809710465075
5254165257079
46498517924360
1400047331163
318902548821017
517819274538690
(-14)(-15)(-20)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

555934673502185  x
0815316934790  x
6809710465075  x
5254165257079  x
46498517924360
1400047331163  x
318902548821017  x
517819274538690
x

Create additional zeros

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

555934673502194
0815316934799
6809710465084
5254165257088
3740768015270
1400047331172
318902548821026
426910183629600

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

555934673502194  x
0815316934799  x
6809710465084  x
5254165257088  x
3740768015270  x
1400047331172  x
318902548821026  x
426910183629600  x

The optimal assignment

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

555934673502194
0815316934799
6809710465084
5254165257088
3740768015270
1400047331172
318902548821026
426910183629600

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

726237855832488
218812539641867
842991822485277
212743822459281
635288353227393
4065254092583688
479124270841219
8699406386599021

The optimal value equals 123.