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:

5333639357528413
968996418495537
2538986263834083
9487321666204031
6081376334305183
9664816390971346
593326738564927
203869506086794

Subtract row minima

We subtract the row minimum from each row:

402050804439710(-13)
87800559404628(-9)
013733738581558(-25)
78711605042415(-16)
3051733402153(-30)
835168507784033(-13)
512518650484119(-8)
163465465682750(-4)

Subtract column minima

We subtract the column minimum from each column:

40750804439710
87670559404628
00733738581558
78581605042415
3038733402153
833868507784033
511218650484119
162165465682750
(-13)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

40750804439710
87670559404628  x
00733738581558  x
78581605042415  x
3038733402153  x
833868507784033  x
511218650484119  x
162165465682750
x

Create additional zeros

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

33043733732640
87670559404635
00733738581565
78581605042422
3038733402160
833868507784040
511218650484126
91458394975680

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

33043733732640  x
87670559404635  x
00733738581565  x
78581605042422  x
3038733402160  x
833868507784040  x
511218650484126  x
91458394975680  x

The optimal assignment

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

33043733732640
87670559404635
00733738581565
78581605042422
3038733402160
833868507784040
511218650484126
91458394975680

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

5333639357528413
968996418495537
2538986263834083
9487321666204031
6081376334305183
9664816390971346
593326738564927
203869506086794

The optimal value equals 138.