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:

29679884221
56388813138026
62566937137154
68711583577781
34504344846615
61648979576059
74313543955178

Subtract row minima

We subtract the row minimum from each row:

09477862019(-2)
432575006713(-13)
4943562405841(-13)
5356068426266(-15)
1935282969510(-15)
473222032(-57)
430412642047(-31)

Subtract column minima

Because each column contains a zero, subtracting column minima has no effect.

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

09477862019  x
432575006713  x
4943562405841
5356068426266  x
1935282969510  x
473222032
430412642047  x
x

Create additional zeros

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

09477864019
432575026713
4741542205639
5356068446266
1935282971510
253020010
430412662047

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

09477864019  x
432575026713  x
4741542205639
5356068446266  x
1935282971510
253020010
430412662047  x
xx

Create additional zeros

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

09477865020
432575036714
4640532105539
5356068456267
1834272871500
142919000
430412672048

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

09477865020  x
432575036714  x
4640532105539  x
5356068456267  x
1834272871500  x
142919000  x
430412672048  x

The optimal assignment

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

09477865020
432575036714
4640532105539
5356068456267
1834272871500
142919000
430412672048

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

29679884221
56388813138026
62566937137154
68711583577781
34504344846615
61648979576059
74313543955178

The optimal value equals 149.