Skip to main content

A package containing various matching algorithms, such as stable marriage, hospital-residents, and student-project allocation including the cases with ties/indifference.

Project description

DOI

Algmatch

Algmatch contains implementations of polynomial-time algorithms for matching problems. The full list of support problem is as follow:

  • SM: Stable Marriage
  • HR: Hospital/Residents
    • Resident-optimal algorithm and hospital-optimal algorithm
  • SPA-S: Student Project Allocation with lecturer preferences over students
    • Student-optimal algorithm and lecturer-optimal algorithm
  • SPA-P: Student Project Allocation with lecturer preferences over projects (requires Gurobi)
    • for usage, see this notebook.
  • SR: Stable Roommates
  • SMT: Strong and Super-stable matchings in Stable Marriage with Ties
  • HRT: Hospital/Residents with Ties
    • Strong: Resident-optimal algorithm and hospital-optimal algorithm for strong stability
    • Super: Resident-optimal algorithm and hospital-optimal algorithm for super-stability
  • SPA-ST: Student Project Allocation with lecturer preferences over students and ties
    • Super: Student-optimal algorithm
    • There are no published lecturer-optimal algorithm for super-stability or any published algorithm for strong stability exists at this time.

Requires Python 3.10 or later.

Format data according to the guidelines in this folder.

Installation

Simply run pip install algmatch.

Usage

To import a specific algorithm, use from algmatch import <algorithm>, e.g. from algmatch import SPAS or from algmatch import StudentProjectAllocation. Create a file or dictionary with your instance, following the guidelines in the DATA_FORMAT_GUIDELINES folder. For example,

Importing data:

from algmatch import HR, SM, SPAS

spas_instance = {
    'students': {
        1: [1, 2],
        2: [2, 3],
        3: [3, 1],
        4: [4, 1]
    },
    'projects': {
        1: {
            'capacity': 1,
            'lecturer': 1
        },
        2: {
            'capacity': 1,
            'lecturer': 1
        },
        3: {
            'capacity': 1,
            'lecturer': 2
        },
        4: {
            'capacity': 1,
            'lecturer': 2
        }
    },
    'lecturers': {
        1: {
            'capacity': 2,
            'preferences': [3, 1, 2, 4]
        },
        2: {
            'capacity': 2,
            'preferences': [2, 4, 3]
        }
    }
}

spas_student = SPAS(dictionary=spas_instance, optimised_side="students")
spas_lecturer = SPAS(dictionary=spas_instance, optimised_side="lecturers")

Getting the stable matchings:

spas_2_student_stable_matching = spas_2_student.get_stable_matching()
spas_2_lecturer_stable_matching = spas_2_lecturer.get_stable_matching()

print("SPA 2 student stable matching:"
print(spas_2_student_stable_matching)

print("SPA 2 lecturer stable matching:")
print(spas_2_lecturer_stable_matching)
SPA student stable matching:
{'student_sided': {'s1': 'p1', 's2': 'p2', 's3': 'p3', 's4': 'p4'}, 'lecturer_sided': {'l1': ['s1', 's2'], 'l2': ['s3', 's4']}}
SPA lecturer stable matching:
{'student_sided': {'s1': 'p2', 's2': 'p3', 's3': 'p1', 's4': 'p4'}, 'lecturer_sided': {'l1': ['s1', 's3'], 'l2': ['s2', 's4']}}

See more example usage here.

Further details

  • All algorithms implemented (barring SPA-P) have verification testing
    • Tested by producing random instances
    • Brute force all stable matchings
    • Check algorithm is generating correct stable matchings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algmatch-1.5.0.tar.gz (72.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algmatch-1.5.0-py3-none-any.whl (122.4 kB view details)

Uploaded Python 3

File details

Details for the file algmatch-1.5.0.tar.gz.

File metadata

  • Download URL: algmatch-1.5.0.tar.gz
  • Upload date:
  • Size: 72.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for algmatch-1.5.0.tar.gz
Algorithm Hash digest
SHA256 c36dbfce911e19f7fe8c971230d91664c56c6f5cb2008837b8e60be7897de73d
MD5 839f9b91c4468c6d2ec7425f0b5fa90a
BLAKE2b-256 0df871879e59a1130613190fc8e00aa7398db3505a7fe60a944e6bcf1cb70513

See more details on using hashes here.

Provenance

The following attestation bundles were made for algmatch-1.5.0.tar.gz:

Publisher: python-publish.yml on BenOnTheBoard/algmatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file algmatch-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: algmatch-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 122.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for algmatch-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97b879b520942a4624ade6f207daad91185de0eaad092299c9fa7688203994dc
MD5 bdbbdd96cbc472dd28ec7990473530aa
BLAKE2b-256 241f86ac946afb014d396f9afd78ea18892bd62fdb25d2567d4640f14d745642

See more details on using hashes here.

Provenance

The following attestation bundles were made for algmatch-1.5.0-py3-none-any.whl:

Publisher: python-publish.yml on BenOnTheBoard/algmatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page