Skip to main content

Scarf

Scarf is a python library for solving stable matching problems with couples, where one application is the National Resident Matching Program. The package is named after Herbert Scarf, the inventor of Scarf's lemma and algorithm.

Features

  • Written in python3.
  • Solve for a near feasible stable matching given the preference of doctors and hospitals, and hospital capacities.
  • Generate random doctor hospital instances for simulation purposes.
  • Accelerated with Numba. It is fast!

Accepted input format:

  • Python Lists
  • JSON

Algorithm:

Installation

pip install scarfmatch

Example Usage

import scarf

# An example with single doctors {s0, s1}, couples {c0=(c00, c01) c1=(c10, c11)}, and hospitals {h0, h1, h2} 
single_pref = [[0, 1, 2], # s0's preference on hospitals is h0 > h1 > h2 > unemployment
             [1, 0]] # s1's preference on hospitals is h1 > h0 > unemployment > h2
             # list only the hospitals preferred to unemployment 
couple_pref = [[(0, 0), (1, 1), (1, 0), (0, 1), (2, 2)], # c0's joint preference on hospital pairs
             [(1, 1), (2, 2), (1, -1)]] # c1's joint preference on joint plans for both members
             # for example, (1, 0) stands for "member 0 goes to hospital 1 and member 1 goes to hospital 0"
             # "-1" stands for the option of unemployment
             # list only the options preferred to (-1, -1) (i.e. both unemployed)
hospital_pref = [0, (0, 1), 1, (1, 0), (0, 0), (1, 1)] # all three hospitals have the same preference: s0 > c01 > s1 > c10 > c00 > c11 > vacancy
# If all hospital use the same preference, then hospital_pref is one list containing integers and tuples, where integers represent singles and tuples represent members of couples
# To specify different preference lists for different hospitals, please use a list of lists
# In each list, only specify acceptable doctors to the given hospital
hospital_cap = [2, 3, 1] # capacities of each hospital

S = scarf.create_instance(single_pref, couple_pref, hospital_pref, hospital_cap)
sol = scarf.solve(S) # solves for a possibly fractional stable matching
intsol = scarf.round(sol, S) # perform Nguyen and Vohra's IR algorithm to obtain a near feasible stable matching

print(intsol)

For more examples involving JSON input please refer to the Jupyter Notebooks in the notebooks folder. For more ways to access the matching result, please refer to the docstring of scarf.ScarfSolution.

Support

License

Released under MIT license

Copyright (c) 2019-2023 Dengwang Tang <dwtang@umich.edu>

Release files for scarfmatch 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scarfmatch 0.0.3
File Size Uploaded
scarfmatch-0.0.3.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scarfmatch 0.0.3
File Interpreter ABI Platform
scarfmatch-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 39.2 kB

Release files / scarfmatch-0.0.3.tar.gz

Download URL scarfmatch-0.0.3.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1b431b87f7d60266b72e8710e9e75f6de903d44f30185fcb51d4ebc62761c045
BLAKE2b-256 checksum
How to use checksums
3c76d45e3cd8b9154901a2c80e8444b4d11f01ed55512db3da8692da3970b172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.13

Release files / scarfmatch-0.0.3-py3-none-any.whl

Download URL scarfmatch-0.0.3-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
714df0b0c0800781efd8a62bfa339d89ff6f0d2cde8d473af5551553392fb7c4
BLAKE2b-256 checksum
How to use checksums
aea52f5d043be65be443d3c0eb6ace533874258cb5dd24c5320e28b1537667dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page