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:

6630977465118696
514670474633281
4188618879827234
854852623881856
57295222924924
1771454364502951
97886745329815
6911193362549028

Subtract row minima

We subtract the row minimum from each row:

551986635407585(-11)
474266070592877(-4)
75427544548380(-34)
824549590851553(-3)
55093200904722(-2)
054282647331234(-17)
2717903825918(-7)
58082251437917(-11)

Subtract column minima

We subtract the column minimum from each column:

551978635406385
474258070591677
75419544548260
82454159085353
55085200903522
05420264733034
2717103825798
58002251436717
(-8)(-12)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

551978635406385  x
474258070591677
75419544548260  x
82454159085353  x
55085200903522  x
05420264733034  x
2717103825798
58002251436717  x
x

Create additional zeros

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

551978655406385
454056068571475
75419564548260
82454161085353
55085220903522
05420284733034
0696903623776
58002451436717

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

551978655406385  x
454056068571475  x
75419564548260  x
82454161085353  x
55085220903522  x
05420284733034  x
0696903623776  x
58002451436717  x

The optimal assignment

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

551978655406385
454056068571475
75419564548260
82454161085353
55085220903522
05420284733034
0696903623776
58002451436717

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

6630977465118696
514670474633281
4188618879827234
854852623881856
57295222924924
1771454364502951
97886745329815
6911193362549028

The optimal value equals 111.