JAVA 3 METHODS STABLE MATCHING - HELPER CLASSES PROVIDED BELOW (Preferences.java & Cost.java). In this problem we will consider a version of. Program to solve the Stable Matching Problem using the Gale-Shapley algorithm. The input to the program will be a text file listing, in order. Import java.io. Stable marriage problem You are encouraged to according to the task description, using any language you may know. Solve the using the Gale/Shapley algorithm. Problem description Given an equal number of men and women to be paired for marriage, each man ranks all the women in order of his preference and each woman ranks all the men in order of her preference. A stable set of engagements for marriage is one where no man prefers a woman over the one he is engaged to, where that other woman also prefers that man over the one she is engaged to. With consulting marriages, there would be no reason for the engagements between the people to change. Gale and Shapley proved that there is a stable set of engagements for any set of preferences and the first link above gives their algorithm for finding a set of stable engagements. Output: HISTORY: abi ACCEPTED abe. Cath ACCEPTED bob. Hope ACCEPTED col. Remove moire pattern photoshop filter tutorials. Ivy ACCEPTED dan. Jan ACCEPTED ed. Bea ACCEPTED fred. Gay ACCEPTED gav. Eve ACCEPTED hal. Hope LEFT col. Hope ACCEPTED ian. Abi LEFT abe. Abi ACCEPTED jon. Dee ACCEPTED col. Ivy LEFT dan. Ivy ACCEPTED abe. Fay ACCEPTED dan. NEWLYWEDS: abi and jon. Bea and fred. Cath and bob. Hope and ian. STABILITY = TRUE. What if ed and hal swapped? NEW-NEWLYWEDS: abi and jon. Bea and fred. Cath and bob. Hope and ian. STABILITY = FALSE. Eve and abe would rather be together than their current partners. Output: engagement: hope col engagement: bea fred engagement: ivy dan engagement: cath bob engagement: abi abe engagement broken: abi abe engagement: abi jon engagement: gay gav engagement: eve abe engagement: jan ed engagement broken: hope col engagement: hope ian engagement: dee col engagement broken: eve abe engagement: eve hal engagement broken: ivy dan engagement: ivy abe engagement: fay dan result: fay dan dee col cath bob hope ian eve hal jan ed abi jon gay gav ivy abe bea fred stable. Exchanging partners of fred and dan ivy abe bea dan fay fred dee col cath bob hope ian eve hal jan ed abi jon gay gav unstable. Dan and fay would prefer each other over their current pairings. Output: Abe is engaged to Ivy Bob is engaged to Cath Col is engaged to Dee Dan is engaged to Fay Ed is engaged to Jan Fred is engaged to Bea Gav is engaged to Gay Hal is engaged to Eve Ian is engaged to Hope Jon is engaged to Abi Stable = Yes Jon & Fred swap partners Stable = No [ ] # This is not optimized, but tries to follow the pseudocode given the Wikipedia entry below. Output: Matchmaking: abi and abe ivy and dan abi dumped abe for jon eve and abe eve dumped abe for hal cath and abe gay and gav jan and ed hope and ian dee and col cath dumped abe for bob ivy dumped dan for abe fay and dan bea and fred Stablility: (all marriages stable) Perturb: engage abi with fred and bea with jon Stablility: eve prefers jon to hal and jon prefers eve to bea gay prefers jon to gav and jon prefers gay to bea fay prefers jon to dan and jon prefers fay to bea bea prefers fred to jon and fred prefers bea to abi [ ]. Output: Engagements: abi accepted abe cath accepted bob hope accepted col ivy accepted dan jan accepted ed bea accepted fred gay accepted gav eve accepted hal hope dumped col and accepted ian abi dumped abe and accepted jon dee accepted col ivy dumped dan and accepted abe fay accepted dan Couples: abi is engaged to jon bea is engaged to fred cath is engaged to bob dee is engaged to col eve is engaged to hal fay is engaged to dan gay is engaged to gav hope is engaged to ian ivy is engaged to abe jan is engaged to ed These couples are stable. What if cath and ivy swap? These couples are not stable. Output: dee is engaged to col fay is engaged to dan eve is engaged to hal gay is engaged to gav bea is engaged to fred jan is engaged to ed ivy is engaged to abe hope is engaged to ian cath is engaged to bob abi is engaged to jon All marriages are stable Engage fred with abi and jon with bea fay likes jon better than dan and jon likes fay better than bea eve likes jon better than hal and jon likes eve better than bea gay likes jon better than gav and jon likes gay better than bea bea likes fred better than jon and fred likes bea better than abi [ ]. Library: XPCE is used for its integrated messaging system.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% facts prefere (abe, [ abi, eve, cath, ivy, jan, dee, fay, bea, hope, gay ] ). Prefere ( bob, [ cath, hope, abi, dee, eve, fay, bea, jan, ivy, gay ] ).
0 Comments
Leave a Reply. |