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:

75858691720521495
12441271620971046
40729773237381728
47547763157567971
47181076567175523
689316272550277048
894115166275925353
3969843337091725
69285112446245522

Subtract row minima

We subtract the row minimum from each row:

6878798401345788(-7)
1143026151996945(-1)
32648965156573640(-8)
41487102551507365(-6)
4011369496404816(-7)
5277011934115432(-16)
7426014760773838(-15)
3666810306788422(-3)
0867951840184916(-6)

Subtract column minima

We subtract the column minimum from each column:

686779840045388
113202615696545
32538965155273600
41377102538506965
400369495104416
5266011921115032
7415014747773438
3655810305488022
0757951827184516
(-11)(-13)(-4)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

686779840045388  x
113202615696545
32538965155273600  x
41377102538506965  x
400369495104416  x
5266011921115032
7415014747773438
3655810305488022  x
0757951827184516  x
x

Create additional zeros

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

686780840045388
103102514595444
32539065155273600
41377202538506965
400469495104416
5165010820104931
7314004646763337
3655820305488022
0758051827184516

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

686780840045388  x
103102514595444
32539065155273600  x
41377202538506965
400469495104416  x
5165010820104931
7314004646763337
3655820305488022  x
0758051827184516  x
xx

Create additional zeros

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

686784880045388
62702510191040
32539469155273600
37337202134466561
400873495104416
476101041664527
6910004242722933
3655864305488022
0758491827184516

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

686784880045388  x
62702510191040
32539469155273600  x
37337202134466561
400873495104416  x
476101041664527
6910004242722933
3655864305488022
0758491827184516  x
xxx

Create additional zeros

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

686785890045488
5260259090039
32539570155273610
36327202033456560
400974495104516
466001031554526
689004141712932
3554864295387021
07585101827184616

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

686785890045488  x
5260259090039  x
32539570155273610  x
36327202033456560
400974495104516  x
466001031554526
689004141712932
3554864295387021  x
07585101827184616  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:

686788920045488
5263289090039
32539873155273610
33297201730426257
4001277495104516
435701001224223
656003838682629
3554897295387021
07588131827184616

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

686788920045488
5263289090039
32539873155273610  x
33297201730426257
4001277495104516  x
435701001224223
656003838682629
3554897295387021
07588131827184616  x
xxxxx

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:

666588920043486
3243289088037
325310075175473630
31277201730406255
4001479515304716
415501001204221
634003838662627
3352897295385019
07590152029184816

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

666588920043486  x
3243289088037  x
325310075175473630  x
31277201730406255  x
4001479515304716  x
415501001204221  x
634003838662627  x
3352897295385019  x
07590152029184816  x

The optimal assignment

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

666588920043486
3243289088037
325310075175473630
31277201730406255
4001479515304716
415501001204221
634003838662627
3352897295385019
07590152029184816

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

75858691720521495
12441271620971046
40729773237381728
47547763157567971
47181076567175523
689316272550277048
894115166275925353
3969843337091725
69285112446245522

The optimal value equals 114.