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 | 50 | 28 | 62 |

80 | 51 | 93 | 36 |

73 | 74 | 91 | 99 |

89 | 79 | 71 | 82 |

**Subtract row minima**

We subtract the row minimum from each row:

8 | 22 | 0 | 34 | (-28) |

44 | 15 | 57 | 0 | (-36) |

0 | 1 | 18 | 26 | (-73) |

18 | 8 | 0 | 11 | (-71) |

**Subtract column minima**

We subtract the column minimum from each column:

8 | 21 | 0 | 34 |

44 | 14 | 57 | 0 |

0 | 0 | 18 | 26 |

18 | 7 | 0 | 11 |

(-1) |

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

There are 3 lines required to cover all zeros:

8 | 21 | 0 | 34 | |

44 | 14 | 57 | 0 | x |

0 | 0 | 18 | 26 | x |

18 | 7 | 0 | 11 | |

x |

**Create additional zeros**

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

1 | 14 | 0 | 27 |

44 | 14 | 64 | 0 |

0 | 0 | 25 | 26 |

11 | 0 | 0 | 4 |

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

There are 4 lines required to cover all zeros:

1 | 14 | 0 | 27 | x |

44 | 14 | 64 | 0 | x |

0 | 0 | 25 | 26 | x |

11 | 0 | 0 | 4 | x |

**The optimal assignment**

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

1 | 14 | 0 | 27 |

44 | 14 | 64 | 0 |

0 | 0 | 25 | 26 |

11 | 0 | 0 | 4 |

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

36 | 50 | 28 | 62 |

80 | 51 | 93 | 36 |

73 | 74 | 91 | 99 |

89 | 79 | 71 | 82 |

The optimal value equals 216.

HungarianAlgorithm.com © 2013-2018