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:

89664635162527262
128718975686641494
11971444515080751
25575667277893912
5614647223135977
323617918291439943
308031362889644512
81842553884418677
231591889143179945

Subtract row minima

We subtract the row minimum from each row:

86634304859496959(-3)
075685447452282(-12)
490737444373044(-7)
1951500667183336(-6)
5504546213025876(-1)
15190746574268226(-17)
18681924167752330(-12)
79820533682398475(-2)
807673762828430(-15)

Subtract column minima

We subtract the column minimum from each column:

86634303231476959
075685284650282
490737281571044
1951500504381336
55045465205876
15190744946248226
1868192404950330
79820532054378475
80767360008430
(-16)(-28)(-2)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

86634303231476959
075685284650282  x
490737281571044  x
1951500504381336
55045465205876  x
15190744946248226
1868192404950330  x
79820532054378475
80767360008430  x
xx

Create additional zeros

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

80574302625416353
0751291284650282
4901343281571044
1345500443775270
55051525205876
9130744340187620
1868253004950330
73760531448317869
80827960008430

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

80574302625416353  x
0751291284650282  x
4901343281571044  x
1345500443775270  x
55051525205876  x
9130744340187620
1868253004950330  x
73760531448317869
80827960008430  x
x

Create additional zeros

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

80575202625416353
0752191284650282
4902243281571044
1345590443775270
55060525205876
04065343196711
1868343004950330
6467044539226960
80917960008430

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

80575202625416353  x
0752191284650282
4902243281571044  x
1345590443775270  x
55060525205876  x
04065343196711
1868343004950330  x
6467044539226960
80917960008430  x
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:

82575402625416353
0732189264448080
6902443281571044
1545610443775270
57062525205876
0206332297659
2068363004950330
6465042337206758
100937960008430

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

82575402625416353  x
0732189264448080
6902443281571044
1545610443775270  x
57062525205876  x
0206332297659
2068363004950330  x
6465042337206758
100937960008430  x
xxx

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:

84575602625416553
0712187244246078
6882441261369042
1745630443775290
59064525206076
0006130275657
2268383004950350
6463040135186756
120957960008630

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

84575602625416553  x
0712187244246078  x
6882441261369042  x
1745630443775290  x
59064525206076  x
0006130275657  x
2268383004950350  x
6463040135186756  x
120957960008630  x

The optimal assignment

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

84575602625416553
0712187244246078
6882441261369042
1745630443775290
59064525206076
0006130275657
2268383004950350
6463040135186756
120957960008630

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

89664635162527262
128718975686641494
11971444515080751
25575667277893912
5614647223135977
323617918291439943
308031362889644512
81842553884418677
231591889143179945

The optimal value equals 146.