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.

7878298616616
72851292263240
23904768534661
3199365415085
9673082422997
2594862821331
23293422127815

Subtract row minima

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

080759154599(-7)
6073080142028(-12)
0672445302338(-23)
2694310364580(-5)
0582173332088(-9)
160395373422(-9)
111722100663(-12)

Subtract column minima

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

080759154556
6073080141625
0672445301935
2694310364177
0582173331685
160395373019
111722100620
(-4)(-3)

Cover all zeros with a minimum number of lines

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

080759154556
6073080141625x
0672445301935
2694310364177x
0582173331685
160395373019x
111722100620x
x

Create additional zeros

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

074698548490
6673080141625
0611839241329
3294310364177
0521567271079
220395373019
171722100620

Cover all zeros with a minimum number of lines

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

074698548490x
6673080141625x
0611839241329
3294310364177x
0521567271079
220395373019x
171722100620x
x

Create additional zeros

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

1074698548490
7673080141625
05182914319
4294310364177
04255717069
320395373019
271722100620

Cover all zeros with a minimum number of lines

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

1074698548490x
7673080141625x
05182914319x
4294310364177x
04255717069x
320395373019x
271722100620x

The optimal assignment

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

1074698548490
7673080141625
05182914319
4294310364177
04255717069
320395373019
271722100620

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

7878298616616
72851292263240
23904768534661
3199365415085
9673082422997
2594862821331
23293422127815

The total minimum cost is 106.


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