Add Gale-Shapley Algorithm for Stable Matching#14376
Closed
signore662-beep wants to merge 3 commits intoTheAlgorithms:masterfrom
Closed
Add Gale-Shapley Algorithm for Stable Matching#14376signore662-beep wants to merge 3 commits intoTheAlgorithms:masterfrom
signore662-beep wants to merge 3 commits intoTheAlgorithms:masterfrom
Conversation
Closing this pull request as invalid@signore662-beep, this pull request is being closed as the files submitted contains an invalid extension. This repository only accepts Python algorithms. Please read the Contributing guidelines first. Invalid files in this pull request: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your change:
This PR implements the Gale-Shapley Algorithm, a Nobel-winning algorithm used to solve the Stable Marriage Problem. It finds a stable matching between two equally sized sets of elements given their ranked preferences.
Key Features:
numpy, nopandas).Why this is a good addition:
While foundational to economics and computer science (used in residency matching for doctors and content delivery networks), a clean, type-hinted implementation is currently missing or needs improvement in the collection.
maths/gale_shapley.py"""
The Gale-Shapley algorithm is a solution to the Stable Marriage Problem.
It guarantees that for every two sets of preferences, a stable matching
always exists such that no two elements would rather be with each other
than their current partners.
"""
from typing import Dict, List, Optional
def stable_matching(
proposer_prefs: Dict[str, List[str]], responder_prefs: Dict[str, List[str]]
) -> Dict[str, str]:
"""
Implements the Gale-Shapley algorithm to find a stable matching.
if name == "main":
import doctest