Hungarian Method Calculator
Solve any assignment problem with the Hungarian method. Enter the cost matrix to get the optimal assignment, the minimum cost (or maximum profit) and every reduction step.
Hungarian Method Calculator
What Is the Assignment Problem?
In an assignment problem, n workers must be matched to n jobs so that each worker gets exactly one job and each job gets exactly one worker. Every worker-job pair has a cost (time, money or distance). The goal is the matching with the lowest total cost, or the highest total profit. Typical examples are assigning machines to operators, salespeople to regions, or drivers to delivery routes.
Hungarian Method Steps
- Balance the matrix. If the numbers of rows and columns differ, add dummy rows or columns of zeros.
- Row reduction. Subtract the smallest value in each row from every value in that row.
- Column reduction. Subtract the smallest value in each column from every value in that column.
- Cover the zeros. Draw the minimum number of horizontal and vertical lines that cover every zero.
- Optimality test. If the number of lines equals n, go to step 6. Otherwise subtract the smallest uncovered value from all uncovered cells, add it to cells at line intersections, and repeat step 4.
- Assign. Pick one zero in every row and column. These cells give the optimal assignment; add their costs from the original matrix.
Solved Example
Five workers W1 to W5 and five jobs J1 to J5 have the cost matrix loaded in the calculator above. After row and column reduction, four lines cover all the zeros, so one adjustment with the smallest uncovered value is needed. The second test needs five lines, and the optimal assignment is W1 → J5 (7), W2 → J1 (6), W3 → J3 (6), W4 → J2 (9) and W5 → J4 (10), for a minimum total cost of 38.
Maximization and Unbalanced Problems
For profit or score tables, choose Maximize profit. The calculator converts the table into a regret matrix by subtracting each value from the largest one, then applies the same steps. For unbalanced problems, dummy rows or columns with zero cost are added; whoever is matched to a dummy is left unassigned.
Related Methods
The assignment problem is a special transportation problem in which every supply and demand equals 1. You can compare it with the transportation problem calculator (North-West Corner, VAM and MODI) or read the guide to the transportation problem. Any assignment problem can also be written as a linear program and solved with the linear programming calculator.
Frequently Asked Questions
What is the Hungarian method?
The Hungarian method is an algorithm that solves the assignment problem: it assigns n workers to n jobs, one each, so that the total cost is as small as possible (or the total profit as large as possible). It works by reducing the cost matrix until an assignment can be made using only zero cells.
How do I use this assignment problem calculator?
Type the cost matrix with one row per worker and the values separated by spaces or commas. Choose Minimize cost or Maximize profit and press Solve. The calculator shows every reduction step, the covering lines and the optimal assignment with its total.
What if the matrix is not square?
An unbalanced assignment problem has more workers than jobs or more jobs than workers. The calculator adds dummy rows or columns with zero cost to make the matrix square. A worker assigned to a dummy job simply stays unassigned.
How does the calculator solve a maximization assignment problem?
It subtracts every value from the largest value in the matrix to build a regret (opportunity loss) matrix, solves that as a minimization problem, and then reports the total profit from the original matrix.
Why do we draw lines to cover the zeros?
The minimum number of lines that cover all zeros tells you how many independent zeros exist. When that number equals n, an optimal assignment can be made. When it is smaller, the smallest uncovered value is subtracted from uncovered cells and added to cells covered twice to create new zeros.
Is the assignment problem a linear programming problem?
Yes. It is a special case of the transportation problem in which every supply and demand equals 1, so it can also be solved with the simplex or transportation method. The Hungarian method is simply much faster for this structure.