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:

74561384785632
7097651168347098
881248147887032
8084946691686186
334370744164470
3256535172804794
8627485178651877
2020889192571110

Subtract row minima

We subtract the row minimum from each row:

73550374675531(-1)
598654057235987(-11)
8044067006224(-8)
1923335307025(-61)
293966700124066(-4)
024211940481562(-32)
68930336047059(-18)
10107881824710(-10)

Subtract column minima

We subtract the column minimum from each column:

73510374675531
598254057235987
8004067006224
1919335307025
293566700124066
020211940481562
68530336047059
1067881824710
(-4)

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

73510374675531  x
598254057235987  x
8004067006224  x
1919335307025
293566700124066  x
020211940481562  x
68530336047059
1067881824710  x
x

Create additional zeros

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

73510374676031
598254057236487
8004067006724
1414280252020
293566700124566
020211940482062
63025285542054
1067881824760

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

73510374676031  x
598254057236487  x
8004067006724  x
1414280252020  x
293566700124566  x
020211940482062  x
63025285542054  x
1067881824760  x

The optimal assignment

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

73510374676031
598254057236487
8004067006724
1414280252020
293566700124566
020211940482062
63025285542054
1067881824760

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

74561384785632
7097651168347098
881248147887032
8084946691686186
334370744164470
3256535172804794
8627485178651877
2020889192571110

The optimal value equals 154.