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:

772370558643825683
66304190378727857
3012433337385359
917892171694806199
80142710602341539
13289165301978944
9574553597422785
58822129573338270
20906668210384323

Subtract row minima

We subtract the row minimum from each row:

54047326320593360(-23)
59233483308020780(-7)
257382832334804(-5)
7562761078644583(-16)
715181511432440(-9)
6218458231208237(-7)
9372533395400763(-2)
0831779068287765(-5)
1484060764323717(-6)

Subtract column minima

We subtract the column minimum from each column:

54047316316593360
59233482307620780
257382732294804
7562760074644583
715180511032440
621845723808237
9372533295360763
0831769064287765
1484059760323717
(-1)(-4)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

54047316316593360  x
59233482307620780  x
257382732294804  x
7562760074644583  x
715180511032440  x
621845723808237
9372533295360763
0831769064287765  x
1484059760323717  x
x

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:

54047316316623360
59233482307623780
257382732295104
7562760074674583
715180511035440
318815420507934
9069502992330730
0831769064317765
1484059760353717

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

54047316316623360  x
59233482307623780
257382732295104  x
7562760074674583  x
715180511035440  x
318815420507934
9069502992330730
0831769064317765  x
1484059760353717  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:

54047316316653363
56203179277323750
257382732295407
7562760074704586
715180511038443
015785117207634
8766472689300700
0831769064347768
1484059760383720

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

54047316316653363  x
56203179277323750
257382732295407  x
7562760074704586  x
715180511038443  x
015785117207634
8766472689300700
0831769064347768
1484059760383720  x
xxx

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:

56047316316673365
56182977257123730
277382732295609
7762760074724588
735180511040445
013764915007434
8764452487280680
0811548862347568
1684059760403722

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

56047316316673365  x
56182977257123730  x
277382732295609  x
7762760074724588  x
735180511040445  x
013764915007434  x
8764452487280680  x
0811548862347568  x
1684059760403722  x

The optimal assignment

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

56047316316673365
56182977257123730
277382732295609
7762760074724588
735180511040445
013764915007434
8764452487280680
0811548862347568
1684059760403722

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

772370558643825683
66304190378727857
3012433337385359
917892171694806199
80142710602341539
13289165301978944
9574553597422785
58822129573338270
20906668210384323

The optimal value equals 93.