Assignment Problem Solver

Solve assignment problems using the Hungarian algorithm. Implements the Hungarian algorithm (Kuhn-Munkres) to find optimal one-to-one assignment between…

Implements the Hungarian algorithm (Kuhn-Munkres) to find optimal one-to-one assignment between workers and jobs, minimizing or maximizing total cost in O(n3) time complexity.

What Is the Assignment Problem?

The assignment problem is a fundamental combinatorial optimization problem: given n agents and n tasks with a cost matrix C, find a one-to-one assignment that minimizes (or maximizes) the total cost. It arises in workforce scheduling, job-shop allocation, vehicle routing, and resource matching.

The Hungarian algorithm (Kuhn-Munkres method, 1955) solves the assignment problem in O(n³) time. It works by iteratively reducing the cost matrix through row and column subtractions, then finding an optimal assignment via augmenting paths in a bipartite graph.

For rectangular matrices (more agents than tasks or vice versa), dummy rows or columns with zero cost are appended to make the matrix square. Unassigned agents or tasks are reported separately.

Formula: Minimize Σ C[i][σ(i)] for all i subject to σ being a permutation (one-to-one mapping) Hungarian steps: 1. Subtract row minima 2. Subtract column minima 3. Cover zeros with minimum lines 4. Adjust matrix, repeat until optimal

Example Calculation

Cost matrix: [[9,2,7],[6,4,3],[5,8,1]]. Row reduction → [[7,0,5],[3,1,0],[4,7,0]]. Column reduction → [[4,0,5],[0,1,0],[1,7,0]]. The zeros allow one task per agent: Agent 1→Task 2 (cost 2), Agent 2→Task 1 (cost 6), Agent 3→Task 3 (cost 1). Total cost = 9 — lower than the tempting Agent 2→Task 3, Agent 3→Task 1 pairing (10).

When to Use This Calculator

Common Mistakes to Avoid

How to Interpret Results

Related Standards & References

Frequently Asked Questions

Can the assignment problem handle maximization?

Yes. To maximize, negate all costs (or subtract each entry from the matrix maximum) and then solve the resulting minimization problem. The optimal assignment is the same; only the sign of the objective changes.

What if the number of workers and jobs is not equal?

The algorithm pads the smaller dimension with dummy rows or columns having zero cost. After solving, assignments to dummy entries indicate unassigned workers or jobs. This makes the method applicable to any rectangular cost matrix.

Can the assignment problem handle real-world constraints like worker skills or availability?

Not directly in the basic formulation. However, you can encode infeasible assignments by setting their cost to a very large number (e.g., 999999), effectively preventing the algorithm from selecting them. For complex constraints, consider integer linear programming solvers.