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:

113441868168376
232965563033423651
87557519467623446
56656733881974176
553495704996892277
632320867014317823
425763744137789379
142275233312984563
47357852299938676

Subtract row minima

We subtract the row minimum from each row:

83138565135073(-3)
064233710191328(-23)
80480448760552739(-7)
50590673275913570(-6)
33127348277467055(-22)
49967256017649(-14)
520263740415642(-37)
2106311210863351(-12)
44327549269608373(-3)

Subtract column minima

We subtract the column minimum from each column:

82538061135064
004228310191319
80420398360552730
50530622875913561
3367343237467046
49366752017640
514263200415633
24636170863342
44267544229608364
(-6)(-5)(-4)(-9)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

82538061135064  x
004228310191319  x
80420398360552730
50530622875913561
3367343237467046  x
49366752017640  x
514263200415633  x
24636170863342  x
44267544229608364  x
x

Create additional zeros

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

82565061135064
006928310191319
531501256332803
232603514864834
33610043237467046
493336752017640
514533200415633
24906170863342
442610244229608364

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

82565061135064  x
006928310191319  x
531501256332803
232603514864834
33610043237467046
493336752017640  x
514533200415633  x
24906170863342  x
442610244229608364  x
xx

Create additional zeros

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

82566061135164
007028310191419
521401155322702
222503404763833
32510042227366045
493346752017650
514543200415733
24916170863442
442610344229608464

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

82566061135164  x
007028310191419  x
521401155322702
222503404763833
32510042227366045
493346752017650  x
514543200415733
24916170863442
442610344229608464  x
xxxx

Create additional zeros

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

82568063155364
007228512191619
50120955322500
202303204761831
30310040227364043
493366754217670
312543000395731
02914170843440
442610544249808664

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

82568063155364  x
007228512191619  x
50120955322500  x
202303204761831  x
30310040227364043  x
493366754217670  x
312543000395731  x
02914170843440  x
442610544249808664  x

The optimal assignment

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

82568063155364
007228512191619
50120955322500
202303204761831
30310040227364043
493366754217670
312543000395731
02914170843440
442610544249808664

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

113441868168376
232965563033423651
87557519467623446
56656733881974176
553495704996892277
632320867014317823
425763744137789379
142275233312984563
47357852299938676

The optimal value equals 181.