Friday, March 6, 2009

Man, busy week. I started and finished SMP yesterday. Funny since my last blogpost a week ago was about starting on that day. Anyway, it's not too bad. I used a dictionary for the women's preferences. One of the form { man number : rank } where man number is the ... number of the man, and rank is obviously his rank.

Thus a woman ranking her men as 5 2 4 3 1 will generate a dictionary of { 5:1, 2:2, 4:3, 3:4, 1:5 }.

Then we compare her current fiances' ranking to a competing free male's ranking (i.e., dict[single_male_number] < dict[competing_fiance_number]) when determining whether her current engagement will end (if single_male.number is less than competing_fiance.number) or not (if dict[single_male_number] is greater than dict[competing_fiance_number]). I used a dictionary for Woman since women must keep track of their preferences and I didn't feel I'd be able to implement this the way I wanted via a stack. However, a man can "pop()" a preference and if she doesn't accept his proposal, she never will, so it works out for Man in a man-optimal implementation.

I created a Woman, Man, and Stack class and have the algorithm run within a loop of the form: while(there_is_an_unmatched_couple()). This works by iterating through a list of Man to see if any Man is single. Any single male implies there is a single female out waiting for him. If so, find him a mate!

No comments:

Post a Comment