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:

37749848676185
84615828541275
4877327167215
94963072937130
2765155818790
4302741383549
9876917848222

Subtract row minima

We subtract the row minimum from each row:

0376111302448(-37)
7249461642063(-12)
427126650669(-6)
646604263410(-30)
2104549758184(-6)
0262337343145(-4)
078608757313(-9)

Subtract column minima

We subtract the column minimum from each column:

037613302448
724946842063
427126570669
646603463410
2104541758184
0262329343145
078600757313
(-8)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

037613302448
724946842063  x
427126570669  x
646603463410  x
2104541758184  x
0262329343145
078600757313  x
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:

034580272145
754946842063
457126570669
676603463410
2404541758184
0232026312842
378600757313

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

034580272145
754946842063  x
457126570669  x
676603463410  x
2404541758184  x
0232026312842
378600757313
xx

Create additional zeros

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

02145014832
8849462142063
587126700669
806604763410
3704554758184
010726181529
36547062600

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

02145014832  x
8849462142063  x
587126700669  x
806604763410  x
3704554758184  x
010726181529  x
36547062600  x

The optimal assignment

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

02145014832
8849462142063
587126700669
806604763410
3704554758184
010726181529
36547062600

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

37749848676185
84615828541275
4877327167215
94963072937130
2765155818790
4302741383549
9876917848222

The optimal value equals 128.