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:

98 | 61 | 74 | 32 |

98 | 42 | 15 | 72 |

9 | 87 | 67 | 76 |

58 | 86 | 70 | 57 |

**Subtract row minima**

We subtract the row minimum from each row:

66 | 29 | 42 | 0 | (-32) |

83 | 27 | 0 | 57 | (-15) |

0 | 78 | 58 | 67 | (-9) |

1 | 29 | 13 | 0 | (-57) |

**Subtract column minima**

We subtract the column minimum from each column:

66 | 2 | 42 | 0 |

83 | 0 | 0 | 57 |

0 | 51 | 58 | 67 |

1 | 2 | 13 | 0 |

(-27) |

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

There are 3 lines required to cover all zeros:

66 | 2 | 42 | 0 | |

83 | 0 | 0 | 57 | x |

0 | 51 | 58 | 67 | x |

1 | 2 | 13 | 0 | |

x |

**Create additional zeros**

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

65 | 1 | 41 | 0 |

83 | 0 | 0 | 58 |

0 | 51 | 58 | 68 |

0 | 1 | 12 | 0 |

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

There are 3 lines required to cover all zeros:

65 | 1 | 41 | 0 | |

83 | 0 | 0 | 58 | x |

0 | 51 | 58 | 68 | |

0 | 1 | 12 | 0 | |

x | x |

**Create additional zeros**

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

65 | 0 | 40 | 0 |

84 | 0 | 0 | 59 |

0 | 50 | 57 | 68 |

0 | 0 | 11 | 0 |

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

There are 4 lines required to cover all zeros:

65 | 0 | 40 | 0 | x |

84 | 0 | 0 | 59 | x |

0 | 50 | 57 | 68 | x |

0 | 0 | 11 | 0 | x |

**The optimal assignment**

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

65 | 0 | 40 | 0 |

84 | 0 | 0 | 59 |

0 | 50 | 57 | 68 |

0 | 0 | 11 | 0 |

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

98 | 61 | 74 | 32 |

98 | 42 | 15 | 72 |

9 | 87 | 67 | 76 |

58 | 86 | 70 | 57 |

The optimal value equals 142.

HungarianAlgorithm.com © 2013-2018