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:

2728818336358
28408830721193
828680551698
22928715579850
43236725834559
33355269833732
306988432235

Subtract row minima

We subtract the row minimum from each row:

2425788033055(-3)
1729771961082(-11)
778175001193(-5)
777720428335(-15)
200442602236(-23)
1320375150(-32)
251937927180(-5)

Subtract column minima

We subtract the column minimum from each column:

2325588033055
1629571961082
768155001193
677520428335
190242602236
030375150
241737927180
(-1)(-20)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

2325588033055
1629571961082
768155001193  x
677520428335  x
190242602236  x
030375150  x
241737927180  x
x

Create additional zeros

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

79426417039
01341345066
768155002793
677520429935
190242603836
0303751210
241737927340

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

79426417039  x
01341345066  x
768155002793  x
677520429935  x
190242603836  x
0303751210  x
241737927340  x

The optimal assignment

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

79426417039
01341345066
768155002793
677520429935
190242603836
0303751210
241737927340

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

2728818336358
28408830721193
828680551698
22928715579850
43236725834559
33355269833732
306988432235

The optimal value equals 131.