Stable marriage problem and Gale-shapley algorithm (RPM)

Source: Internet
Author: User
Tags rounds

What is an algorithm? Whenever someone asks the author such a question, he will always cite this example: if you are a matchmaker, there are a number of single men to ask for help, as well as the same number of single women to come to the marriage. If you already know how these girls rank in every boy's mind, and how boys rank in every girl's heart, how do you pair them?

The best pairing option is, of course, that the other half of each person is just the "First choice". This is perfect, but in most cases it is impossible to achieve. For example, male 1th favorite is female 1th, and female 1th's favorite is not a male 1th, the best choice of two people can not be satisfied at the same time. If several boys liked the same girl most, the boys ' first choice would not be met at the same time. When this ideal pairing scheme is not possible, what is the matching scheme to be satisfactory?

In fact, the object of finding is too perfect is not a good thing, harmony is the key to marriage. If male 1th and female 1th each have each object, but male 1th feel, compared to his present, female 1th is better, female 1th also found that in their own mind, male 1th ranked than the current boyfriend more forward. In this way, these two people may abandon their current object-if this happens, we say that marriage collocation is unstable. As a matchmaker, you know that the introduction of the object is not OK, it is afraid that the relationship is not stable. When pairing with the customer, although not everyone can get the most satisfied, but the collocation must be stable. In other words, for each person, in his mind than his current partner better than the opposite sex, will not think he is a better choice. Now, our question is: Does a stable marriage match always exist? What should I look for?

A failed attempt

For the sake of analysis, we make some arrangements below. We numbered males with letters A, B, and C, numbered 1, 2, and 3 for females. We put all the males from top to bottom on the left, the brackets in the figures indicate the rank of all women in each person's mind, and then put all the women on the right side, using the letters in brackets to indicate their preference for men. Figure 1 shows that 2 men and 2 women in a situation, each man is more like female 1th, but female 1th prefers male B, female 2nd prefers male a. If according to A-1, B-2 to match, then male B and female 1 are more like each other, such marriage collocation is unstable. But if you change the pairing scheme (2), the pairing is stable.

Figure 11 An unstable marriage collocation diagram

Perhaps a lot of people will immediately think of a strategy for finding a stable marriage match: to constantly mend the current collocation scheme. If two people think each other is better than their current partner, let these two people become a pair, the remaining two people who are dumped into a pair.

Figure 21 a stable marriage match

If there are men and women who want to elope, continue to swap their wishes for the couple until eventually all the unstable combinations are eliminated. It is easy to see that the final result of applying this "patching strategy" must satisfy stability, but the problem with this strategy is that it does not necessarily have a "final result". As a matter of fact, repeated adjustments to the collocation scheme as described above may eventually lead to a dead loop, so the strategy is not even guaranteed to come up with a definite scheme, as shown in 3.

Figure 3 Applying a "patching strategy" may result in a dead loop

Gale-shapley algorithm

In 1962, American mathematician David Gale and Lloyd Shapley invented a strategy for finding a stable marriage. Regardless of the number of men and women, and regardless of their preferences, the use of this strategy can always get a stable collocation. In other words, they proved that a stable marriage match always exists. Interestingly, this strategy reflects a lot of real life situations.

In this strategy, the boy will round and round to pursue his favorite woman, the woman can choose to accept or reject his suitors. In the first round, every boy chooses the girl in the first place on his list and confessed to her. At this time, a girl may face the situation there are three: no one to tell her, only one person with her confession, there is more than one person to confess to her. In the first case, the girl doesn't have to do anything, just keep on waiting; in the second case, accept the confession of the person and promise to be a lover for the time being; in the third case, choose from all the suitors the one you like best, promise to make a couple with him temporarily, and reject all the other suitors.

At the end of the first round, some boys already had girlfriends, and some boys were still single. In the second round, every single boy chooses his favorite one from all the girls who have not rejected him, and to her, whether she is single now or not. As in the first round, girls need to choose the best one from the confession and reject the other suitors. Note that if the girl already has a boyfriend, when she meets a better suitor, she must reject her current boyfriend and throw herself into the arms of a new suitor. In this way, some single boys will get their girlfriends, and those who already have girlfriends may become singles again. In each subsequent round, the single boy continues to pursue the next girl in the list, and the girl chooses the best one from all the suitors, including her current boyfriend, and says no to the others. This is going to go on and on until at some point everyone is no longer single, and the next round will not have any new confession to take place, the whole process ends automatically. At this time the marriage collocation must be stable.

