The Stable Marriage Program ------------------------------- Rob Irving, University of Glasgow --------------------------------- General ------- This is a program designed to solve arbitrary instances of the stable marriage problem [1, 2]. It incorporates the extended version of the Gale-Shapley algorithm first published in [1], and described in detail in [2]. For a given instance of the problem, the program will find both the man-optimal and the woman-optimal stable matching. 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 M - positive integers, numbers of men and women respectively, space-separated -- lines 2..N+1: the men's preference lists, each has form X : A B C ... -- where X is the owner and A, B, C, ... are entries in order; -- lines N+2..M+N+1: the women's preference lists, in the same form -- identifiers are arbitrary strings of up to 20 chaacters, space-separated in the lists The output consists of: -- the original preference lists -- the so-called 'GS lists' -- the preference lists annotated with the man-optimal matching -- a list of the matched pairs for the man-optimal matching -- the preference lists annotated with the woman-optimal matching -- a list of the matched pairs for the woman-optimal matching -- Assumptions -- each preference list is on a single line, with no trailing blanks; -- the number of lists corresponds exactly to the input values of N and M -- 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_sm -- a generic package to represent preference information, sm_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_sm.exe for Windows -- solve_sm.x86 for Unix on PC architecture -- solve_sm.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. D.Gusfield & R.W.Irving, The Stable Marriage Problem: Structure and Algorithms, MIT Press, 1989.