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:

24608527725926
9211187408788
4536453325499
15905521917222
34298824119912
74499094356159
7979255526040

Subtract row minima

We subtract the row minimum from each row:

03661348352(-24)
9110086398687(-1)
4132412921095(-4)
07540676577(-15)
231877130881(-11)
3914555902624(-35)
0908548455333(-7)

Subtract column minima

We subtract the column minimum from each column:

02661048351
910083398686
4122412621094
06540376576
23877100880
394555602623
0808545455332
(-10)(-3)(-1)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

02661048351  x
910083398686  x
4122412621094  x
06540376576
23877100880  x
394555602623  x
0808545455332
x

Create additional zeros

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

32661048351
940083398686
4422412621094
06237073543
26877100880
424555602623
0778242425029

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

32661048351
940083398686  x
4422412621094  x
06237073543
26877100880  x
424555602623  x
0778242425029
xx

Create additional zeros

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

32560047340
950084398686
4522412721094
06136072532
27877110880
434555702623
0768142414928

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

32560047340
950084398686  x
4522412721094  x
06136072532
27877110880
434555702623
0768142414928
xxxx

Create additional zeros

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

32156047300
990088438690
4922413125098
05732072492
27473110840
430515702223
0727742414528

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

32156047300  x
990088438690  x
4922413125098  x
05732072492  x
27473110840  x
430515702223  x
0727742414528  x

The optimal assignment

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

32156047300
990088438690
4922413125098
05732072492
27473110840
430515702223
0727742414528

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

24608527725926
9211187408788
4536453325499
15905521917222
34298824119912
74499094356159
7979255526040

The optimal value equals 119.