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.

6974852189674879901
233753299106323073
1114845272764371782
4650427539112224982
1055993268238237191
32799489922113996249
77694647432359385083
82747888406919396
385231817766725672
12948311741541553036

Subtract row minima

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

6873842088664778890(-1)
18320279451272568(-5)
47774502057301075(-7)
424602349878184578(-4)
954983167228136090(-1)
196681767980864936(-13)
5446232420036152760(-23)
76687222346313330(-6)
082201514463695369(-3)
18372063430441925(-11)

Subtract column minima

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

6866842088664765890
18250279451142568
40774502057171075
42390234987854578
947983167228123090
195981767980734936
543923242003622760
7661722234630330
075201514463565369
17672063430311925
(-7)(-13)

Cover all zeros with a minimum number of lines

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

6866842088664765890x
18250279451142568
40774502057171075x
42390234987854578
947983167228123090x
195981767980734936x
543923242003622760x
7661722234630330x
075201514463565369x
17672063430311925x
x

Create additional zeros

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

6866852088664765890
17240269340132467
40784502057171075
41380224886744477
947993167228123090
195982767980734936
543924242003622760
7661732234630330
075211514463565369
17673063430311925

Cover all zeros with a minimum number of lines

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

6866852088664765890x
17240269340132467
40784502057171075x
41380224886744477
947993167228123090x
195982767980734936
543924242003622760x
7661732234630330x
075211514463565369x
17673063430311925x
xx

Create additional zeros

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

6866892088665165890
1320022890092063
40824502061171075
37340184482704073
9471033167228523090
155582727540694532
543928242004022760
7661772234670330
075251514467565369
17677063434311925

Cover all zeros with a minimum number of lines

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

6866892088665165890
1320022890092063
40824502061171075x
37340184482704073
9471033167228523090x
155582727540694532
543928242004022760
7661772234670330
075251514467565369x
17677063434311925x
xxxxx

Create additional zeros

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

6664891886665165870
1118020870091863
40844502263191077
35320164282703873
9471053167248725092
135382707340694332
523728221804022560
7459770034670310
075271514669585371
17679063636331927

Cover all zeros with a minimum number of lines

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

6664891886665165870x
1118020870091863x
40844502263191077x
35320164282703873x
9471053167248725092x
135382707340694332x
523728221804022560x
7459770034670310x
075271514669585371x
17679063636331927x

The optimal assignment

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

6664891886665165870
1118020870091863
40844502263191077
35320164282703873
9471053167248725092
135382707340694332
523728221804022560
7459770034670310
075271514669585371
17679063636331927

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

6974852189674879901
233753299106323073
1114845272764371782
4650427539112224982
1055993268238237191
32799489922113996249
77694647432359385083
82747888406919396
385231817766725672
12948311741541553036

The total minimum cost is 101.


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