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:

6384777243219847
82954890894811
2070651294664649
6737707147705195
1655838238549668
351467642849491
280215413188039
9231281649248846

Subtract row minima

We subtract the row minimum from each row:

426356512207726(-21)
6093468887469(-2)
85853082543437(-12)
300333410331458(-37)
039676622388052(-16)
311063602409087(-4)
078195211167837(-2)
76151203387230(-16)

Subtract column minima

We subtract the column minimum from each column:

426344511206317
6081467887320
85841072542028
3002134033049
039556612386643
311051601407678
0787521166428
7615002385821
(-12)(-10)(-14)(-9)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

426344511206317
6081467887320  x
85841072542028  x
3002134033049  x
039556612386643
311051601407678
0787521166428
7615002385821  x
xx

Create additional zeros

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

426243501106216
7081467888320
95841072552028
3102134034049
038546511386542
31950591307577
0776510166327
7715002395821

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

426243501106216
7081467888320  x
95841072552028  x
3102134034049  x
038546511386542  x
31950591307577
0776510166327  x
7715002395821  x
x

Create additional zeros

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

3353344120537
7081467897320
95841072642028
3102134043049
038546511476542
2204150406668
0776510256327
77150023185821

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

3353344120537  x
7081467897320  x
95841072642028  x
3102134043049  x
038546511476542  x
2204150406668  x
0776510256327  x
77150023185821  x

The optimal assignment

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

3353344120537
7081467897320
95841072642028
3102134043049
038546511476542
2204150406668
0776510256327
77150023185821

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

6384777243219847
82954890894811
2070651294664649
6737707147705195
1655838238549668
351467642849491
280215413188039
9231281649248846

The optimal value equals 166.