Marriage algorithm Notes

Source: Internet
Author: User

Marriage algorithm

Once thought of similar problems, marriage algorithm is about couples, I think is also about the couple side. At the time, the idea was: if everyone put their favorite people out of a place to list, for others to refer to, there is a lot less failure of the confession and show love. Boys can look at the ranking of girls in the rankings to decide to chase not chase. But the idea is that this is the end, without thinking about how to make everyone happy when the working set becomes a ring from a single chain.

Marriage algorithm is proposed by Gale and Shapley, regardless of whether the version is the employer and the employee or the couple, now we only discuss the couple, discuss another can also, which contains the conditions are similar. To arrange a match in a situation where everyone knows how to rank. To make marriage stable, there is a need for a stable mechanism to make everyone have a stable marriage.

A stable marriage requires a perfect match and stability. Perfect match requires that everyone will eventually marry someone without a single, monogamous wife. The stable match requirement cannot occur under an existing match: in Match (M1,W1) and (M2,W2) two pair match, M1 compared to W1 prefer W2, and W2 prefer M2 compared to M1, otherwise there will be derailment or elope situation.

In the G-S algorithm, the basic idea is as follows, there are three male and female states: free, dating, married. Make a match according to the following rules

· At first, everyone was free, and the first woman to be ranked in the top of his list of free men, M,w immediately became a dating state.

· Dating the woman can be expressed by other free men, if the free male than the existing date in the top ranking, then abandon the existing appointment, and the free man into the dating relationship (M1,W). Free men will continue to follow the ranks of the woman to vindicate, until the end, but will not abandon the existing date.

· Finally, everyone enters the dating state, when all the appointments become married and the status becomes married.

An algorithm that looks fairly simple, if represented in code form, requires only a few loops:

M∈m,w∈w, respectively, the male, the woman.

Initialize all the m∈m,w∈w for free

While there is a man m is free and has not confessed to all the women

If the woman who does not declare in the men's M priority list is the woman who has the highest ranking, W

If Lady W for Free

(m,w) Enter the status of the appointment;

Else Ms. W is dating M1.

If Ms W prefers m1,then men m to remain single, (W,M1) love status unchanged;

If Ms W prefers m,then men M1 into single, (w,m) into a state of love;

To the end of the loop, output all matching results.

Although the g-s algorithm looks fairly simple, we are not sure that the algorithm will return a perfectly stable match, and we need to prove our point of view:

① first to prove that the G-S algorithm returns a perfect match result: first of all to affirm in the men again and again after the confession, enter the date of the status of the men and women to increase, because only better men pursue the woman, the woman will abandon the existing date, all the woman is in the dating state. There is no one man m free, but all the women are confessed. Because if all the confessions of the woman to enter the status of the date, all the men need to enter the status, and the premise that a man to all the ladies are confessed but still in the single contrary. That is, at the end of all loops, a perfectly matched result is obtained.

② re-g-s algorithm returns a stable matching result: first we determine whether it is stable from an existing set of appointments. When the first man confessed to the first woman there Was (m,w), apparently stable, because no other date object made the existing appointment unstable. If a new matching object appears (M1,W1), is it still stable? First M1 not to W vindicate, to prove that men M1 rankings on the table W1 ranked higher than W; or M1 after the declaration to W, W rejected M1, because the rankings of the table m ranked higher than M1. Both cases are stable because the woman chooses the best among the men who are currently being pursued, making the match stable. Each subsequent confession also follows this rule so that the match has been stable. Combined with ①, the algorithm will eventually return a perfectly stable match result.

After returning a perfectly stable algorithm, we would like to think that the perfect and stable match result is unique. We consider this situation:

Priority table for M1: W1 W2

Priority table for M2: W2 W1

Priority table for W1: M2 M1

Priority table for W2: M1 m2

The perfect stable match given in the g-s algorithm is (M1,W1), (M2,W2). But we see (M1,W2), (M2,W1) is also stable. Just the g-s algorithm gives only one of several stable matches.

Did not see the results before, it seems that men in the g-s algorithm to eat a big loss, because the woman is always thrown away, in the woman has a more like the man vindicate, dropped the existing date, with the confession of the person dating.

In this example, the g-s algorithm gives a matching result that shows that men are compensated for what they want with their favorite lady, but the lady has no choice but to ' marry, marry the dog with the dog '. The man chooses ' I love the person ', but the person whom I love does not like me, but the woman chooses ' the person who loves me ', but I do not like the person who loves me. So, the g-s algorithm is more biased towards men, because women are forced to accept. It is not in vain for men in this long confession process of hardship. We can consider a more extreme situation where the first choice on all men's rankings is different, regardless of the woman's table, and the result is certain. Because all the men after the first confession have been the favorite lady, will not be a confession, there will be no change in matching results. The truth is that the lady ate a big loss.

So to understand in a deeper sense why this is the case, why it seems that men have been abandoned by the woman but the algorithm is biased towards men.

In the algorithm, it is certain that the woman will succeed in her first confession. This means that there is no lower limit to the female spouse, her sorting table only when the expression can be expressed, and in the absence of the confession, she can not take the initiative to vindicate, in all the matching results of the women's initiative almost lost. Men, however, have been looking for the best effective date in the sort table from top to bottom. All the women who ranked higher than the existing ones rejected the man, and the woman did not refuse the highest ranking among the men. So the g-s algorithm for Men is the best companion for all stable matches.

