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:

34524226656
368666591858
572346872579
981982337
162182234439
514796222387

Subtract row minima

We subtract the row minimum from each row:

32504006454(-2)
18684841040(-18)
3402364256(-23)
870972236(-1)
056672823(-16)
2925740165(-22)

Subtract column minima

We subtract the column minimum from each column:

32504006431
18684841017
3402364233
870972213
05667280
2925740142
(-23)

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

32504006431
18684841017  x
3402364233  x
870972213  x
05667280  x
2925740142
x

Create additional zeros

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

31493906330
18684842017
3402365233
870982213
05668280
2824730041

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

31493906330
18684842017
3402365233  x
870982213  x
05668280  x
2824730041
xx

Create additional zeros

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

14322206313
151314200
34023821933
8701153913
056625450
117560024

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

14322206313  x
151314200  x
34023821933  x
8701153913  x
056625450  x
117560024  x

The optimal assignment

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

14322206313
151314200
34023821933
8701153913
056625450
117560024

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

34524226656
368666591858
572346872579
981982337
162182234439
514796222387

The optimal value equals 123.