The Hungarian algorithm, also known as the Kuhn-Munkres algorithm, is a combinatorial optimization algorithm that solves the assignment problem in polynomial time. The assignment problem is the problem of finding the optimal way to assign a set of tasks to a set of agents while minimizing the total cost or maximizing the total profit.
Here is a step-by-step outline of the Hungarian algorithm:
1. Cost Matrix Preparation
Prepare a cost matrix where the element ( c_{ij} ) represents the cost of assigning task ( j ) to agent ( i ). Ensure the matrix is square; if it is not, add dummy rows or columns with zero cost.
2. Row Reduction
For each row of the cost matrix, subtract the smallest element of that row from all elements in the same row. This step ensures that every row has at least one zero.
3. Column Reduction
Similarly, for each column of the cost matrix produced after row reduction, subtract the smallest element of that column from all elements in the same column. This step ensures that every column has at least one zero.
4. Cover Zeros with Minimum Number of Lines
Cover all the zeros in the matrix using a minimum number of horizontal and vertical lines. This involves:
Finding the maximum number of independent zeros (zeros that aren't in the same row or column).
Drawing the least number of lines to cover all these zeros.
5. Test for Optimality
If the minimum number of covering lines is equal to the number of rows (or columns), an optimal assignment exists among the zeros. If not, proceed to the next step.
6. Adjust the Matrix
Find the smallest element not covered by any line. Subtract this element from all uncovered elements and add it to the elements covered by two lines. This adjustment better aligns the assignments and sets the stage for uncovering new potential assignments.
7. Repeat
Repeat steps 4 to 6 until the number of covering lines equals the number of rows or columns in the matrix, at which point an optimal assignment is guaranteed.
8. Optimal Assignment
Identify the optimal assignment from the final matrix of zeros, ensuring that each agent-task pair corresponds to the original cost matrix's minimum cost configuration.
Example:
Suppose you have three tasks and three agents with the following cost matrix:
Cover T3 with a horizontal line for the fourth zero.
We used 3 lines, which is equal to the number of tasks, meeting the optimality condition.
5. Optimal Assignment:
From these zeros, assign:
A1 to T3 (0 cost position in final reduced matrix)
A2 to T2 (0 cost position in final reduced matrix)
A3 to T1 (0 cost position in final reduced matrix)
Summary:
The final assignment (Agent to Task) that minimizes overall costs is:
A1 to T3
A2 to T2
A3 to T1
This assignment minimizes the total cost using the Hungarian algorithm.
Conclusion
The Hungarian algorithm efficiently solves the assignment problem, ensuring minimized costs through systematic row and column reductions, zero-covering, and iterative adjustments. This process guarantees an optimal solution in polynomial time, which is suitable for various optimization scenarios in operational research.
An unbalanced assignment problem occurs when the number of tasks does not equal the number of agents. To solve an unbalanced assignment problem, you can convert it into a balanced problem by adding dummy tasks or dummy agents with zero costs. Here’s a step-by-step guide:
1. Identify if the Assignment Problem is Unbalanced
Check whether the number of tasks is equal to the number of agents. If not, you have an unbalanced assignment problem.
2. Balancing the Cost Matrix
Adding Dummy Agents or Tasks
If the number of agents (rows) is less than the number of tasks (columns): Add extra rows (dummy agents) to the cost matrix.
If the number of tasks (columns) is less than the number of agents (rows): Add extra columns (dummy tasks) to the cost matrix.
The value of the added elements (dummy entries) should be set to zero or a very large number depending on the context, but zero is generally preferred if you are trying to minimize the cost.
Example
Let’s say you have 4 agents and 3 tasks with the following cost matrix (unbalanced):
Follow the covering zeros step by identifying the minimal number of lines required to cover all zeros.
Adjust the Matrix
If the number of lines is equal to the number of rows (or columns), the solution is optimal. If not, adjust the matrix by finding the smallest element not covered by any line, subtract that element from all uncovered elements, and add it to elements covered by two lines. Iterate these steps until the condition is met.
Optimal Assignment
After covering zeros and necessary adjustments, determine the optimal assignment while avoiding assigning dummy roles (if zero was used in dummy tasks, they should be skipped if practical optimization is required).
Conclusion
Once you balance the problem, solving the unbalanced assignment problem becomes straightforward using the Hungarian algorithm. This method ensures finding the minimal cost (or maximizing profit) configuration while efficiently handling different scenarios in operational research.