Add Hungarian Algorithm Implementation in C #1666
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
issue solved #1569
Pull Request: Add Hungarian Algorithm Implementation in C
Description
This PR introduces an implementation of the Hungarian Algorithm (also known as the Kuhn-Munkres algorithm) in C to solve the assignment problem. The assignment problem is widely used in optimization, scheduling, and resource allocation, aiming to minimize the total cost of assigning tasks to workers, where each worker is assigned exactly one task, and each task is completed by only one worker.
Implementation Details
u
andv
: Dual variables used to manage potentials for optimal assignment.p
andway
: Arrays used for tracking the optimal path and backtracking in the matching process.minv
andused
: Arrays to manage minimum values and visited status during the assignment process.Code Structure
hungarian_algorithm
: Main function that implements the Hungarian Algorithm using matrix reduction and optimization techniques.min
: Helper function to find the minimum of two values.main
: Initializes the cost matrix and invokes thehungarian_algorithm
function, which calculates and prints the minimum cost and the optimal assignment.Example Output
Using the predefined 4x4 cost matrix:
Sample program output:
This result provides an assignment of workers to tasks that minimizes the overall cost.
Testing
N
constant and cost matrix.Future Improvements