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:

48 | 71 | 97 | 44 |

11 | 79 | 89 | 2 |

6 | 30 | 74 | 96 |

73 | 62 | 15 | 54 |

**Subtract row minima**

We subtract the row minimum from each row:

4 | 27 | 53 | 0 | (-44) |

9 | 77 | 87 | 0 | (-2) |

0 | 24 | 68 | 90 | (-6) |

58 | 47 | 0 | 39 | (-15) |

**Subtract column minima**

We subtract the column minimum from each column:

4 | 3 | 53 | 0 |

9 | 53 | 87 | 0 |

0 | 0 | 68 | 90 |

58 | 23 | 0 | 39 |

(-24) |

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

There are 3 lines required to cover all zeros:

4 | 3 | 53 | 0 | |

9 | 53 | 87 | 0 | |

0 | 0 | 68 | 90 | x |

58 | 23 | 0 | 39 | x |

x |

**Create additional zeros**

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

1 | 0 | 50 | 0 |

6 | 50 | 84 | 0 |

0 | 0 | 68 | 93 |

58 | 23 | 0 | 42 |

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

There are 4 lines required to cover all zeros:

1 | 0 | 50 | 0 | x |

6 | 50 | 84 | 0 | x |

0 | 0 | 68 | 93 | x |

58 | 23 | 0 | 42 | x |

**The optimal assignment**

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

1 | 0 | 50 | 0 |

6 | 50 | 84 | 0 |

0 | 0 | 68 | 93 |

58 | 23 | 0 | 42 |

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

48 | 71 | 97 | 44 |

11 | 79 | 89 | 2 |

6 | 30 | 74 | 96 |

73 | 62 | 15 | 54 |

The optimal value equals 94.

HungarianAlgorithm.com © 2013-2019