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:

646410727442
2719972287
67935283959
455716515688
204767985778
327824371942

Subtract row minima

We subtract the row minimum from each row:

54540626432(-10)
2609871276(-1)
62880233454(-5)
29410354072(-16)
02747783758(-20)
1359518023(-19)

Subtract column minima

We subtract the column minimum from each column:

54540446426
2609853270
6288053448
29410174066
02747603752
135950017
(-18)(-6)

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

54540446426
2609853270  x
6288053448
29410174066
02747603752  x
135950017  x
x

Create additional zeros

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

49490395921
26010353270
5783002943
24360123561
02752603752
1359100017

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

49490395921
26010353270  x
5783002943  x
24360123561
02752603752  x
1359100017  x
x

Create additional zeros

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

3737027479
26011553270
57831202943
1224002349
02764603752
1359220017

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

3737027479
26011553270  x
57831202943
1224002349
02764603752  x
1359220017  x
xx

Create additional zeros

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

2828027380
26012462270
48741202034
315001440
02773693752
1359319017

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

2828027380  x
26012462270  x
48741202034  x
315001440  x
02773693752  x
1359319017  x

The optimal assignment

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

2828027380
26012462270
48741202034
315001440
02773693752
1359319017

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

646410727442
2719972287
67935283959
455716515688
204767985778
327824371942

The optimal value equals 126.