On the algorithm of stable and complete marriage

Source: Internet
Author: User

First of all: This article is not a discussion of marital problems, but an example of the marriage problem of daily life as an illustration of an interesting algorithm:Gale-shapley algorithm (delay recognition algorithm), if you feel disappointed, I will express my apologies, but if you are interested, It is recommended that you take a look, especially for a friend who is not yet a GF or BF, and a friend who is about to get married, you will find it useful in explaining the implementation of the algorithm.

In 1962, two mathematicians David Gale and Lloyd Shapely put forward the following questions: Given a number of boys and the same number of girls, each of them has a psychological preference for all the opposite sex. Is there a combination of pairs of men and women that form a stable relationship? The stable combination here means that no two non-partner heterosexual evaluations of each other are higher than those of their respective partners. (It is understandable that such a heterosexual is too easy to get into an affair, so it is some kind of unstable factor.) The further question is, how do you find this stable combination (if it exists) in the case where everyone is known to have a preference order for the opposite sex? You can understand that this is the question that mathematicians asked for matchmaker: given a group of lone men and women, looking for a way to lead the red line to ensure that the apricot in the cradle ....

  1. Stable and complete marriage

The above problem is known as a stable marriage problem. It has a number of possible solutions. In order to convince people that mathematicians are not really so boring, I want to point out that it is indeed an authentic combinatorial mathematical problem with its specific mathematical value. Of course, it also has a lot of other backgrounds and applications, such as the recruitment intermediary between several companies and candidates, "but how can mathematicians let go of a name so nosy?" Let's look at the following example:

There are n women and M-Men in a community. It is assumed that each woman ranks according to her preference for each man as a spouse, without juxtaposition. In other words, this arrangement is purely sequential, and each woman arranges these men in order, "N, similarly, each man also arranges these ladies in order," N, we know that there are n! species in this community that are paired into a complete marriage. Suppose a marriage match exists in women A and B and two men A and B, making

i) A and a marry;

II) B and B marriage;

III) a prefers B (ranking more preferred) rather than A;

IV) B prefers a rather than B.

Well, we think that the complete marriage is unstable. Because under this hypothesis, A and B may run away with others, and they all believe that each has a preference for his new partner than the current spouse. If a complete marriage is not unstable, we call it a stable and complete marriage.

   2. A stable and complete marriage algorithm

2.1   Building a model

A binary graph is used to establish a mathematical model for this problem. The g= (x,,y) is a binary graph where x={w1,w2,w3...wn} is a collection of n-bit ladies, while Y = {m1,m2,m3....mn} is a collection of N-Men. Connect each female-vertex (lady on the left) to each male-vertex (men on the right). The resulting binary graph is complete in the sense that it contains all possible edges between the two vertex sets. corresponding to each edge (WI,MJ) There is a number of p,q, where p represents the position of MJ in the sort of WI for men, Q indicates the position of MJ to the lady in the order of the woman to sort in the WI.  The complete marriage of these ladies and gentlemen corresponds perfectly to the (n-side) of the binary graph G. In notation, it is more convenient to use the model provided by the priority rank evaluation matrix. The matrix is an array of n rows n columns, and n rows correspond to each woman w1,w2,w3....wn,n column corresponding to each man m1,m2,m3...mn. In line I and section J intersection position on behalf of WI to MJ rank and MJ to the WI row of the number of p,q.  A perfect marriage. A set of n positions on the matrix that contains exactly one position for each row and one position for each column. Example 1 makes the n=3, and the priority Rank evaluation matrix is:

M1 m2 M3

W1 1,3 2,2 3,1

W2 3,1 1,3 2,2

W3 2,2 3,1 1,3

Exists 3! = 6 kinds of possible complete marriages. One is

W1<->m1,w2<->m2,w3<->m3

As every woman gets her first choice, the perfect marriage is stable, but every man gets the last choice. The other stable and complete marriage is achieved by having each man get his first choice.

  The basic idea of 2.2 delay recognition algorithm

Problem: For each priority rank evaluation matrix, there is a stable and complete marriage strategy. How to find a stable and complete marriage?

Through the delay recognition algorithm (gale-shapely algorithm)

Start by marking all the women with the loser.

When an unsuccessful woman is present, do the following

1) Each unsuccessful woman chooses a man of his rank who has not yet refused her.

2) Every man who has chosen him, and who has not yet refused, chooses the woman with the highest priority, postpones her decision, and rejects the other women at this time.

Thus, during the algorithm execution, the woman proposed to the man, some men and women engaged, but, if received a better proposal, the man can Huihun.

The algorithm, once the man is engaged, he has been engaged in the state, but her fiancee can change, and for him every change is an improvement. However, the woman was engaged several times during the algorithm's execution, and each time she was told that it led to a less desirable partner.

