Logo HungarianAlgorithm.com

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



Solution

This is the cost matrix.

714513121178
804147499170
2183961811
786447189949
244741345139
893565424599

Subtract row minima

For each row, the minimum element is subtracted from all elements in that row.

603421067(-11)
390685029(-41)
016374169(-2)
60462908131(-18)
02317102715(-24)
5403071064(-35)

Subtract column minima

For each column, the minimum element is subtracted from all elements in that column.

603401058
390485020
016354160
60462708122
0231510276
5402871055
(-2)(-9)

Cover all zeros with a minimum number of lines

A total of 5 lines are required to cover all zeros.

603401058x
390485020
016354160x
60462708122x
0231510276x
5402871055
x

Create additional zeros

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

603801058
350044616
020354160
60502708122
0271510276
500243651

Cover all zeros with a minimum number of lines

A total of 6 lines are required to cover all zeros.

603801058x
350044616x
020354160x
60502708122x
0271510276x
500243651x

The optimal assignment

Because there are 6 lines required, an optimal assignment exists among the zeros.

603801058
350044616
020354160
60502708122
0271510276
500243651

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

714513121178
804147499170
2183961811
786447189949
244741345139
893565424599

The total minimum cost is 146.


HungarianAlgorithm.com © 2026. All rights reserved.
Part of Echion, KvK 50713795, BTW NL001446762B10.