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.

4432767080409695
7947937499405845
376862332574411
373476573552937
21741864287165
7796483430739341
93262177474404
9115829384951420

Subtract row minima

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

12044384886463(-32)
3975334590185(-40)
366761322473400(-1)
340446270522634(-3)
20731763276064(-1)
47661840436311(-30)
89221773430360(-4)
7716879708106(-14)

Subtract column minima

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

0027344886463
2773630590185
246744282473400
220275870522634
873059276064
3566100436311
7722069430360
6515175708106
(-12)(-17)(-4)

Cover all zeros with a minimum number of lines

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

0027344886463x
2773630590185
246744282473400
220275870522634x
873059276064
3566100436311x
7722069430360
6515175708106
xxxx

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.

0028344896564
2663629580185
236644272373400
220285870532735
772058266064
3566200446412
7621068420360
6405174698106

Cover all zeros with a minimum number of lines

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

0028344896564x
2663629580185
236644272373400
220285870532735
772058266064
3566200446412x
7621068420360
6405174698106
xxxxx

Create additional zeros

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

07353448167271
1963622510185
166644201673400
150285163532735
072051196064
3573900517119
6921061350360
5705167628106

Cover all zeros with a minimum number of lines

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

07353448167271
1963622510185
166644201673400
150285163532735
072051196064
3573900517119x
6921061350360
5705167628106
xxxxxx

Create additional zeros

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

07351832167271
196366350185
1666444073400
150283547532735
07203536064
51892500678735
6921045190360
5705151468106

Cover all zeros with a minimum number of lines

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

07351832167271x
196366350185x
1666444073400x
150283547532735x
07203536064x
51892500678735x
6921045190360x
5705151468106x

The optimal assignment

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

07351832167271
196366350185
1666444073400
150283547532735
07203536064
51892500678735
6921045190360
5705151468106

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

4432767080409695
7947937499405845
376862332574411
373476573552937
21741864287165
7796483430739341
93262177474404
9115829384951420

The total minimum cost is 182.


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