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

Don't show the steps of the Hungarian algorithm
Maximize the total cost

This is the original cost matrix:

9867847213205
88135739759613
3897521265783
90493643402143
3383770241358
46214477672716
48216117343283

Subtract row minima

We subtract the row minimum from each row:

936279678150(-5)
750442662830(-13)
0867218235480(-3)
6928152219022(-21)
0353467211055(-3)
305286151110(-16)
314440171566(-17)

Subtract column minima

We subtract the column minimum from each column:

936264670150
750292654830
0865718155480
692802211022
0351967131055
305136143110
31429091566
(-15)(-8)

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

936264670150  x
750292654830  x
0865718155480
692802211022  x
0351967131055
305136143110  x
31429091566  x
x

Create additional zeros

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

1036264670150
850292654830
07647854470
792802211022
0259573045
405136143110
41429091566

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

1036264670150  x
850292654830  x
07647854470  x
792802211022  x
0259573045  x
405136143110  x
41429091566  x

The optimal assignment

Because there are 7 lines required, the zeros cover an optimal assignment:

1036264670150
850292654830
07647854470
792802211022
0259573045
405136143110
41429091566

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

9867847213205
88135739759613
3897521265783
90493643402143
3383770241358
46214477672716
48216117343283

The optimal value equals 111.