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:

5223349169657
41102473442192
1581896277350
9061943017252
23591139507951
4073039636441
6967918146961

Subtract row minima

We subtract the row minimum from each row:

4920046139354(-3)
3101463341182(-10)
773088196542(-8)
8859922815050(-2)
1248028396840(-11)
3302332565734(-7)
615983066153(-8)

Subtract column minima

We subtract the column minimum from each column:

422004679320
2401463281148
07308813658
815992289016
54802833686
260233250570
545983006119
(-7)(-6)(-34)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

422004679320
2401463281148  x
07308813658  x
815992289016  x
54802833686
260233250570  x
545983006119  x
x

Create additional zeros

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

371504128815
2401963281148
07358813658
815997289016
04302328631
260283250570
545988006119

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

371504128815
2401963281148  x
07358813658
815997289016  x
04302328631
260283250570  x
545988006119  x
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:

371404018714
2502063281148
07258712647
825998289016
04202227620
270293250570
555989006119

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

371404018714
2502063281148
07258712647
825998289016  x
04202227620
270293250570
555989006119  x
xxxx

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:

371403908614
2502062271048
07258611637
836099289017
04202126610
270293149560
566090006120

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

371403908614  x
2502062271048  x
07258611637  x
836099289017  x
04202126610  x
270293149560  x
566090006120  x

The optimal assignment

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

371403908614
2502062271048
07258611637
836099289017
04202126610
270293149560
566090006120

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

5223349169657
41102473442192
1581896277350
9061943017252
23591139507951
4073039636441
6967918146961

The optimal value equals 103.