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.

8432797215875580
2054885625326
611777829124256
316069739981078
168886272552528
98085197851952
57418058148854
9219438313842662

Subtract row minima

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

691764570724065(-15)
1504380120271(-5)
5396902143448(-8)
22516064089169(-9)
148684070532326(-2)
77883177649930(-2)
56307957138753(-1)
79630700711349(-13)

Subtract column minima

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

621764570683965
804380116261
4696902103348
15516064085069
78684070492226
07883177645920
4930795798653
72630700671249
(-7)(-4)(-1)

Cover all zeros with a minimum number of lines

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

621764570683965
804380116261x
4696902103348x
15516064085069x
78684070492226x
07883177645920x
4930795798653x
72630700671249
x

Create additional zeros

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

561158510623359
804380716261
4696902703348
15516064685069
78684076492226
07883178245920
4930796398653
6602464061643

Cover all zeros with a minimum number of lines

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

561158510623359
804380716261
4696902703348x
15516064685069x
78684076492226x
07883178245920x
4930796398653x
6602464061643
xx

Create additional zeros

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

551157500613258
704279715250
46106902803348
15526064785069
78784077492226
07983178345920
4940796498653
6502363060542

Cover all zeros with a minimum number of lines

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

551157500613258x
704279715250x
46106902803348x
15526064785069x
78784077492226x
07983178345920x
4940796498653x
6502363060542x

The optimal assignment

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

551157500613258
704279715250
46106902803348
15526064785069
78784077492226
07983178345920
4940796498653
6502363060542

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

8432797215875580
2054885625326
611777829124256
316069739981078
168886272552528
98085197851952
57418058148854
9219438313842662

The total minimum cost is 74.


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