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:

10 | 93 | 96 | 40 | 46 |

76 | 99 | 4 | 49 | 74 |

39 | 55 | 25 | 10 | 27 |

21 | 78 | 10 | 23 | 66 |

64 | 26 | 46 | 88 | 33 |

**Subtract row minima**

We subtract the row minimum from each row:

0 | 83 | 86 | 30 | 36 | (-10) |

72 | 95 | 0 | 45 | 70 | (-4) |

29 | 45 | 15 | 0 | 17 | (-10) |

11 | 68 | 0 | 13 | 56 | (-10) |

38 | 0 | 20 | 62 | 7 | (-26) |

**Subtract column minima**

We subtract the column minimum from each column:

0 | 83 | 86 | 30 | 29 |

72 | 95 | 0 | 45 | 63 |

29 | 45 | 15 | 0 | 10 |

11 | 68 | 0 | 13 | 49 |

38 | 0 | 20 | 62 | 0 |

(-7) |

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

There are 4 lines required to cover all zeros:

0 | 83 | 86 | 30 | 29 | x |

72 | 95 | 0 | 45 | 63 | |

29 | 45 | 15 | 0 | 10 | x |

11 | 68 | 0 | 13 | 49 | |

38 | 0 | 20 | 62 | 0 | x |

x |

**Create additional zeros**

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

0 | 83 | 97 | 30 | 29 |

61 | 84 | 0 | 34 | 52 |

29 | 45 | 26 | 0 | 10 |

0 | 57 | 0 | 2 | 38 |

38 | 0 | 31 | 62 | 0 |

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

There are 4 lines required to cover all zeros:

0 | 83 | 97 | 30 | 29 | |

61 | 84 | 0 | 34 | 52 | |

29 | 45 | 26 | 0 | 10 | x |

0 | 57 | 0 | 2 | 38 | |

38 | 0 | 31 | 62 | 0 | 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:

0 | 81 | 97 | 28 | 27 |

61 | 82 | 0 | 32 | 50 |

31 | 45 | 28 | 0 | 10 |

0 | 55 | 0 | 0 | 36 |

40 | 0 | 33 | 62 | 0 |

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

There are 4 lines required to cover all zeros:

0 | 81 | 97 | 28 | 27 | |

61 | 82 | 0 | 32 | 50 | |

31 | 45 | 28 | 0 | 10 | |

0 | 55 | 0 | 0 | 36 | |

40 | 0 | 33 | 62 | 0 | x |

x | x | x |

**Create additional zeros**

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

0 | 71 | 97 | 28 | 17 |

61 | 72 | 0 | 32 | 40 |

31 | 35 | 28 | 0 | 0 |

0 | 45 | 0 | 0 | 26 |

50 | 0 | 43 | 72 | 0 |

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

There are 5 lines required to cover all zeros:

0 | 71 | 97 | 28 | 17 | x |

61 | 72 | 0 | 32 | 40 | x |

31 | 35 | 28 | 0 | 0 | x |

0 | 45 | 0 | 0 | 26 | x |

50 | 0 | 43 | 72 | 0 | x |

**The optimal assignment**

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

0 | 71 | 97 | 28 | 17 |

61 | 72 | 0 | 32 | 40 |

31 | 35 | 28 | 0 | 0 |

0 | 45 | 0 | 0 | 26 |

50 | 0 | 43 | 72 | 0 |

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

10 | 93 | 96 | 40 | 46 |

76 | 99 | 4 | 49 | 74 |

39 | 55 | 25 | 10 | 27 |

21 | 78 | 10 | 23 | 66 |

64 | 26 | 46 | 88 | 33 |

The optimal value equals 90.

HungarianAlgorithm.com © 2013-2023