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 | 15 | 14 | 95 |

24 | 33 | 71 | 53 |

62 | 73 | 61 | 8 |

96 | 75 | 17 | 2 |

**Subtract row minima**

We subtract the row minimum from each row:

72 | 1 | 0 | 81 | (-14) |

0 | 9 | 47 | 29 | (-24) |

54 | 65 | 53 | 0 | (-8) |

94 | 73 | 15 | 0 | (-2) |

**Subtract column minima**

We subtract the column minimum from each column:

72 | 0 | 0 | 81 |

0 | 8 | 47 | 29 |

54 | 64 | 53 | 0 |

94 | 72 | 15 | 0 |

(-1) |

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

There are 3 lines required to cover all zeros:

72 | 0 | 0 | 81 | x |

0 | 8 | 47 | 29 | x |

54 | 64 | 53 | 0 | |

94 | 72 | 15 | 0 | |

x |

**Create additional zeros**

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

72 | 0 | 0 | 96 |

0 | 8 | 47 | 44 |

39 | 49 | 38 | 0 |

79 | 57 | 0 | 0 |

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

There are 4 lines required to cover all zeros:

72 | 0 | 0 | 96 | x |

0 | 8 | 47 | 44 | x |

39 | 49 | 38 | 0 | x |

79 | 57 | 0 | 0 | x |

**The optimal assignment**

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

72 | 0 | 0 | 96 |

0 | 8 | 47 | 44 |

39 | 49 | 38 | 0 |

79 | 57 | 0 | 0 |

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

86 | 15 | 14 | 95 |

24 | 33 | 71 | 53 |

62 | 73 | 61 | 8 |

96 | 75 | 17 | 2 |

The optimal value equals 64.

HungarianAlgorithm.com © 2013-2024