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:

60 | 23 | 97 | 65 |

83 | 36 | 32 | 83 |

44 | 61 | 29 | 70 |

29 | 25 | 96 | 96 |

**Subtract row minima**

We subtract the row minimum from each row:

37 | 0 | 74 | 42 | (-23) |

51 | 4 | 0 | 51 | (-32) |

15 | 32 | 0 | 41 | (-29) |

4 | 0 | 71 | 71 | (-25) |

**Subtract column minima**

We subtract the column minimum from each column:

33 | 0 | 74 | 1 |

47 | 4 | 0 | 10 |

11 | 32 | 0 | 0 |

0 | 0 | 71 | 30 |

(-4) | (-41) |

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

There are 4 lines required to cover all zeros:

33 | 0 | 74 | 1 | x |

47 | 4 | 0 | 10 | x |

11 | 32 | 0 | 0 | x |

0 | 0 | 71 | 30 | x |

**The optimal assignment**

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

33 | 0 | 74 | 1 |

47 | 4 | 0 | 10 |

11 | 32 | 0 | 0 |

0 | 0 | 71 | 30 |

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

60 | 23 | 97 | 65 |

83 | 36 | 32 | 83 |

44 | 61 | 29 | 70 |

29 | 25 | 96 | 96 |

The optimal value equals 154.

HungarianAlgorithm.com © 2013-2022