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:

91939680878872
43967367571759
1712507859317
10673312725617
89414929331950
1269156842037
20215371485372

Subtract row minima

We subtract the row minimum from each row:

192124815160(-72)
2679565040042(-17)
149477556014(-3)
05723262467(-10)
7022301014031(-19)
865116401633(-4)
013351283352(-20)

Subtract column minima

We subtract the column minimum from each column:

192013615160
2678454840042
148367356014
05612062467
702119814031
86406201633
002249283352
(-1)(-11)(-2)

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

192013615160  x
2678454840042
148367356014
05612062467  x
702119814031
86406201633  x
002249283352  x
x

Create additional zeros

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

192013615240
1870374032034
6028654806
05612062547
62131106023
86406202433
002249284152

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

192013615240  x
1870374032034
6028654806
05612062547
62131106023
86406202433  x
002249284152
xxxx

Create additional zeros

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

2526131215300
1870314026028
6022654200
0566056541
6213500017
147006803033
001649224146

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

2526131215300  x
1870314026028  x
6022654200  x
0566056541  x
6213500017  x
147006803033  x
001649224146  x

The optimal assignment

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

2526131215300
1870314026028
6022654200
0566056541
6213500017
147006803033
001649224146

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

91939680878872
43967367571759
1712507859317
10673312725617
89414929331950
1269156842037
20215371485372

The optimal value equals 181.