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:

30 | 85 | 56 | 82 |

59 | 83 | 12 | 24 |

73 | 51 | 37 | 1 |

79 | 87 | 8 | 98 |

**Subtract row minima**

We subtract the row minimum from each row:

0 | 55 | 26 | 52 | (-30) |

47 | 71 | 0 | 12 | (-12) |

72 | 50 | 36 | 0 | (-1) |

71 | 79 | 0 | 90 | (-8) |

**Subtract column minima**

We subtract the column minimum from each column:

0 | 5 | 26 | 52 |

47 | 21 | 0 | 12 |

72 | 0 | 36 | 0 |

71 | 29 | 0 | 90 |

(-50) |

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

There are 3 lines required to cover all zeros:

0 | 5 | 26 | 52 | x |

47 | 21 | 0 | 12 | |

72 | 0 | 36 | 0 | x |

71 | 29 | 0 | 90 | |

x |

**Create additional zeros**

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

0 | 5 | 38 | 52 |

35 | 9 | 0 | 0 |

72 | 0 | 48 | 0 |

59 | 17 | 0 | 78 |

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

There are 4 lines required to cover all zeros:

0 | 5 | 38 | 52 | x |

35 | 9 | 0 | 0 | x |

72 | 0 | 48 | 0 | x |

59 | 17 | 0 | 78 | x |

**The optimal assignment**

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

0 | 5 | 38 | 52 |

35 | 9 | 0 | 0 |

72 | 0 | 48 | 0 |

59 | 17 | 0 | 78 |

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

30 | 85 | 56 | 82 |

59 | 83 | 12 | 24 |

73 | 51 | 37 | 1 |

79 | 87 | 8 | 98 |

The optimal value equals 113.

HungarianAlgorithm.com © 2013-2024