This repository contains a Python implementation of the Stable Marriage Algorithm, a mechanism for solving the stable marriage problem. The algorithm is widely used in the field of matching theory to find a stable matching between two sets of elements, such as job applicants and employers or medical students and residency programs.
The Stable Marriage Algorithm is a mechanism designed to find a stable matching between two sets of elements, each with its own preferences. It ensures that there are no pairs of elements who would both prefer to be matched with each other over their current partners.
To use this Python implementation of the Stable Marriage Algorithm, follow these steps:
-
Clone this repository to your local machine:
git clone https://github.com/MohammadYasinKarbasian/Stable-Marriage.git
-
Run the algorithm by executing the main Python script:
python 'stable marriage.py'
-
Follow the prompts to provide the input data or specify the test file you want to use for matching.
-
The algorithm will perform the matching and display the results.
The Stable Marriage Algorithm works as follows:
-
Two sets of elements, each with their preferences, are given as input.
-
The algorithm proceeds in rounds, where each element in one set proposes to the most preferred element in the other set who has not already rejected them.
-
The receiving elements compare the proposals and either accept the proposal or reject it in favor of a more preferred proposer.
-
This process continues until no more proposals can be made.
-
The result is a stable matching, where no element is incentivized to break their current match in favor of another.
This repository includes four test.txt files containing sample input data for testing the Stable Marriage Algorithm. You can use these files to validate the correctness and performance of the implementation. Each test file includes the preferences of the elements.
- Test1.txt
- Test2.txt
- Test3.txt
- Test4.txt
Contributions to this project are welcome! If you have suggestions for improvements or bug fixes, please open an issue or create a pull request. For major changes, please discuss them in an issue first.
This project is licensed under the MIT License - see the LICENSE file for details.