The Hospital-Resident problem involves finding stable matches between residents (doctors) and hospitals. This program uses an extended version of the Gale-Shapley algorithm, originally developed by Rob Irving1.
- Install the AdaCore GNAT Compiler.
- Build the main program:
gnatmake src/stablematch.adb
- Configure the sample dataset to be generated by editing data/generate_sample_data.py.
- Generate the datafile:
python data/generate_sample_data.py
./stablematch < data.txt
Input is given as text on standard input as follows:
- Line 1: N, M, positive integers, numbers of residents and hospitals respectively
- Lines 2..N+1: the resident preference lists, each has form X : A B C ...
- Lines N+2..M+N+1: the hospital preference lists, each has form X : P : A B C ..., where P is the number of positions available
Output is given as a list of matched pairs in the form (Resident,Hospital) saved to file as output_ro (resident-optimal) and output_ho (hospital-optimal).
- Dan Gusfield & Robert W. Irving, The Stable Marriage Problem: Structure and Algorithms (MIT Press)