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:

7592186161929914348
32707827866772377940
90692047709584977819
27405515412631289482
5666879355461429
76643183708945541430
4833428884321445916
85225678614772399164
56261262957956346
52122111551023218746

Subtract row minima

We subtract the row minimum from each row:

668395252830823439(-9)
543510594045105213(-27)
715012851766578590(-19)
1225400261116137967(-15)
5262835311057385(-4)
6250176956753140016(-14)
39243379752353607(-9)
6303456392550176942(-22)
54059242755754144(-2)
42211145013117736(-10)

Subtract column minima

We subtract the column minimum from each column:

618385226830723439
04350033404505213
665002825766568590
7253900111637967
476282551047385
5750166930753130016
34243279492352607
580335613255076942
4905824155744144
3721011901317736
(-5)(-1)(-26)(-10)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

618385226830723439
04350033404505213  x
665002825766568590  x
7253900111637967  x
476282551047385
5750166930753130016
34243279492352607
580335613255076942
4905824155744144
3721011901317736  x
xxx

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:

608375125820713438
04450033404605313
665102825766668600
7263900111738067
466281440046384
5650156829743129015
33243178482252506
570325512245066941
4805723054743143
3731011901417836

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

608375125820713438
04450033404605313  x
665102825766668600  x
7263900111738067  x
466281440046384
5650156829743129015
33243178482252506
570325512245066941  x
4805723054743143  x
3731011901417836
xxx

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:

598265024820703437
04450033414705413
665102825776768610
7263900121838167
456180330045383
5549146728743128014
32233077472252405
570325512255167041
4805723055843243
362901801407835

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

598265024820703437  x
04450033414705413  x
665102825776768610  x
7263900121838167  x
456180330045383  x
5549146728743128014
32233077472252405
570325512255167041  x
4805723055843243  x
362901801407835  x
x

Create additional zeros

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

598265024820703937
04450033414705913
665102825776768660
7263900121838667
456180330045433
50449622369262309
27182572421701900
570325512255167541
4805723055843743
362901801408335

Cover all zeros with a minimum number of lines

There are 10 lines required to cover all zeros:

598265024820703937  x
04450033414705913  x
665102825776768660  x
7263900121838667  x
456180330045433  x
50449622369262309  x
27182572421701900  x
570325512255167541  x
4805723055843743  x
362901801408335  x

The optimal assignment

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

598265024820703937
04450033414705913
665102825776768660
7263900121838667
456180330045433
50449622369262309
27182572421701900
570325512255167541
4805723055843743
362901801408335

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

7592186161929914348
32707827866772377940
90692047709584977819
27405515412631289482
5666879355461429
76643183708945541430
4833428884321445916
85225678614772399164
56261262957956346
52122111551023218746

The optimal value equals 183.