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:

53271359108581
349463549959
6866603977994
76504094261453
52777618287490
32376613408541
5111634712843

Subtract row minima

We subtract the row minimum from each row:

431734907571(-10)
046160519656(-3)
6159533207287(-7)
6236268012039(-14)
3459580105672(-18)
1924530277228(-13)
5010624602742(-1)

Subtract column minima

We subtract the column minimum from each column:

43724907543
036060519628
6149523207259
6226258012011
3449570105644
191452027720
500614602714
(-10)(-1)(-28)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

43724907543
036060519628  x
6149523207259
6226258012011  x
3449570105644  x
191452027720  x
500614602714  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:

41504707341
036060539628
5947503007057
6226258014011
3449570125644
191452029720
500614622714

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

41504707341  x
036060539628  x
5947503007057  x
6226258014011  x
3449570125644  x
191452029720  x
500614622714  x

The optimal assignment

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

41504707341
036060539628
5947503007057
6226258014011
3449570125644
191452029720
500614622714

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

53271359108581
349463549959
6866603977994
76504094261453
52777618287490
32376613408541
5111634712843

The optimal value equals 107.