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:

67 | 44 | 41 | 55 |

79 | 88 | 81 | 55 |

34 | 92 | 65 | 27 |

11 | 41 | 69 | 43 |

**Subtract row minima**

We subtract the row minimum from each row:

26 | 3 | 0 | 14 | (-41) |

24 | 33 | 26 | 0 | (-55) |

7 | 65 | 38 | 0 | (-27) |

0 | 30 | 58 | 32 | (-11) |

**Subtract column minima**

We subtract the column minimum from each column:

26 | 0 | 0 | 14 |

24 | 30 | 26 | 0 |

7 | 62 | 38 | 0 |

0 | 27 | 58 | 32 |

(-3) |

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

There are 3 lines required to cover all zeros:

26 | 0 | 0 | 14 | x |

24 | 30 | 26 | 0 | |

7 | 62 | 38 | 0 | |

0 | 27 | 58 | 32 | x |

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:

26 | 0 | 0 | 21 |

17 | 23 | 19 | 0 |

0 | 55 | 31 | 0 |

0 | 27 | 58 | 39 |

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

There are 3 lines required to cover all zeros:

26 | 0 | 0 | 21 | x |

17 | 23 | 19 | 0 | |

0 | 55 | 31 | 0 | |

0 | 27 | 58 | 39 | |

x | x |

**Create additional zeros**

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

45 | 0 | 0 | 40 |

17 | 4 | 0 | 0 |

0 | 36 | 12 | 0 |

0 | 8 | 39 | 39 |

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

There are 4 lines required to cover all zeros:

45 | 0 | 0 | 40 | x |

17 | 4 | 0 | 0 | x |

0 | 36 | 12 | 0 | x |

0 | 8 | 39 | 39 | x |

**The optimal assignment**

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

45 | 0 | 0 | 40 |

17 | 4 | 0 | 0 |

0 | 36 | 12 | 0 |

0 | 8 | 39 | 39 |

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

67 | 44 | 41 | 55 |

79 | 88 | 81 | 55 |

34 | 92 | 65 | 27 |

11 | 41 | 69 | 43 |

The optimal value equals 163.

HungarianAlgorithm.com © 2013-2021