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:

64 | 90 | 9 | 42 |

15 | 55 | 33 | 58 |

25 | 26 | 17 | 91 |

58 | 53 | 18 | 17 |

**Subtract row minima**

We subtract the row minimum from each row:

55 | 81 | 0 | 33 | (-9) |

0 | 40 | 18 | 43 | (-15) |

8 | 9 | 0 | 74 | (-17) |

41 | 36 | 1 | 0 | (-17) |

**Subtract column minima**

We subtract the column minimum from each column:

55 | 72 | 0 | 33 |

0 | 31 | 18 | 43 |

8 | 0 | 0 | 74 |

41 | 27 | 1 | 0 |

(-9) |

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

There are 4 lines required to cover all zeros:

55 | 72 | 0 | 33 | x |

0 | 31 | 18 | 43 | x |

8 | 0 | 0 | 74 | x |

41 | 27 | 1 | 0 | x |

**The optimal assignment**

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

55 | 72 | 0 | 33 |

0 | 31 | 18 | 43 |

8 | 0 | 0 | 74 |

41 | 27 | 1 | 0 |

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

64 | 90 | 9 | 42 |

15 | 55 | 33 | 58 |

25 | 26 | 17 | 91 |

58 | 53 | 18 | 17 |

The optimal value equals 67.

HungarianAlgorithm.com © 2013-2020