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:

9727791365788684
7318284734538294
8185283848305112
5976791563492534
689021437833877
8181245475819251
2068911143179442
3835424989975158

Subtract row minima

We subtract the row minimum from each row:

841466052657371(-13)
550102916356476(-18)
697316263618390(-12)
446164048341019(-15)
608213357025069(-8)
575703051576827(-24)
9578003268331(-11)
3071454621623(-35)

Subtract column minima

We subtract the column minimum from each column:

811466036597371
52010290296476
667316262012390
416164032281019
578213355419069
545703035516827
6578001608331
0071438561623
(-3)(-16)(-6)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

811466036597371
52010290296476  x
667316262012390  x
416164032281019
578213355419069  x
545703035516827  x
6578001608331  x
0071438561623  x
x

Create additional zeros

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

71456026496361
52010390296476
667316362012390
3151540221809
578213455419069
545704035516827
65780101608331
0072438561623

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

71456026496361
52010390296476  x
667316362012390  x
3151540221809
578213455419069
545704035516827  x
65780101608331  x
0072438561623  x
xx

Create additional zeros

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

67052022456357
52010430296876
667316402012430
2747500181405
53789455015065
545704435517227
65780141608731
0072838562023

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

67052022456357  x
52010430296876  x
667316402012430  x
2747500181405  x
53789455015065  x
545704435517227  x
65780141608731  x
0072838562023  x

The optimal assignment

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

67052022456357
52010430296876
667316402012430
2747500181405
53789455015065
545704435517227
65780141608731
0072838562023

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

9727791365788684
7318284734538294
8185283848305112
5976791563492534
689021437833877
8181245475819251
2068911143179442
3835424989975158

The optimal value equals 175.