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
- A production supervisor assigning workers to machines to minimize total processing time or cost
- A project manager allocating team members to tasks based on skill match and effort estimates
- A logistics coordinator assigning delivery vehicles to routes to minimize total travel distance
- A university administrator scheduling exam rooms to courses to minimize conflicts or walking distance
Common Mistakes to Avoid
- Entering costs inconsistently — all values in the cost matrix must use the same unit (dollars, hours, distance); mixing units produces meaningless assignments
- Forgetting to switch between minimize and maximize modes — if you are assigning by profit or preference (higher is better), select maximize; for cost or time (lower is better), select minimize
- Using assignment for problems with multiple assignments per agent — the Hungarian algorithm assigns each agent to exactly one task; if agents can handle multiple tasks, use a different model
- Not handling infeasible pairings — if certain agent-task combinations are impossible, set their cost to a very large number rather than leaving them as zero
How to Interpret Results
- The total cost represents the global optimum — no other one-to-one assignment can achieve a lower (or higher, for maximization) total
- If some rows or columns are listed as unassigned, there are more agents than tasks (or vice versa) — these agents/tasks remain free
- Compare the optimal total against the naive assignment (e.g., row 1 to column 1) to see how much improvement the algorithm provides
Related Standards & References
- Kuhn, H. W. (1955), 'The Hungarian Method for the Assignment Problem', Naval Research Logistics Quarterly — original publication of the algorithm
- Munkres, J. (1957), 'Algorithms for the Assignment and Transportation Problems', Journal of the SIAM — the refinement establishing polynomial-time execution
- Burkard, Dell'Amico & Martello (2009), Assignment Problems (SIAM) — comprehensive modern reference on assignment models and algorithms
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.