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:

89 | 22 | 51 | 99 |

66 | 33 | 70 | 55 |

52 | 75 | 54 | 78 |

34 | 21 | 64 | 58 |

**Subtract row minima**

We subtract the row minimum from each row:

67 | 0 | 29 | 77 | (-22) |

33 | 0 | 37 | 22 | (-33) |

0 | 23 | 2 | 26 | (-52) |

13 | 0 | 43 | 37 | (-21) |

**Subtract column minima**

We subtract the column minimum from each column:

67 | 0 | 27 | 55 |

33 | 0 | 35 | 0 |

0 | 23 | 0 | 4 |

13 | 0 | 41 | 15 |

(-2) | (-22) |

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

There are 3 lines required to cover all zeros:

67 | 0 | 27 | 55 | |

33 | 0 | 35 | 0 | x |

0 | 23 | 0 | 4 | x |

13 | 0 | 41 | 15 | |

x |

**Create additional zeros**

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

54 | 0 | 14 | 42 |

33 | 13 | 35 | 0 |

0 | 36 | 0 | 4 |

0 | 0 | 28 | 2 |

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

There are 4 lines required to cover all zeros:

54 | 0 | 14 | 42 | x |

33 | 13 | 35 | 0 | x |

0 | 36 | 0 | 4 | x |

0 | 0 | 28 | 2 | x |

**The optimal assignment**

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

54 | 0 | 14 | 42 |

33 | 13 | 35 | 0 |

0 | 36 | 0 | 4 |

0 | 0 | 28 | 2 |

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

89 | 22 | 51 | 99 |

66 | 33 | 70 | 55 |

52 | 75 | 54 | 78 |

34 | 21 | 64 | 58 |

The optimal value equals 165.

HungarianAlgorithm.com © 2013-2021