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.

547184601451
301534790384
9661148953927
4858972218757
48574115745366
29188692653069
4872988225993

Subtract row minima

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

537083590440(-1)
271204487081(-3)
057239863018(-9)
3949063127848(-9)
3342260593851(-15)
1106874471251(-18)
3963079135084(-9)

Subtract column minima

Because each column already contains a zero, subtracting the column minima has no effect.

Cover all zeros with a minimum number of lines

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

537083590440x
271204487081x
057239863018x
3949063127848
3342260593851x
1106874471251x
3963079135084
x

Create additional zeros

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

537095590440
2712124487081
0571439863018
273705106636
3342380593851
1108074471251
275106713872

Cover all zeros with a minimum number of lines

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

537095590440x
2712124487081x
0571439863018x
273705106636x
3342380593851x
1108074471251x
275106713872x

The optimal assignment

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

537095590440
2712124487081
0571439863018
273705106636
3342380593851
1108074471251
275106713872

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

547184601451
301534790384
9661148953927
4858972218757
48574115745366
29188692653069
4872988225993

The total minimum cost is 76.


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