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.

98853234784
824456363625
28637644245
18677414461
26499758338
946818226481

Subtract row minima

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

91782527077(-7)
57193111110(-25)
21560573538(-7)
14637010057(-4)
23469455035(-3)
7650044663(-18)

Subtract column minima

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

77592523077
430317110
7370533538
044706057
9279451035
6231004663
(-14)(-19)(-4)

Cover all zeros with a minimum number of lines

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

77592523077
430317110x
7370533538x
044706057x
9279451035
6231004663x
x

Create additional zeros

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

68501614068
430317200
7370534438
044706957
0188542026
6231005563

Cover all zeros with a minimum number of lines

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

68501614068
430317200x
7370534438x
044706957
0188542026
6231005563x
xx

Create additional zeros

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

6844108062
490317260
13370535038
038640951
0127936020
6831006163

Cover all zeros with a minimum number of lines

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

6844108062
490317260x
13370535038
038640951
0127936020
6831006163
xxxx

Create additional zeros

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

6832108050
6104319380
13250535026
026640939
00793608
6819006151

Cover all zeros with a minimum number of lines

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

6832108050x
6104319380x
13250535026x
026640939x
00793608x
6819006151x

The optimal assignment

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

6832108050
6104319380
13250535026
026640939
00793608
6819006151

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

98853234784
824456363625
28637644245
18677414461
26499758338
946818226481

The total minimum cost is 128.


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