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.

68544661323542
654514757397884
606742956488283
9572748162603978
459569255423220
304151999979123
8675463889838072
5040914923686135

Subtract row minima

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

6349411818037(-5)
610474353357480(-4)
515833047397374(-9)
563335422321039(-39)
439367235203018(-2)
213242090888214(-9)
48378051454234(-38)
271768260453812(-23)

Subtract column minima

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

4249331818025
400394353357468
305825047397362
353327422321027
22935923520306
0323409088822
27370051454222
6176026045380
(-21)(-8)(-12)

Cover all zeros with a minimum number of lines

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

4249331818025
400394353357468x
305825047397362x
353327422321027
22935923520306x
0323409088822x
27370051454222x
6176026045380x
x

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.

4148320717024
400394353357568
305825047397462
343226412220026
22935923520316
0323409088832
27370051454322
6176026045390

Cover all zeros with a minimum number of lines

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

4148320717024
400394353357568x
305825047397462
343226412220026
22935923520316x
0323409088832x
27370051454322x
6176026045390x
xx

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.

3441250010017
400395053358268
235118040327455
272519411513019
22935930520386
0323479088902
27370751455022
6176033045460

Cover all zeros with a minimum number of lines

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

3441250010017x
400395053358268x
235118040327455x
272519411513019x
22935930520386x
0323479088902x
27370751455022x
6176033045460x

The optimal assignment

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

3441250010017
400395053358268
235118040327455
272519411513019
22935930520386
0323479088902
27370751455022
6176033045460

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

68544661323542
654514757397884
606742956488283
9572748162603978
459569255423220
304151999979123
8675463889838072
5040914923686135

The total minimum cost is 178.


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