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:

5818104427489218999
2721822609988934490
5477255256989255980
453334048986339068
8728335562765904022
38882065655235516826
56543183245463816
723589179558821771
8337524747761408816
5899275414245178798

Subtract row minima

We subtract the row minimum from each row:

4991351839839900(-9)
2519800589786914288(-2)
4972204706484205475(-5)
420303745953308765(-3)
8122274902159843416(-6)
186804545321531486(-20)
55532082234453715(-1)
6427019875074963(-8)
763045404005433819(-7)
539422499190128293(-5)

Subtract column minima

We subtract the column minimum from each column:

3191351839830810
719800589786823388
3172204706484114575
240303745953217865
6322274902159752516
06804545321522396
37532082234362815
4627019875065063
583045404005424729
35942249919037393
(-18)(-9)(-9)

Cover all zeros with a minimum number of lines

There are 8 lines required to cover all zeros:

3191351839830810  x
719800589786823388
3172204706484114575
240303745953217865  x
6322274902159752516
06804545321522396  x
37532082234362815
4627019875065063  x
583045404005424729  x
35942249919037393  x
xx

Create additional zeros

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

3191372039830810
517780589584803186
297018470628294373
240303947953217865
6120254901957732314
06804747321522396
35510082212342613
46270311875065063
583045424205424729
359422511119037393

Cover all zeros with a minimum number of lines

There are 9 lines required to cover all zeros:

3191372039830810  x
517780589584803186  x
297018470628294373
240303947953217865  x
6120254901957732314
06804747321522396  x
35510082212342613  x
46270311875065063  x
583045424205424729  x
359422511119037393  x
x

Create additional zeros

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

3191372939830810
517780679584803186
20619380537303464
240303956953217865
521116400104864145
06804756321522396
35510091212342613
46270320875065063
583045425105424729
359422512019037393

Cover all zeros with a minimum number of lines

There are 10 lines required to cover all zeros:

3191372939830810  x
517780679584803186  x
20619380537303464  x
240303956953217865  x
521116400104864145  x
06804756321522396  x
35510091212342613  x
46270320875065063  x
583045425105424729  x
359422512019037393  x

The optimal assignment

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

3191372939830810
517780679584803186
20619380537303464
240303956953217865
521116400104864145
06804756321522396
35510091212342613
46270320875065063
583045425105424729
359422512019037393

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

5818104427489218999
2721822609988934490
5477255256989255980
453334048986339068
8728335562765904022
38882065655235516826
56543183245463816
723589179558821771
8337524747761408816
5899275414245178798

The optimal value equals 115.