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:

42372873535898955
258395261062891036
94317594044485554
602440137626399032
862621778477294396
499983718265687158
517175263862651624
94995685701969598
448098511924753189

Subtract row minima

We subtract the row minimum from each row:

39069843232868652(-3)
1573851605279026(-10)
87240523337414847(-7)
47112706313267719(-13)
655056635682275(-21)
0503422331619229(-49)
3555591022464908(-16)
88935079641308992(-6)
2561793205561270(-19)

Subtract column minima

We subtract the column minimum from each column:

39069843227868644
1573851604779018
87240523332414839
4711270638267711
655056635182267
0503422331119221
3555591022414900
8893507964808984
2561793200561262
(-5)(-8)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

39069843227868644  x
1573851604779018  x
87240523332414839
4711270638267711  x
655056635182267
0503422331119221  x
3555591022414900  x
8893507964808984  x
2561793200561262  x
x

Create additional zeros

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

39074843227868644
1573901604779018
82190472827364334
4711320638267711
600051584631762
0503922331119221
3555641022414900
8893557964808984
2561843200561262

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

39074843227868644
1573901604779018  x
82190472827364334
4711320638267711  x
600051584631762
0503922331119221  x
3555641022414900  x
8893557964808984  x
2561843200561262  x
xx

Create additional zeros

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

36074812924838341
1576931604779018
79190442524334031
4714350638267711
570048554301459
0534222331119221
3558671022414900
8896587964808984
2564873200561262

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

36074812924838341
1576931604779018  x
79190442524334031
4714350638267711  x
570048554301459
0534222331119221  x
3558671022414900  x
8896587964808984
2564873200561262  x
xxx

Create additional zeros

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

28074732116837533
15841011604787018
71190361716333223
4722430638347711
49004047350651
0615022331127221
3566751022415700
8096587156008176
2572953200641262

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

28074732116837533  x
15841011604787018  x
71190361716333223  x
4722430638347711  x
49004047350651  x
0615022331127221  x
3566751022415700  x
8096587156008176  x
2572953200641262  x

The optimal assignment

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

28074732116837533
15841011604787018
71190361716333223
4722430638347711
49004047350651
0615022331127221
3566751022415700
8096587156008176
2572953200641262

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

42372873535898955
258395261062891036
94317594044485554
602440137626399032
862621778477294396
499983718265687158
517175263862651624
94995685701969598
448098511924753189

The optimal value equals 173.