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:

87682362878135
5861606477139311
1552348450139792
75253949838470
1135341668237617
974593944897960
75933155508318
13802985587586

Subtract row minima

We subtract the row minimum from each row:

85660342657933(-2)
47504953662820(-11)
23921713708479(-13)
71213545794066(-4)
0242355712656(-11)
883684853907051(-9)
74923054498207(-1)
11780965385564(-2)

Subtract column minima

We subtract the column minimum from each column:

8545029057933
47294948402820
21821661108479
7103540534066
032303112656
881584801307051
74713049238207
11570912785564
(-21)(-5)(-26)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

8545029057933  x
47294948402820  x
21821661108479
7103540534066  x
032303112656  x
881584801307051
74713049238207  x
11570912785564  x
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:

8545029077933
47294948404820
0161964908277
7103540536066
032303114656
861382781106849
74713049238407
11570912787564

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

8545029077933  x
47294948404820  x
0161964908277  x
7103540536066  x
032303114656  x
861382781106849  x
74713049238407  x
11570912787564  x

The optimal assignment

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

8545029077933
47294948404820
0161964908277
7103540536066
032303114656
861382781106849
74713049238407
11570912787564

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

87682362878135
5861606477139311
1552348450139792
75253949838470
1135341668237617
974593944897960
75933155508318
13802985587586

The optimal value equals 107.