The Stable Roommates Program ---------------------------- Rob Irving, University of Glasgow --------------------------------- General ------- This is a program designed to solve arbitrary instances of the stable roommates problem [1, 2, 3]. It incorporates the algorithm first published in [2], and described in detail in [3]. The number of participants can be arbitrary, and need not be an even number. For a given instance of the problem, the program will find a stable matching if one exists, or else will report that no stable matching is possible. The preference lists need not be complete - in other words, participants may class certain others as unacceptable. Nor need they be consistent - X may appear on Y's preference list even although Y does not appear on that of X (but in such a case X and Y cannot, of course, be paired in a stable matching). The participants may be represented by arbitrary identifiers of up to 20 characters in length. Input / output -------------- The program is entirely text-based, reading from standard input and writing to standard output. The required input is as follows: -- line 1: N - a positive integer, the size of the instance (number of participants) -- lines 2..N+1: the preference lists, each has form X : A B C ... -- where X is the owner and A, B, C, ... are entries in order; -- person identifiers are arbitrary strings of up to 20 characters, space-separated in the lists The output consists of: -- the original preference lists -- the so-called 'phase-1 table' -- an indication of whether a stable matching exists -- if so, the preference lists annotated with one such matching -- and a list of the matched pairs -- Assumptions -- each person's list is on a single line, with no trailing blanks -- the number of lists corresponds exactly to the input value of n -- lists need not be complete, nor need they be consistent, but no list contains an identifier that does not have its own list, and no list contains a repeated entry -- each line is terminated by an EOL (end of line) character Source code ----------- The src folder contains the source code, written in Ada 95. It consists of the following: -- a main program, solve_rm -- a generic package to represent preference information, rm_pref_info -- a generic package to represent a table of names, name_table -- a package to represent names, names It is portable, and may be compiled with any Ada 95 compiler. Executable ---------- The bin folder contains executable versions for Windows and for Unix (PC x86 and Sparc Solaris -- solve_rm.exe for Windows -- solve_rm.x86 for Unix on PC architecture -- solve_rm.sparc for Unix on Sparc architecture together with sample input files. DISCLAIMER: this program is not supported, and although it has been subjected to extensive testing, the authors cannot take responsibility for any loss etc. resulting from errors or unexpected behaviour. Copies of the program may be made freely for private study or educational use, provided that the program headers acknowledging the authors are retained. References ---------- 1. D.Gale & L.S.Shapley, College admissions and the stability of marriage, American Mathematical Monthly, 69 (1962), 9 - 15. 2. R.W.Irving, An efficient algorithm for the stable roommates problem, Journal of Algorithms, 6 (1985), 577-595. 3. D.Gusfield & R.W.Irving, The Stable Marriage Problem: Structure and Algorithms, MIT Press, 1989.