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:

662897177320599
40163658651346
5596708110631845
4917587935332252
3360345716135067
734088839368263
317467616859065
549766898269885

Subtract row minima

We subtract the row minimum from each row:

612392126815094(-5)
39153557640245(-1)
45866071053835(-10)
32041621816535(-17)
20472144303754(-13)
703785809065230(-3)
266962566308560(-5)
489160837609279(-6)

Subtract column minima

We subtract the column minimum from each column:

41237106815094
19151445640245
25863959053835
12020501816535
047032303754
503764689065230
66941446308560
289139717609279
(-20)(-21)(-12)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

41237106815094  x
19151445640245
25863959053835  x
12020501816535  x
047032303754  x
503764689065230  x
66941446308560
289139717609279
x

Create additional zeros

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

41237106817094
17131243620043
25863959055835
12020501818535
047032323754
503764689067230
46739426108358
268937697409077

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

41237106817094  x
17131243620043  x
25863959055835  x
12020501818535  x
047032323754  x
503764689067230  x
46739426108358
268937697409077
x

Create additional zeros

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

41237106821094
17131243624043
25863959059835
12020501822535
047032363754
503764689071230
06335385707954
228533657008673

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

41237106821094  x
17131243624043  x
25863959059835  x
12020501822535  x
047032363754  x
503764689071230  x
06335385707954  x
228533657008673  x

The optimal assignment

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

41237106821094
17131243624043
25863959059835
12020501822535
047032363754
503764689071230
06335385707954
228533657008673

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

662897177320599
40163658651346
5596708110631845
4917587935332252
3360345716135067
734088839368263
317467616859065
549766898269885

The optimal value equals 121.