Following is Gale–Shapley algorithm. Program for stable marriage problem #include Java Linked Lists Mathematical. 002, import java.util.*. The Gale-Shapely algorithm only unmatches a woman if the new proposer is preferred to the existing proposer. Also, to note: List manList= m. The algorithm supplied by the instructor is inconsistent with the Gale-Shapley algorithm used to solve this problem. Was This Post Helpful.
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. Ivy ACCEPTED dan.
A JAVA Program for the Gale-Shapley Algorithm. The Gale-Shapley algorithm was developed to pair men and women who had expressed their individual preferences about one another. Their pairings should result in stable marriages. Windows Xp Professional Sp3 Iso Download Deutsch. A marriage is considered stable if no spouse is motivated to select another.
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. 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 ] ). Prefere ( col, [ hope, eve, abi, dee, bea, fay, ivy, gay, cath, jan ] ). Prefere ( dan, [ ivy, fay, dee, gay, hope, eve, jan, bea, cath, abi ] ). Prefere ( ed, [ jan, dee, bea, cath, fay, eve, abi, ivy, hope, gay ] ).
Prefere ( fred, [ bea, abi, dee, gay, eve, ivy, cath, jan, hope, fay ] ). Prefere ( gav, [ gay, eve, ivy, bea, cath, abi, dee, hope, jan, fay ] ). Prefere ( hal, [ abi, eve, hope, fay, ivy, cath, jan, bea, gay, dee ] ). Prefere ( ian, [ hope, cath, dee, gay, bea, abi, fay, ivy, jan, eve ] ).
Prefere ( jon, [ abi, fay, jan, gay, eve, bea, dee, cath, ivy, hope ] ). Prefere ( abi, [ bob, fred, jon, gav, ian, abe, dan, ed, col, hal ] ). Prefere ( bea, [ bob, abe, col, fred, gav, dan, ian, ed, jon, hal ] ). Prefere ( cath, [ fred, bob, ed, gav, hal, col, ian, abe, dan, jon ] ). Prefere ( dee, [ fred, jon, col, abe, ian, hal, gav, dan, bob, ed ] ). Prefere ( eve, [ jon, hal, fred, dan, abe, gav, col, ed, ian, bob ] ).
Prefere ( fay, [ bob, abe, ed, ian, jon, dan, fred, gav, col, hal ] ). Prefere ( gay, [ jon, gav, hal, fred, bob, abe, col, ed, dan, ian ] ).
Prefere ( hope, [ gav, jon, bob, abe, ian, dan, hal, ed, col, fred ] ). Prefere ( ivy, [ ian, col, hal, gav, fred, bob, abe, ed, jon, dan ] ). Prefere ( jan, [ ed, hal, gav, abe, bob, jon, col, ian, fred, dan ] ). Woman (abi ). Woman (bea ). Woman (cath ).
Woman (dee ). Woman (eve ). Woman (fay ).
Woman (gay ). Woman (hope ). Woman (ivy ). Output: abe + ivy bob + cath col + dee dan + fay ed + jan fred + bea gav + gay hal + eve ian + hope jon + abi these couples are stable what if abe and bob swap. Output: See Java output.
Works with: This solution works for Ada, too, since SPARK code is correct Ada code. The data set package: package Preferences is type Guy_X is (no_guy, abe, bob, col, dan, ed, fred, gav, hal, ian, jon ); subtype Guy is Guy_X range Guy_X'Succ (Guy_X'First ). Guy_X'Last; type Girl_X is (no_girl, abi, bea, cath, dee, eve, fay, gay, hope, ivy, jan ); subtype Girl is Girl_X range Girl_X'Succ (Girl_X'First ). Girl_X'Last; type Extended_Rank is range 0. 10; subtype Rank is Extended_Rank range 1.