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:

87772798648877105630
329773436494589088
137320882888048286
64861442197024516515
6965131185249621983
6978601045722404523
3676222443787511812
5417679363162169177
4457629985895789256
1581698950294491568

Subtract row minima

We subtract the row minimum from each row:

7767178854786704620(-10)
289369392450548684(-4)
76714276827442220(-6)
50720285561037511(-14)
666210882219318950(-3)
627153338015333816(-7)
28681416357067304(-8)
5316669262061159076(-1)
3851023925289728650(-6)
1177658546250451164(-4)

Subtract column minima

We subtract the column minimum from each column:

7051178652786704620
217769370450548684
05114074827442220
43560263561037511
594610680219318950
555553136015333816
21521414337067304
460669060061159076
3135021905289728650
461658344250451164
(-7)(-16)(-2)(-2)

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

7051178652786704620  x
217769370450548684  x
05114074827442220  x
43560263561037511
594610680219318950  x
555553136015333816  x
21521414337067304  x
460669060061159076  x
3135021905289728650
461658344250451164  x
x

Create additional zeros

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

7051188652786704620
217770370450548684
05115074827442220
4255025255936500
594611680219318950
555554136015333816
21521514337067304
460679060061159076
3034020895188718549
461668344250451164

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

7051188652786704620  x
217770370450548684  x
05115074827442220  x
4255025255936500
594611680219318950
555554136015333816  x
21521514337067304  x
460679060061159076  x
3034020895188718549
461668344250451164  x
xx

Create additional zeros

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

7051208652786704622
217772370450548686
05117074827442222
4053023053734480
574411478199116930
555556136015333818
21521714337067306
460699060061159078
2832018874986698349
461688344250451166

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

7051208652786704622  x
217772370450548686
05117074827442222  x
4053023053734480
574411478199116930
555556136015333818  x
21521714337067306  x
460699060061159078  x
2832018874986698349
461688344250451166
xxxx

Create additional zeros

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

7051248656787104626
177372330410508286
05121078827842226
3649019049730440
534011078159112890
555560140019333822
215221143770713010
460739064065159082
2428014874586657949
05768794421041766

Cover all zeros with a minimum number of lines

There are 10 lines required to cover all zeros:

7051248656787104626  x
177372330410508286  x
05121078827842226  x
3649019049730440  x
534011078159112890  x
555560140019333822  x
215221143770713010  x
460739064065159082  x
2428014874586657949  x
05768794421041766  x

The optimal assignment

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

7051248656787104626
177372330410508286
05121078827842226
3649019049730440
534011078159112890
555560140019333822
215221143770713010
460739064065159082
2428014874586657949
05768794421041766

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

87772798648877105630
329773436494589088
137320882888048286
64861442197024516515
6965131185249621983
6978601045722404523
3676222443787511812
5417679363162169177
4457629985895789256
1581698950294491568

The optimal value equals 97.