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:

36 | 1 | 11 | 92 |

4 | 18 | 52 | 7 |

94 | 15 | 53 | 93 |

94 | 59 | 24 | 73 |

**Subtract row minima**

We subtract the row minimum from each row:

35 | 0 | 10 | 91 | (-1) |

0 | 14 | 48 | 3 | (-4) |

79 | 0 | 38 | 78 | (-15) |

70 | 35 | 0 | 49 | (-24) |

**Subtract column minima**

We subtract the column minimum from each column:

35 | 0 | 10 | 88 |

0 | 14 | 48 | 0 |

79 | 0 | 38 | 75 |

70 | 35 | 0 | 46 |

(-3) |

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

There are 3 lines required to cover all zeros:

35 | 0 | 10 | 88 | |

0 | 14 | 48 | 0 | x |

79 | 0 | 38 | 75 | |

70 | 35 | 0 | 46 | x |

x |

**Create additional zeros**

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

25 | 0 | 0 | 78 |

0 | 24 | 48 | 0 |

69 | 0 | 28 | 65 |

70 | 45 | 0 | 46 |

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

There are 3 lines required to cover all zeros:

25 | 0 | 0 | 78 | |

0 | 24 | 48 | 0 | x |

69 | 0 | 28 | 65 | |

70 | 45 | 0 | 46 | |

x | x |

**Create additional zeros**

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

0 | 0 | 0 | 53 |

0 | 49 | 73 | 0 |

44 | 0 | 28 | 40 |

45 | 45 | 0 | 21 |

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

There are 4 lines required to cover all zeros:

0 | 0 | 0 | 53 | x |

0 | 49 | 73 | 0 | x |

44 | 0 | 28 | 40 | x |

45 | 45 | 0 | 21 | x |

**The optimal assignment**

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

0 | 0 | 0 | 53 |

0 | 49 | 73 | 0 |

44 | 0 | 28 | 40 |

45 | 45 | 0 | 21 |

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

36 | 1 | 11 | 92 |

4 | 18 | 52 | 7 |

94 | 15 | 53 | 93 |

94 | 59 | 24 | 73 |

The optimal value equals 82.

HungarianAlgorithm.com © 2013-2017