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

This is the original cost matrix:

86 | 89 | 60 | 59 | 94 |

87 | 11 | 74 | 46 | 71 |

13 | 49 | 23 | 86 | 36 |

64 | 65 | 39 | 65 | 64 |

33 | 7 | 53 | 13 | 52 |

**Subtract row minima**

We subtract the row minimum from each row:

27 | 30 | 1 | 0 | 35 | (-59) |

76 | 0 | 63 | 35 | 60 | (-11) |

0 | 36 | 10 | 73 | 23 | (-13) |

25 | 26 | 0 | 26 | 25 | (-39) |

26 | 0 | 46 | 6 | 45 | (-7) |

**Subtract column minima**

We subtract the column minimum from each column:

27 | 30 | 1 | 0 | 12 |

76 | 0 | 63 | 35 | 37 |

0 | 36 | 10 | 73 | 0 |

25 | 26 | 0 | 26 | 2 |

26 | 0 | 46 | 6 | 22 |

(-23) |

**Cover all zeros with a minimum number of lines**

There are 4 lines required to cover all zeros:

27 | 30 | 1 | 0 | 12 | x |

76 | 0 | 63 | 35 | 37 | |

0 | 36 | 10 | 73 | 0 | x |

25 | 26 | 0 | 26 | 2 | x |

26 | 0 | 46 | 6 | 22 | |

x |

**Create additional zeros**

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

27 | 36 | 1 | 0 | 12 |

70 | 0 | 57 | 29 | 31 |

0 | 42 | 10 | 73 | 0 |

25 | 32 | 0 | 26 | 2 |

20 | 0 | 40 | 0 | 16 |

**Cover all zeros with a minimum number of lines**

There are 4 lines required to cover all zeros:

27 | 36 | 1 | 0 | 12 | |

70 | 0 | 57 | 29 | 31 | |

0 | 42 | 10 | 73 | 0 | x |

25 | 32 | 0 | 26 | 2 | x |

20 | 0 | 40 | 0 | 16 | |

x | x |

**Create additional zeros**

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

26 | 36 | 0 | 0 | 11 |

69 | 0 | 56 | 29 | 30 |

0 | 43 | 10 | 74 | 0 |

25 | 33 | 0 | 27 | 2 |

19 | 0 | 39 | 0 | 15 |

**Cover all zeros with a minimum number of lines**

There are 4 lines required to cover all zeros:

26 | 36 | 0 | 0 | 11 | |

69 | 0 | 56 | 29 | 30 | |

0 | 43 | 10 | 74 | 0 | x |

25 | 33 | 0 | 27 | 2 | |

19 | 0 | 39 | 0 | 15 | |

x | x | x |

**Create additional zeros**

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

24 | 36 | 0 | 0 | 9 |

67 | 0 | 56 | 29 | 28 |

0 | 45 | 12 | 76 | 0 |

23 | 33 | 0 | 27 | 0 |

17 | 0 | 39 | 0 | 13 |

**Cover all zeros with a minimum number of lines**

There are 5 lines required to cover all zeros:

24 | 36 | 0 | 0 | 9 | x |

67 | 0 | 56 | 29 | 28 | x |

0 | 45 | 12 | 76 | 0 | x |

23 | 33 | 0 | 27 | 0 | x |

17 | 0 | 39 | 0 | 13 | x |

**The optimal assignment**

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

24 | 36 | 0 | 0 | 9 |

67 | 0 | 56 | 29 | 28 |

0 | 45 | 12 | 76 | 0 |

23 | 33 | 0 | 27 | 0 |

17 | 0 | 39 | 0 | 13 |

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

86 | 89 | 60 | 59 | 94 |

87 | 11 | 74 | 46 | 71 |

13 | 49 | 23 | 86 | 36 |

64 | 65 | 39 | 65 | 64 |

33 | 7 | 53 | 13 | 52 |

The optimal value equals 161.

HungarianAlgorithm.com © 2013-2017