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:

81252225105728822689
31498223896692789025
99198636317686511688
42616090231336915742
6854735782098688922
2057269089235958760
1924495473685787865
13908992495555962449
41153489424728437183
5148984967955726506

Subtract row minima

We subtract the row minimum from each row:

7115121504718721679(-10)
82659066436955672(-23)
833702015607035072(-16)
2948477710023784429(-13)
6147028711391618215(-7)
1350198382165251053(-7)
1419444968630737360(-5)
0777679364242831136(-13)
2601974273213285668(-15)
4542924361895120440(-6)

Subtract column minima

We subtract the column minimum from each column:

7115121504718521679
82659066436935672
833702015607015072
2948477710023584429
6147028711391418215
1350198382165231053
1419444968630537360
0777679364242631136
260197427321385668
454292436189510440
(-20)

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

7115121504718521679  x
82659066436935672  x
833702015607015072
2948477710023584429  x
6147028711391418215  x
1350198382165231053
1419444968630537360  x
0777679364242631136  x
260197427321385668  x
454292436189510440  x
x

Create additional zeros

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

7115121504718521979
82659066436935702
800671712576712069
2948477710023584729
6147028711391418515
1047168079134928050
1419444968630537660
0777679364242631436
260197427321385968
454292436189510470

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

7115121504718521979  x
82659066436935702  x
800671712576712069
2948477710023584729  x
6147028711391418515  x
1047168079134928050
1419444968630537660  x
0777679364242631436  x
260197427321385968
454292436189510470  x
xx

Create additional zeros

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

7123121504718522779
83459066436935782
720599449594061
2956477710023585529
6155028711391419315
2478727154120042
1427444968630538460
0857679364242632236
18011661924505960
455092436189510550

Cover all zeros with a minimum number of lines

There are 10 lines required to cover all zeros:

7123121504718522779  x
83459066436935782  x
720599449594061  x
2956477710023585529  x
6155028711391419315  x
2478727154120042  x
1427444968630538460  x
0857679364242632236  x
18011661924505960  x
455092436189510550  x

The optimal assignment

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

7123121504718522779
83459066436935782
720599449594061
2956477710023585529
6155028711391419315
2478727154120042
1427444968630538460
0857679364242632236
18011661924505960
455092436189510550

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

81252225105728822689
31498223896692789025
99198636317686511688
42616090231336915742
6854735782098688922
2057269089235958760
1924495473685787865
13908992495555962449
41153489424728437183
5148984967955726506

The optimal value equals 146.