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:

35 | 58 | 95 | 33 |

37 | 34 | 79 | 70 |

64 | 22 | 24 | 95 |

92 | 6 | 49 | 32 |

**Subtract row minima**

We subtract the row minimum from each row:

2 | 25 | 62 | 0 | (-33) |

3 | 0 | 45 | 36 | (-34) |

42 | 0 | 2 | 73 | (-22) |

86 | 0 | 43 | 26 | (-6) |

**Subtract column minima**

We subtract the column minimum from each column:

0 | 25 | 60 | 0 |

1 | 0 | 43 | 36 |

40 | 0 | 0 | 73 |

84 | 0 | 41 | 26 |

(-2) | (-2) |

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

There are 3 lines required to cover all zeros:

0 | 25 | 60 | 0 | x |

1 | 0 | 43 | 36 | |

40 | 0 | 0 | 73 | x |

84 | 0 | 41 | 26 | |

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:

0 | 26 | 60 | 0 |

0 | 0 | 42 | 35 |

40 | 1 | 0 | 73 |

83 | 0 | 40 | 25 |

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

There are 4 lines required to cover all zeros:

0 | 26 | 60 | 0 | x |

0 | 0 | 42 | 35 | x |

40 | 1 | 0 | 73 | x |

83 | 0 | 40 | 25 | x |

**The optimal assignment**

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

0 | 26 | 60 | 0 |

0 | 0 | 42 | 35 |

40 | 1 | 0 | 73 |

83 | 0 | 40 | 25 |

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

35 | 58 | 95 | 33 |

37 | 34 | 79 | 70 |

64 | 22 | 24 | 95 |

92 | 6 | 49 | 32 |

The optimal value equals 100.

HungarianAlgorithm.com © 2013-2023