The fact that the g-s algorithm gives a stable matching result is the worst of all possible matching men's results, as shown below.

Give three definitions: effective partner, best partner, worst partner. An effective companion is a partner who can form a stable match, the best partner is the highest of the effective partner, and the worst partner is the lowest. Obviously the g-s algorithm gives the best companion for men. We use the law to give proof: assuming that the existence (w,m) makes m not the worst effective companion of W, in the match given by the g-s algorithm, the man is not the worst partner of the lady, then there is a couple where w is paired with a M1 that is more disliked than M, and M is paired with another woman W1. Because W is the best effective companion for M, W1 is an effective companion for M, and we can find that it should be w instead of W1. So getting (M,W) is an unstable pairing. This match is not stable. So the g-s algorithm gives a stable matching result which is the worst of all possible matching men's results.

The significance of the g-s algorithm in real life lies in knowing the list of needs of the existing population. To achieve the highest overall expectations. And this is a very simple way, simply so that you do not have to understand the various details of each person's preferences, just to take their sort of table out, according to the algorithm can certainly get a stable result that everyone is satisfied.

Before the g-s algorithm was proposed, the United States began using this method to arrange work for medical students, known as the National Residency Matching program. The hospitals have never rejected the best candidates from the college and indicated that they could be hired, and then after receiving the notice from the hospital, the system automatically assigns him to the highest-intended hospital according to the desired form and rejects other engagements until the end of the cycle. In the end, all students can be assigned to work. But at that time just used the algorithm, do not know the stability of the algorithm, just feel that the algorithm is reasonable. Actually the algorithm is really reasonable. It did solve the problem of physician matching project at that time.

G-s algorithm can be really used in marriage, such as male and female Blind Date column, as the organizer of the column, just let the men and women in the beginning to understand each opposite sex, to the opposite sex ranking, and then according to the algorithm with men and women's sorting table automatically can be derived from N to stable couples. Save time and effort, hundreds of pairs of couples estimated a few seconds or less time by the algorithm. When people question the high-quality matching efficiency of this algorithm, the G-S algorithm is proved to be a stable match.

After sorting out the g-s algorithm, I was wondering if this algorithm could be used to decide the college entrance exam volunteer problem. After the college entrance examination, everyone has their own achievements. Then the school gives all the students the rankings, because the college entrance exam results are the default rankings of the school to students. Students then rank the university according to their preference. At this time, the students act as the marriage algorithm of the men, and continue to have not refused their favorite school to indicate the application to enter the university. But the university is not like the marriage algorithm of the lady can only accept a man. Universities can determine how many students can be accommodated according to their admissions plans. But the move does not break the loop algorithm. Students are allowed to enter the university when they are not enrolled. In all applicants, the highest n students were selected as students of the university (n is the number of students enrolled in the University Enrollment program) and other applications were rejected. Students who have not been admitted to a university continue to apply to their favorite university. Until the end of the final cycle, all the students found the university (if the total number of admissions programs in all universities is greater than the total number of students).

In this g-s algorithm also solves the university Entrance examination volunteer question, but we did not consider the school to divide the specialized question, if we put the school each profession as the marriage algorithm one object also may solve the multi-professional question. In fact, it's not that easy to operate. Because the amount of information to collect is soaring, each student has to rank all the majors in all universities. Then the matching results are obtained according to the G-S algorithm.

Although it takes a lot of time to collect the data, it perfectly solves the problem of volunteering, because the existing volunteer fills the students ' free will to a great extent. If the students give all sorts of choices instead of just a few volunteers, it is obvious that the fairness of the students has been improved.

The G-S algorithm is extended to a deeper, g-s algorithm can solve many opposing multi-individual and multi-choice competition problem. The opposite refers to all the objects of the atmosphere two camps, such as men and women, students and universities, employers and staff. Although there is a choice and selection of the pros and cons of the problem. Many individuals mean that there are many individuals in each faction, and there are many bases. Multi-choice means that each individual has its own sequence of choices for an individual in another camp. Competition refers to the selection of the number of requests to reach the upper limit, will be the choice of the best left, the remaining refusal.

It is undeniable that the g-s algorithm is unfair, because the result of the selection is the best of all matching results, the result of the selection is the worst of all matching results. So the use of this algorithm in real life should be somewhat scruples. But the revelation that g-s to us is not only so.

In life the g-s algorithm is not very common in use. Or not in strict enforcement, because the individual does not have a very definite camp in the choice and the chosen side. But this just makes life full of unknowns and miracles. Few people willingly wish to be chosen for a lifetime, to a large extent, give up their right to choose. But there are not many people who would like to pursue all of their favorite things to determine the best choice they can achieve. It may be sad, but it should be life.

According to the G-S algorithm, we should think, in the pursuit of things in life to try more, you always wait for the opportunity to appear and then choose the best, but not to pursue their own. The final result is to act as the chosen party in the g-s algorithm, and finally get the worst of all the choices you can get. All attempts are not futile, after you are rejected, you are physically and mentally exhausted, get the best. Maybe you can't try every choice you like, but every time you try you will give you a better position.

Finish.

Marriage algorithm Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.