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:

89 | 78 | 45 | 13 |

5 | 39 | 6 | 47 |

4 | 54 | 41 | 26 |

6 | 46 | 67 | 86 |

**Subtract row minima**

We subtract the row minimum from each row:

76 | 65 | 32 | 0 | (-13) |

0 | 34 | 1 | 42 | (-5) |

0 | 50 | 37 | 22 | (-4) |

0 | 40 | 61 | 80 | (-6) |

**Subtract column minima**

We subtract the column minimum from each column:

76 | 31 | 31 | 0 |

0 | 0 | 0 | 42 |

0 | 16 | 36 | 22 |

0 | 6 | 60 | 80 |

(-34) | (-1) |

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

There are 3 lines required to cover all zeros:

76 | 31 | 31 | 0 | x |

0 | 0 | 0 | 42 | x |

0 | 16 | 36 | 22 | |

0 | 6 | 60 | 80 | |

x |

**Create additional zeros**

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

82 | 31 | 31 | 0 |

6 | 0 | 0 | 42 |

0 | 10 | 30 | 16 |

0 | 0 | 54 | 74 |

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

There are 4 lines required to cover all zeros:

82 | 31 | 31 | 0 | x |

6 | 0 | 0 | 42 | x |

0 | 10 | 30 | 16 | x |

0 | 0 | 54 | 74 | x |

**The optimal assignment**

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

82 | 31 | 31 | 0 |

6 | 0 | 0 | 42 |

0 | 10 | 30 | 16 |

0 | 0 | 54 | 74 |

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

89 | 78 | 45 | 13 |

5 | 39 | 6 | 47 |

4 | 54 | 41 | 26 |

6 | 46 | 67 | 86 |

The optimal value equals 69.

HungarianAlgorithm.com © 2013-2020