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:

92 | 40 | 78 | 5 |

62 | 81 | 49 | 43 |

95 | 4 | 88 | 52 |

54 | 4 | 59 | 68 |

**Subtract row minima**

We subtract the row minimum from each row:

87 | 35 | 73 | 0 | (-5) |

19 | 38 | 6 | 0 | (-43) |

91 | 0 | 84 | 48 | (-4) |

50 | 0 | 55 | 64 | (-4) |

**Subtract column minima**

We subtract the column minimum from each column:

68 | 35 | 67 | 0 |

0 | 38 | 0 | 0 |

72 | 0 | 78 | 48 |

31 | 0 | 49 | 64 |

(-19) | (-6) |

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

There are 3 lines required to cover all zeros:

68 | 35 | 67 | 0 | x |

0 | 38 | 0 | 0 | x |

72 | 0 | 78 | 48 | |

31 | 0 | 49 | 64 | |

x |

**Create additional zeros**

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

68 | 66 | 67 | 0 |

0 | 69 | 0 | 0 |

41 | 0 | 47 | 17 |

0 | 0 | 18 | 33 |

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

There are 4 lines required to cover all zeros:

68 | 66 | 67 | 0 | x |

0 | 69 | 0 | 0 | x |

41 | 0 | 47 | 17 | x |

0 | 0 | 18 | 33 | x |

**The optimal assignment**

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

68 | 66 | 67 | 0 |

0 | 69 | 0 | 0 |

41 | 0 | 47 | 17 |

0 | 0 | 18 | 33 |

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

92 | 40 | 78 | 5 |

62 | 81 | 49 | 43 |

95 | 4 | 88 | 52 |

54 | 4 | 59 | 68 |

The optimal value equals 112.

HungarianAlgorithm.com © 2013-2018