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:

85454084271722
21859098468351
31569766738920
51642312325924
422342629966
3998164091495
17884884757565

Subtract row minima

We subtract the row minimum from each row:

682823671005(-17)
0646977256230(-21)
1136774653690(-20)
3952110204712(-12)
381902225562(-4)
3493113586440(-5)
0713167585848(-17)

Subtract column minima

We subtract the column minimum from each column:

6892367005
0456977156230
1117774643690
3933110104712
38002215562
3474113576440
0523167485848
(-19)(-10)

Cover all zeros with a minimum number of lines

There are 5 lines required to cover all zeros:

6892367005  x
0456977156230
1117774643690
3933110104712  x
38002215562  x
3474113576440
0523167485848
xx

Create additional zeros

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

79923670016
034586645130
116663532580
5033110104723
49002215573
346302465330
0412056374748

Cover all zeros with a minimum number of lines

There are 6 lines required to cover all zeros:

79923670016  x
034586645130
116663532580  x
5033110104723  x
49002215573  x
346302465330  x
0412056374748
x

Create additional zeros

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

83923670016
030546204726
156663532580
5433110104723
53002215573
386302465330
0371652334344

Cover all zeros with a minimum number of lines

There are 7 lines required to cover all zeros:

83923670016  x
030546204726  x
156663532580  x
5433110104723  x
53002215573  x
386302465330  x
0371652334344  x

The optimal assignment

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

83923670016
030546204726
156663532580
5433110104723
53002215573
386302465330
0371652334344

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

85454084271722
21859098468351
31569766738920
51642312325924
422342629966
3998164091495
17884884757565

The optimal value equals 151.