Will this strategy be the same as the previous fix, where there is never going to end? No. Here we will show that as the number of rounds increases, there is always a time for everyone to pair. Since at least one boy will confess to a girl in each round, the total number of confessions will increase as the number of rounds increases. If the whole process has not ended up with all the right things for everyone, there will eventually be a boy chasing all the girls. Once a girl has been chased once, it is impossible to be single again. Since all the girls have been chased by the boy, it means that all the girls are not single now, which means that everyone is paired at the moment.

Figure 4 Applying the above strategy, a stable marriage match will be obtained after the Tri-rounds

Next, we need to prove that the matching scheme is really stable. The first thing to notice is that as the number of wheels increases, the object of a boy's quest is always getting worse, and a girl's boyfriend can only get better. Suppose male A and female 1 each have their own object, but compared to the current object, male a prefers female 1. As a result, male a must have confessed to female 1 before. Since female 1 did not end up with male a, indicating that female 1 refused male A, that is to say she has a better than male a boy. This proves that, although two people are not a pair, but all feel that each other than their current partner better, such a situation can never happen.

We put a strategy for solving a problem, or a scheme, or a process, or a series of operational rules, or, more aptly, a set of computational methods called "Algorithms." The above strategy for finding a stable marriage is called the "Gale-shapley algorithm", and some people call it "delay recognition algorithm".

The significance and application of Gale-shapley algorithm

Each algorithm has its practical significance, can give us a lot of inspiration. The big point of the Gale-shapley algorithm is that, as a matchmaker for these men and women, you don't need to figure out a stable marriage match, or even need to know everyone's preferences, just follow this algorithm to organize a male-female pairing activity. All you need to do is to make the algorithm flow as a game rule to tell everyone that the game will automatically get a satisfying marriage match. The whole algorithm can be described simply as: everyone does what they want to do. It's a natural thing for men to start catching up with their favorite girls, and it's in her interest for women to keep choosing the best boys. As a result, everyone will automatically follow the rules of the game without worrying about someone making a false statement about their preferences.

Historically, such "matching games" have really been used, and more interestingly, the application of the algorithm is actually 10 years earlier than the proposed algorithm itself. As early as 1952, the United States began to use this method for medical students to arrange work, which is called the "national Resident matching program." The basic process of pairing is that the hospitals choose the best candidates from the medical students who have not yet rejected the position and send a notice of employment, and when the student receives a notice of employment from each hospital, the system automatically assigns it to the highest desired position based on the form he fills out and rejects the other positions. So again and again until each student is assigned to work. At that time, it was not known that such a process would guarantee the stability of the assignment, but intuitively it was reasonable. It was not until 10 that Gale and Shapley studied the process systematically, and proposed a stable marriage problem, and proved the correctness of the algorithm.

The algorithm has a lot of interesting properties. For example, you might think that this male-to-female rejection is better for men or better for women. The answer is that this option is better for men. In fact, there are often more than one form of stable marriage, but the results of these algorithms ensure that every male partner is ideally suited to all possible stable marriage schemes, and that each woman's partner is the worst of all possible stable marriage schemes. Subject to space limitations, we omit the process of proof.

There are some potential problems with this algorithm. As we have just said, for every woman, the result is the worst of all possible stable collocation. At this point, if there is a woman who knows all the other people's preferences list, after careful calculation, she may find that deliberately refused to the person should not be rejected (temporarily keep a poor person around), perhaps have the opportunity to wait for better results. Therefore, in the real life of the application of this algorithm, we have to consider some possible fraud and game.

The algorithm has some limitations. For example, it could not handle the problem of stable collocation of 2n individuals without gender. A simple application scenario is the problem of dorm allocation: assuming that each dorm has two people, and that every student in the 2n has a preference rating for the rest of 2n-1 students, how to find a stable dormitory allocation? At this point, the Gale-shapley algorithm is no longer available. In fact, there is probably no stable collocation in the problem of dormitory allocation. For example, there are A, B, C, D four people, where a puts B in the first, B puts C in the first, C puts a in the first, and all three of them put D in the end. It is easy to see that at this time there must be no stable dormitory allocation plan. If a, d with the dormitory, B, C with the dormitory, then C will think a is a better roommate (because C put a in the first), and a will think C is a better roommate (because he ranked D in the end). Similarly, B, d with dormitory or C, D with dormitory also are not, so stable dormitory allocation is not there. At this point, it is a more basic problem to redefine the quality of dormitory allocation.

There are many other variants of the marital stability problem, some of which are even NP-complete, and are still not (and unlikely) an effective algorithm. This is a very interesting topic in graph theory, algorithms, and game theory.

http://kb.cnblogs.com/page/511691/

Stable marriage problem and Gale-shapley algorithm (RPM)

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.