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:

15 | 88 | 41 | 81 |

32 | 42 | 15 | 85 |

82 | 90 | 41 | 50 |

68 | 45 | 74 | 89 |

**Subtract row minima**

We subtract the row minimum from each row:

0 | 73 | 26 | 66 | (-15) |

17 | 27 | 0 | 70 | (-15) |

41 | 49 | 0 | 9 | (-41) |

23 | 0 | 29 | 44 | (-45) |

**Subtract column minima**

We subtract the column minimum from each column:

0 | 73 | 26 | 57 |

17 | 27 | 0 | 61 |

41 | 49 | 0 | 0 |

23 | 0 | 29 | 35 |

(-9) |

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

There are 4 lines required to cover all zeros:

0 | 73 | 26 | 57 | x |

17 | 27 | 0 | 61 | x |

41 | 49 | 0 | 0 | x |

23 | 0 | 29 | 35 | x |

**The optimal assignment**

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

0 | 73 | 26 | 57 |

17 | 27 | 0 | 61 |

41 | 49 | 0 | 0 |

23 | 0 | 29 | 35 |

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

15 | 88 | 41 | 81 |

32 | 42 | 15 | 85 |

82 | 90 | 41 | 50 |

68 | 45 | 74 | 89 |

The optimal value equals 125.

HungarianAlgorithm.com © 2013-2017