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:

549734639352778558
2835368559999901
10896997818133245
902942507322514923
818325734663451624
91375331432721586
5536348184114677
7690953563903827
869630687354478028

Subtract row minima

We subtract the row minimum from each row:

20630295918435124(-34)
2734358458898890(-1)
8876795797931043(-2)
687202851029271(-22)
656795730472908(-16)
86324826382216081(-5)
5435338083013666(-1)
7387920530873524(-3)
5868240452619520(-28)

Subtract column minima

We subtract the column minimum from each column:

12560292918305124
1927358428885890
0806795497918043
600202821016271
57609570471608
782548268223081
462833805300666
6580920230743524
506124015266520
(-8)(-7)(-30)(-13)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

12560292918305124  x
1927358428885890
0806795497918043  x
600202821016271  x
57609570471608  x
782548268223081  x
462833805300666  x
6580920230743524  x
506124015266520
x

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:

12560292918305126
1725338226683870
0806795497918045
600202821016273
576095704716010
782548268223083
462833805300668
6580920230743526
485903813244500

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

12560292918305126
1725338226683870
0806795497918045  x
600202821016273  x
576095704716010  x
782548268223083  x
462833805300668  x
6580920230743526  x
485903813244500
xx

Create additional zeros

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

8520252514264726
1321337822279830
0807195497918049
600242821016277
5760135704716014
782552268223087
4628378053006612
6580960230743530
44550349200460

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

8520252514264726  x
1321337822279830  x
0807195497918049  x
600242821016277  x
5760135704716014  x
782552268223087  x
4628378053006612  x
6580960230743530  x
44550349200460  x

The optimal assignment

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

8520252514264726
1321337822279830
0807195497918049
600242821016277
5760135704716014
782552268223087
4628378053006612
6580960230743530
44550349200460

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

549734639352778558
2835368559999901
10896997818133245
902942507322514923
818325734663451624
91375331432721586
5536348184114677
7690953563903827
869630687354478028

The optimal value equals 176.