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):

Don't show the steps of the Hungarian algorithm
Maximize the total cost

This is the original cost matrix:

481860
128481680
1927224120
144541890

Negate all values

Because the objective is to maximize the total cost we negate all elements:

-48-18-60
-128-48-16-80
-192-72-24-120
-144-54-18-90

Make the matrix nonnegative

The cost matrix contains negative elements, we add 192 to each entry to make the cost matrix nonnegative:

144174186192
64144176112
012016872
48138174102

Subtract row minima

We subtract the row minimum from each row:

0304248(-144)
08011248(-64)
012016872
09012654(-48)

Subtract column minima

We subtract the column minimum from each column:

0000
050700
09012624
060846
(-30)(-42)(-48)

Cover all zeros with a minimum number of lines

There are 3 lines required to cover all zeros:

0000  x
050700  x
09012624
060846
x

Create additional zeros

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

6000
650700
08412018
054780

Cover all zeros with a minimum number of lines

There are 3 lines required to cover all zeros:

6000  x
650700
08412018
054780
xx

Create additional zeros

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

560050
60200
0347018
04280

Cover all zeros with a minimum number of lines

There are 4 lines required to cover all zeros:

560050  x
60200  x
0347018  x
04280  x

The optimal assignment

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

560050
60200
0347018
04280

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

481860
128481680
1927224120
144541890

The optimal value equals 336.