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:

14 | 4 | 13 | 99 | 36 |

26 | 92 | 51 | 44 | 91 |

52 | 3 | 64 | 54 | 2 |

66 | 1 | 21 | 86 | 25 |

69 | 33 | 80 | 94 | 95 |

**Subtract row minima**

We subtract the row minimum from each row:

10 | 0 | 9 | 95 | 32 | (-4) |

0 | 66 | 25 | 18 | 65 | (-26) |

50 | 1 | 62 | 52 | 0 | (-2) |

65 | 0 | 20 | 85 | 24 | (-1) |

36 | 0 | 47 | 61 | 62 | (-33) |

**Subtract column minima**

We subtract the column minimum from each column:

10 | 0 | 0 | 77 | 32 |

0 | 66 | 16 | 0 | 65 |

50 | 1 | 53 | 34 | 0 |

65 | 0 | 11 | 67 | 24 |

36 | 0 | 38 | 43 | 62 |

(-9) | (-18) |

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

There are 4 lines required to cover all zeros:

10 | 0 | 0 | 77 | 32 | x |

0 | 66 | 16 | 0 | 65 | x |

50 | 1 | 53 | 34 | 0 | x |

65 | 0 | 11 | 67 | 24 | |

36 | 0 | 38 | 43 | 62 | |

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:

10 | 11 | 0 | 77 | 32 |

0 | 77 | 16 | 0 | 65 |

50 | 12 | 53 | 34 | 0 |

54 | 0 | 0 | 56 | 13 |

25 | 0 | 27 | 32 | 51 |

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

There are 4 lines required to cover all zeros:

10 | 11 | 0 | 77 | 32 | |

0 | 77 | 16 | 0 | 65 | x |

50 | 12 | 53 | 34 | 0 | x |

54 | 0 | 0 | 56 | 13 | |

25 | 0 | 27 | 32 | 51 | |

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 | 11 | 0 | 67 | 22 |

0 | 87 | 26 | 0 | 65 |

50 | 22 | 63 | 34 | 0 |

44 | 0 | 0 | 46 | 3 |

15 | 0 | 27 | 22 | 41 |

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

There are 5 lines required to cover all zeros:

0 | 11 | 0 | 67 | 22 | x |

0 | 87 | 26 | 0 | 65 | x |

50 | 22 | 63 | 34 | 0 | x |

44 | 0 | 0 | 46 | 3 | x |

15 | 0 | 27 | 22 | 41 | x |

**The optimal assignment**

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

0 | 11 | 0 | 67 | 22 |

0 | 87 | 26 | 0 | 65 |

50 | 22 | 63 | 34 | 0 |

44 | 0 | 0 | 46 | 3 |

15 | 0 | 27 | 22 | 41 |

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

14 | 4 | 13 | 99 | 36 |

26 | 92 | 51 | 44 | 91 |

52 | 3 | 64 | 54 | 2 |

66 | 1 | 21 | 86 | 25 |

69 | 33 | 80 | 94 | 95 |

The optimal value equals 114.

HungarianAlgorithm.com © 2013-2024