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:

82917098517357767
129768466579469987
75493339310446718
228123515441886066
764795773270529118
58259533983553774
7156291813881830
801286201163488140
891185253879675

Subtract row minima

We subtract the row minimum from each row:

77866593466807262(-5)
08556345367348775(-12)
0478626863376011(-7)
0591293219663844(-22)
58297759145234730(-18)
55229203680523471(-3)
7055281703771729(-1)
691759052377029(-11)
588154920849372(-3)

Subtract column minima

We subtract the column minimum from each column:

77856493466805562
08455345367347075
0468526863374311
0580293219662144
58287659145234560
55219103680521771
705427170377029
690749052375329
587144920847672
(-1)(-1)(-17)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

77856493466805562  x
08455345367347075
0468526863374311
0580293219662144  x
58287659145234560  x
55219103680521771  x
705427170377029  x
690749052375329  x
587144920847672  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:

80856493466805562
08152315064316772
043822383034408
3580293219662144
61287659145234560
58219103680521771
735427170377029
720749052375329
887144920847672

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

80856493466805562  x
08152315064316772
043822383034408
3580293219662144  x
61287659145234560  x
58219103680521771  x
735427170377029  x
720749052375329  x
887144920847672
xx

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:

82856493467005562
07950294864296570
041802181032386
5580293221662144
63287659145434560
60219103682521771
755427170397029
740749054375329
885124700827470

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

82856493467005562  x
07950294864296570  x
041802181032386  x
5580293221662144  x
63287659145434560  x
60219103682521771  x
755427170397029  x
740749054375329  x
885124700827470  x

The optimal assignment

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

82856493467005562
07950294864296570
041802181032386
5580293221662144
63287659145434560
60219103682521771
755427170397029
740749054375329
885124700827470

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

82917098517357767
129768466579469987
75493339310446718
228123515441886066
764795773270529118
58259533983553774
7156291813881830
801286201163488140
891185253879675

The optimal value equals 106.