This repository contains an implementation of the Hungarian Algorithm for solving the assignment problem, where the goal is to minimize the total cost of assigning tasks to agents. The program reads a cost matrix from a CSV file, reduces it, and determines the optimal assignment while providing a step-by-step visualization of the process.
The following Python libraries are required to run the program:
rich: For visualizing the matrix in the terminal.- Standard Python libraries like
csvandexceptions.
To install the required dependency, run:
pip install rich - Clone the repository:
git clone https://github.com/your-username/hungarian-algorithm.git
cd hungarian-algorithm - Prepare your cost matrix in a CSV file (e.g.,
tableau.csv) with values separated by semicolons (;). Example:
4;1;3
2;0;5
3;2;2
- Run the script:
python main.py - The program will:
- Read the matrix from the CSV file.
- Display the reduced matrix after row and column adjustments.
- Show the assignment process with zeros encircled (green) or barred (red).
- Calculate and display the total cost of the optimal assignment.
├── main.py # Main script implementing the algorithm.
├── tableau.csv # Sample input file (cost matrix).
├── README.md # Documentation.
When provided with the following input matrix:
4;1;3
2;0;5
3;2;2
The program outputs:
- The reduced matrix.
- The assignment process with zero markings.
- The total cost of the optimal assignment.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to open issues or submit pull requests to improve this project.