Thursday, March 11th at NOON
For this project you will implement the stable marriage problem to pair hands. Every left hand needs a right hand pair. You will write a high up "Hand" class that contains the functionality of all Hands. You will also have 2 derived classes, "LeftHand" and "RightHand" that contain the functionality that each needs to extend from the base class. In a main program, you will read in from an input file a test case that says the number of Hands to create, and specifies each Hand's (both Left and Right) preferences for the other kind of Hand. Then you will implement the stable marriage algorithm to pair your Hands so they live happily ever after. You will also create a Makefile to compile all your C++ files.
The stable marriage problem is a problem of finding a stable matching between 2 matched sets. Given n left hands and n right hands, where each hand has ranked all members of the opposite kind of hand with a unique number between 1 and n in order of preference, match the left and right hands such that there are no 2 hands of opposite kinds who would both rather have each other than their current partners. If there are no such hands, the marriages are "stable".
Here is the algorithm for creating a stable pairing:
function stableMatching {
Initialize all l in L and r in R to free
while exists free left l who still has a right r to propose to {
r = l's highest ranked such right
if r is free
(l, r) become engaged
else some pair (l', r) already exists
if r prefers l to l'
(l, r) become engaged
l' becomes free
else
(l', r) remain engaged
}
}
Hand.h and Hand.cpp) that is the base class for the LeftHand and RightHand classes. The Hand class contains the functionality common to both Left and Right Hand classes. You will also define the LeftHand and RightHand classes (each with a .h and .cpp file) that derive from the Hand class and are more specialized. There should be some difference between the Left and Right Hands! (don't make them empty classes). testSMPHand.cpp that implements the stable marriage algorithm several times over based on the input file - for each case, pairing Left and Right hands based on their preference. Generate output as specified above (no need to write explicitly to a file in your main function). computer% make clean computer% make computer% ./testHand
Hand.h, Hand.cpp, LeftHand.h, LeftHand.cpp, RightHand.h, RightHand.cpp, testSMPHand.cpp, and Makefile. MAKE SURE YOUR NAME IS ON THE TOP OF EACH FILE (except the Makefile)! Use
jbsartor as the grader and assign6 ( assign6Mulligan if it is late) as
the assignment name.
computer% turnin --submit jbsartor assign6 Hand.h Hand.cpp LeftHand.h LeftHand.cpp RightHand.h RightHand.cpp testSMPHand.cpp Makefile
Hand.h Hand.cpp LeftHand.h LeftHand.cpp RightHand.h RightHand.cpp testSMPHand.cpp Makefile