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:

43073083108752
863598438216114
8749789522418549
9675683336917045
9161214877566258
4028308072296512
56917101099219
10873129862128

Subtract row minima

We subtract the row minimum from each row:

0263267968348(-4)
82319439781270(-4)
652756730196327(-22)
63423503583712(-33)
704002756354137(-21)
281618686017530(-12)
498403328512(-7)
9863028851027(-1)

Subtract column minima

We subtract the column minimum from each column:

0103267958348
82159439781170
651156730186327
63263503573712
702402756344137
28018686016530
496803318512
9703028850027
(-16)(-1)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

0103267958348  x
82159439781170  x
651156730186327  x
63263503573712  x
702402756344137
28018686016530  x
496803318512
9703028850027  x
x

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:

0104267958348
82159539781170
651157730186327
63263603573712
692302655334036
28019686016530
486702208411
9703128850027

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

0104267958348  x
82159539781170  x
651157730186327  x
63263603573712  x
692302655334036  x
28019686016530  x
486702208411  x
9703128850027  x

The optimal assignment

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

0104267958348
82159539781170
651157730186327
63263603573712
692302655334036
28019686016530
486702208411
9703128850027

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

43073083108752
863598438216114
8749789522418549
9675683336917045
9161214877566258
4028308072296512
56917101099219
10873129862128

The optimal value equals 122.