As long as there is no woman to be rejected, every man is engaged to a woman, and because of the same number, every woman is engaged to the man.

Now, pairing each man with his betrothed woman can get a complete marriage, and it can be proved that this complete marriage is stable.

Consider ladies A and B and men A and B, which is a paired with a, B is paired with B, but a prefers B to a. We proved that B could not be more of a preference than preference B. Because at some stage of the algorithm a B is preferred in A/b, a chooses B, but a is rejected by B by giving a woman a higher priority. However, the woman paired with man B during the algorithm actually has at least the same priority as any woman he refuses to accept. Since a was rejected by B, B must prefer B to a. Therefore, there is no unstable pairing, and the complete marriage is stable.

  2.3 Examples of delay recognition algorithms

Example 2 using the delay recognition algorithm for the priority Rank evaluation matrix

A B c D

A 2,1 3,2 4,1

B 2,4 3,1 4,2

C 2,1 3,3 4,3 1,4

D 1,3 3,4 2,3

The result of the algorithm is:

i) a Select a, b select B,c Select D,d Select A;a Reject D.

II) d Select D,d reject C.

III) c Select A;a reject A.

IV) a SELECT B;b reject B.

V) b Select A; Reject B.

VI) b SELECT C.

In Ⅵ), there is no rejection, so

A<->b b<->c C<->a d<->d

is a stable and complete marriage.

In the deferred recognition algorithm, if we swap the roles of men and women and let men choose women according to their priority, then we get a stable and complete marriage, but marriage may not have to be different from the stable marriage that women choose men to get.

Example 3 uses the deferred recognition algorithm for the precedence rank evaluation matrix in the above example, where men choose women. The result is:

i) a select C,b Select A,c Select B,d Select a

II) A reject D,d select B;b Select D.

III) d Select D.

Complete marriage

A<->c b<->a c<->b d<->d

is stable, and this is the same complete marriage that is obtained by using the algorithm in the opposite way.

In a stable and well-established marriage, a stable, complete marriage is called the best for the woman if she is given at least the same high priority in her sort table as a woman who is given a spouse as a partner than her spouse in every other stable marriage. In other words, there is no stable complete marriage that makes the lady get a spouse with a higher rank in her sort. If a stable and complete marriage is optimal for every woman, it is said that the perfect marriage is the best for women. We use a similar approach to define the best stable marriage for men. However, it is not obvious that a stable and complete marriage is a priority for women and men. In fact, if each woman independently gets all the best mates in a stable marriage and results in a male-female pairing, the conclusion is not obvious (it can be imagined that the results of this approach may result in two women getting the same man). Obviously, there may only be a perfect marriage for women and a perfect marriage with only one man's best.

  The nature of the 2.4 delay recognition algorithm

According to the gale-shapely algorithm, we can certainly get a stable marriage. That is, no matter how the priority tables of the N men and N women are distributed, there is at least one stable marriage match. In the implementation of the "male first" algorithm, a stable marriage match has the following three-point properties:

(1) Men are able to get the best possible companion, as a result: if there are other stable matches, then any male partner in the rankings will not be better than the "male first" results, we say that each male obtains the "good" partner.

(2) Women can only passively step closer to her favorite goal, but in the end often not reach, the result is: if there are other stable matching, then any one of the female partners in the rankings will not be worse than the "male priority" results, we say that each woman gets the "worst" partner.

(3) Regardless of the order in which the men propose, the final result is a stable marriage.

Of course, the implementation of this algorithm is also: "Female priority", the same, the resulting stable marriage match has the corresponding three points of nature:

(1) In all possible stable marriage matches, the result of "female priority" is that each woman gets the "best" partner.

(2) in all possible stable marriage matches, the "female priority" results obtained by each male are the "worst" partner.

(3) Regardless of the order in which women propose, "Women's priority" is ultimately matched by a stable marriage.

4. Concluding remarks

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 any other positions. So again and again until each student is assigned to work. Of course, it was not known at the time that such a process would guarantee the stability of the assignment, but it was intuitively thought to be reasonable.  It was not until 10 that Gale and shapely studied the process systematically, and proposed a stable marriage problem , and proved the correctness of the algorithm. Using stability to evaluate the pairing scheme is really good, but sometimes we meet some other needs, and they correspond to many other problems in the algorithmic world. For example, if we already know the "compatibility" of each pair of men and women, how do we find a pairing scheme that makes the resulting total compatibility maximum? In the field of algorithms, this is called the maximum weight matching problem of binary graphs. For example, if gender differences are not taken into account (for example, a match between a deskmate and a partner), the problem is more complicated, which is usually categorized as a general graph match. These problems have now been found in effective algorithms, life in the application of algorithms everywhere. What we have to do is to lead you from the familiar things around you, to see the infinite charm of the algorithm.

On the algorithm of stable and complete marriage

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.