• 沒有找到結果。

A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM

N/A
N/A
Protected

Academic year: 2021

Share "A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM"

Copied!
9
0
0

加載中.... (立即查看全文)

全文

(1)

BIT 24 (1984), 308 316

A P A R A L L E L A L G O R I T H M T O S O L V E T H E S T A B L E M A R R I A G E P R O B L E M

S. S. TSENG and R. C. T. LEE

Institute of Computer Engineering, Institute of Computer and Decision Sciences,

College of Engineering, National Tsing Hua University',

National Chiao Tung University, Hsinchu, Taiwan, Republic of China Hsinchu, Taiwan, Republic of China

Abstract.

In this paper a parallel algorithm to solve the stable marriage problem is given. The worst case performance of this algorithm is stated, A theoretical analysis shows that the probability of the occurrence of this worst case is extremely small. For instance, if there are sixteen men and sixteen women involved, then the probability that the worst case occurs is only 10 -4s. Possible future research is also discussed in this paper.

I. Introduction.

In this paper, we are concerned with the stable marriage problem [Gale and Shapley 1962, McVitie and Wilson 1970, McVitie and Wilson 1971, Wilson 1972, Allison 1983]. We shall show that this problem can be solved by a divide- and-conquer approach [Bentley 1980]. Using this approach, a parallel algorithm is proposed in this paper.

It is pointed out in this paper that in the worst case, our parallel algorithm does not help too much. However, a theoretical analysis also shows that the probability that this worst case occurs is extremely small. For instance, if there are eight men and eight women, then the probability of the occurrence of the worst case is only 5" 10-16. If the number of men is 16, then that probability is reduced to 10 -45 .

Possible future research is discussed in Section 6.

2. The stable marriage problem.

The stable marriage problem is defined as follows: We are given N men and N women and each man ranks each woman from 1 to N and vice versa. A set of marriages is a one-to-one correspondence of men to women. If there does

(2)

A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM 309 not exist an unmarried pair both preferring each other to their current partners, then we say that this set of marriages is stable.

Before giving an example, we shall denote Mi(Wi) to be Man i (Woman i). This notation will be used for the rest of this paper.

EXAMPLE 2.1. Consider the following case:

MI 1 2 W 1 1 2

M 2 2 1 W 2 2 1

Man's ranking Woman's ranking

The set of marriages ((M1,'W1), (M 2, W2) ) is stable because each man has got his first choice, and each woman her first choice as well.

The set of marriages ( ( M , W2), (M2, I4/"1)) is not a stable one because there exists a man, namely MI, and a woman, namely W~ who prefer each other to their present partners; M~ prefers W1 to W2 and WI prefers M~ to M2.

The stable marriage problem was first introduced by Gale and Shapley [3] and later discussed in [6]. In this paper, we shall show that the stable marriage problem can be solved by a parallel algorithm. Before giving the algorithm formally, let us first show that we can attack the problem by the divide-and- conquer strategy [2].

3. The divide-and-conquer approach to solve the stable marriage problem. The divide-and-conquer approach was discussed in [2]. If a problem can be solved by a divide-and-conquer approach, a solution can usually be obtained rather easily.

Let us consider the following case:

M 1 3 2 1 4 M 2 3 1 2 4 M 3 4 3 1 2 M 4 2 4 3 "1 W 1 1 3 2 4 W z 4 1 3 2 W 3 4 3 1 2 W 4 2 4 3 1

In the matrices above we see that M~ prefers W3 to I4/2, W2 to WI and W1 to

(3)

310 s . s . TSENG AND g. C. T. LEE

We first divide the problem into four subproblems. Each sub-problem contains only one man. Thus each man can propose his choice as follows:

Pair 1 (M1, I4/3) P a i r 2 (M2, W3) Pair 3

(M3, W4)

P a i r 4 (M4, W2)

Having obtained four sub-solutions, we shall now try to merge them into one solution. The first stage is to merge Pair 1 with Pair 2 and Pair 3 with Pair 4 as illustrated below:

t

1

I

1

[

9.

]

[(M3, W4),(M4, W2) ]

...

For the pairs (M 3, I4/4) and (M4, I4/2), since different men have chosen different women, we may simply combine these two pairs. F o r (M 1, 14/3) and (M2, W3), note that both men have chosen the same woman. We therefore have to do something. So far as W3 is concerned, she prefers M 1 to M2. Therefore, I413 accepts M1 and rejects M 2. M 2, the rejected man, proposes his next best choice, namely WI. Tht/s our solution is now as follows:

I M,,W )I

I

I

I

t

I

I

I

(M,,W3),(M=,WO

]

[ (M3, W4),(Mn, W2) l

...

The next merging step produces the following solution:

( M , I413) (M 2, I411) (M3, I414) (M,, W2)

Since no two men propose to the same woman, we have got a stable marriage solution.

The generation of initial sub-solutions can be done in parallel. All of the subsequent merging steps can also be executed in parallel. Thus our algorithm is a parallel one.

If sufficient processors are used, within each merging step, many operations can be executed in parallel. Let us now illustrate this point by an example.

(4)

A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM MI 1 4 5 6 2 3 7 8 W1 8 7 6 4 3 5 1 2 M2 1 2 4 8 7 6 3 5 WE 1 5 4 3 6 2 7 8 M 3 3 2 1 4 8 7 5 6 W3 1 3 2 4 7 8 6 5 M , 4 6 7 8 1 3 2 5 W4 4 7 8 2 6 1 3 5 M5 2 3 4 6 7 1 8 5 W5 3 1 2 5 6 8 7 4 M6 2 1 8 6 5 7 3 4 W6 1 2 3 4 5 6 7 8 M7 5 3 1 4 8 6 2 7 W7 2 1 3 5 4 6 7 8 M8 5 7 6 3 1 2 4 8 I418 7 4 2 1 5 6 8 3 311

For the data above, we shall finally produce the following two subsolutions:

Sub-solution:

(M1,W1)

(ME, WE) (M3, W 3) (M4, I4/,) Sub-solution: (Ms, W2) (M6, W1) (MT, W3) (Ms W5) When we merge these two sub-solutions, we Obtain

(MI, WI) (ME, W2) (M3, 14/3) (M,, W4) (Ms, W2) (M6, I4/i) (MT, W3) (Ms, 14f5).

There are three conflicting pairs: M1, M6, M2, M5 ; Ma, MT.

Each pair of men proposes to the same woman.

M1 and M 6 both choose W 1. Since W~ prefers M 6 to M 1, Mt is rejected. Similarly, M2 and M 7 will also be rejected. These three men, M~, M 2 and MT, will all propose to their next best choices.Again, these proposals can be made in parallel.

In the following section, we shall present our algorithm formally.

4. A parallel algorithm to find a male (female) optimal stable solution.

To simplify our discussion we shall assume that there are N = 2" men and N women. A male optimal stable solution is a stable solution where every man is at least as well off under it as under any other stable solutions. A female optimal stable solution is similar except that the women get their best possible choices. In the following we shall give an algorithm which will always produce a male optimal stable solution.

ALGORITHM A.

An algorithm which produces a male optimal stable solution.

Input:

A male ranking matrix and a female ranking matrix.

Output:

A male optimal stable solution.

Step

1: Divide the problem into two sub-problems, by halving the male ranking matrix. Call these two sub-problems P1 and P2-

(5)

312

Step 2 : Step 3 :

A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM

Recursively apply this algorithm to find male optimal stable solutions for P1 and P2- Call these two solutions $1 and $2.

Apply Algorithm B which is a merging algorithm to combine S~ and $2 into S.

In this algorithm, a merging procedure is used. Let us first introduce some definitions.

In a solution, suppose Mi~, .... Mi~ , k >= 2, propose to the same woman W~. Without loss of generality, we shall assume that so far as W~ is concerned~ the ranking of Mi~ is the highest. That is, W~ prefers Mi~ to Mi~, .... Mi~ t o Mi~_t. Then W~ will accept Mi~ and reject M~, . . . . Mik_. We shall say that {Mi~, .... Mi~_~ } is the set of rejected men of W~. In a solution S, let W~ denote the set of women who are proposed to by more than one man. Let R~ be the union of the sets of rejected men of members in V¢~. Then R~ is called the set of rejected men associated with S.

ALGORITHM B.

A merging algorithm which produces a male optimal stable solution out of two male optimal stable sub-solutions.

Input: Two male optimal stable solutions $1 and $2 and their associated

ranking matrices.

Output: A male optimal stable solution which combines S~ and $2.

Step 1 : Let S be the union of S~ and $2.

Step 2: If no two men propose to the same woman in S, then accept S as the solution and return. Otherwise, go to Step 3.

Step 3 : For each man M~ in R~, and for the set of rejected men associated with S,

replace (M i, V¢~) in S by (Mi, Wk) where W k is the next best choice of M i .

Step 4: Go to step 2.

EXAMPLE 4.1. Consider the following case:

M 1 1 4 5 6 2 3 7 8 M 2 1 2 4 8 7 6 3 5 M 3 3 2 1 4 8 7 5 6 M 4 4 6 7 8 1 3 2 5 Ms 2 3 4 6 7 1 8 5 M 6 2 1 8 6 5 7 3 4 M 7 5 3 1 4 8 6 2 7 M 8 5 7 6 3 1 2 4 8 Men's ranking ~ 8 7 6 4 3 5 1 2 ~ 1 5 4 3 6 2 7 8 ~ 1 3 2 4 7 8 6 5 ~ 4 7 8 2 6 1 3 5 ~ 3 1 2 5 6 8 7 4 ~ 1 2 3 4 5 6 7 8 ~ 2 1 3 5 4 6 7 8 ~ 7 4 2 1 5 6 8 3 Women'sranking

(6)

A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM 313 The merging steps are illustrated as follows:

I

t

I (3,3)(4,4) l

1

I

1 (111)(2'2)(3'3)(4'4) i

1

[ <5,2)<6,1) I

I

I

I

I

1(5,2)(6,1)(7,3)(8,5)]

I

] ( 1 , 5 ) ( 2 , 8 ) ( 3 , 3 ) ( 4 , 4 ) ( 5 , 2 ) ( 6 , 6 ) ( 7 , 1)(8,7) ]~

It can be easily seen that the solution obtained by using Algorithm A is the male optimal stable solution.

5. The performance of Algorithm A.

In this section, we shall present the probability that the worst case occurs when our parallel algorithm is employed. Our result is based upon a worst case analysis of the McVitie-Wilson algorithm [6, 7].

Wilson [8] showed that the maximal number of proposals to obtain the male optimal stable solution is N 2 - N + l when the McVitie-Wilson algorithm is used. Besides, he also showed that for the problem sizes (N) 5, 10, 15, 20, 25, 30, 40 and 50, the theoretical maximum (N 2 - N + 1) is much larger than the actual maxima which were obtained by running 1000 random sets of data for each N. We shall show that the probability that the worst case occurs is of the order

CN-2N+~e-N

when the McVitie-Wilson algorithm is used. EXAMPLE 5.1. Consider the following case:

M 1 1 7 6 5 4 3 2 8 W1 7 6 5 4 3 2 1 8 M2 2 1 7 6 5 4 3 8 W2 1 8 7 6 5 4 3 2 M3 3 2 1 7 6 5 4 8 I4:3 2 1 8 7 6 5 4 3 M4 4 3 2 1 7 6 5 8 I4:4 3 2 1 8 7 6 5 4 M5 5 4 3 2 1 7 6 8 W5 4 3 2 1 8 7 6 5 M6 6 5 4 3 2 1 7 8 W~ 5 4 3 2 1 8 7 6 M7 7 6 5 4 3 2 1 8 14:7 6 5 4 3 2 1 8 7 M8 1 7 6 5 4 3 2 8 Wa 8 7 6 5 4 3 2 1

Men's ranking Women's ranking

The male optimal stable solution is (1, 2) (2, 3) (3,4) (4, 5) (5, 6) (6, 7) (7, 1) (8, 8), and the number of men's proposals in this solution is 57. This is a worst case for N equal to 8.

(7)

314 S. S. TSENG AND R. C. T. LEE

By using the sequential algorithm to find the male optimal stable solution, the number of proposals required is at most N 2 - N + 1. NOW, w e are concerned with the number of steps required to obtain the male optimal stable solution by

using our parallel algorithm.

LEMMA 5.1. For a worst case execution of McVitie-Wilson's algorithm the

following two statements are true:

1. Let M k finally propose to this N t h choice W i. Then the N t h column of the male ranking matrix consists only of one woman W i and the ( N - 1 ) t h column consists of all the other N - 1 women.

2. Let M j propose to his (N - 1)th choice I/V,. Then the first choice of W~ must be Mj.

PROOF. It is well known that there is only one m a n M k who will propose to his Nth choice W~ and all of the other men propose to their ( N - 1 ) t h choice women if the worst case occurs by using the McVitie-Wilson algorithm. This means that all of the ( N - 1 ) t h choice women of men, except the ( N - 1 ) t h choice woman of Mk, a r e all distinct and all different from W~. Furthermore, it can be easily seen that W/ has not been proposed to by any man before M k

proposes to her and this proposal must be the last proposal of men. This means that V¢~ must be the Nth choice woman of each man. Thus, we can conclude that Statement 1 is true.

F o r Statement 2, note that M k proposes to his Nth choice W~. Any other man Mj proposes to his ( N - 1)th choice W,. This means that 14/, prefers Mj to all other men. Equivalently, we may say that the first choice of W, is Mj. Thus, Statement 2 is true. •

THEOREM 5.1. I f N 2 - N + 1 proposals are needed in McVitie-Witson" s algorithm to obtain the male optimal stable solution, then the probability that this worst case occurs is o f the order CN-2N+~e -N with 2.5 < C < 3.5.

PROOF. If we are given N men and N women, then each male ranking matrix has probability 1/(N!) N of occurring and so does each female ranking matrix. If the worst case occurs, according to Statement 1 of L e m m a 5.1, there are N possible choices of W~ and N ( N - 1 ) / 2 ( N - 1)! possible choices of column N - 1. Therefore, there are totally N 2 ( N - 1 ) / 2 ( N - 1 ) ! ( ( N - 2 ) ! ) N desirable male ranking matrices. Moreover, according to Statement 2 of Lemma 5.1, the total number of desirable female ranking matrices is N ( ( N - 1 ) ! ) N. Let the probability that the worst case occurs for the McVitie-Wilson algorithm be denoted as Ps.

P, N 2 ( N - 1 ) ( N - 1 ) ! ( ( N - 2 ) ! ) N" N ( ( N - - 1)!) N N 3 ( N - 1 ) ( N - 1)! = 2 ( N ! ) N ( N [)N = 2 ( N - - I)N" N2N

(8)

A PARALLEL ALGORITHM TO SOLVE THE STABLE MARRIAGE PROBLEM 315 It is clear that the worst case may occur by using our parallel algorithm only if N 2 - N + 1 proposals are needed when the McVitie-Wilson algorithm is used.

LEMMA 5.2. The number of steps needed to obtain the male optimal stable solution by using our parallel algorithm is at most N 2 - 2N + [log 2 N].

PROOF. In our parallel algorithm, for the worst case, if there is always only one man in R~, then the parallel algorithm reduces to the sequential algorithm except for the first merging step. It takes [log 2 N] to complete" the first merging step. It takes ( N - 2 ) + ( N - 1 ) ( N - 2 ) = N 2 - 2 N steps to complete the rest of the execution of our parallel algorithm. Thus the complexity of our algorithm is N 2 - 2N + [log 2 N]. •

Example 5.1 is also an example in which the number of steps needed to obtain the male optimal stable solution is N 2 - 2 N + [log 2 N] = 51 by using our parallel algorithm.

LEMMA 5.3. In the worst case of our parallel algorithm the first column of the

male ranking matrix consists of exactly N - 1 women.

PROOF. If the first column of the male ranking matrix consists of N - 2 or less women, then more than one conflict are resolved when the first merging is completed. Therefore, N 2 - 2 N - 1 or less steps are needed to complete the rest of the execution of our parallel algorithm. This result contradicts the assumption that N 2 - 2 N + [log 2 N] steps are needed by our parallel algorithm. Thus, this lemma is proved. •

THEOREM 5.2. The probability that the worst case occurs in the parallel algorithm is less than C N - 2 N + S e -2N with 30 < C < 70, for N > 2.

PROOF. Every worst case which occurs when our parallel algorithm is used corresponds to a worst case of the McVitie-Wilson algorithm, but not vice versa. So the probability that a worst case occurs for our algorithm is not greater than the worst case probability of the McVitie-Wilson algorithm.

According to Lemma 5.3, the number of possible choices of the elements of the male ranking matrix from column 1 to column N - 2 is reduced from ( ( N - 2 ) ! ) N to N ( N - 1 ) / 2 ( N - 1 ) ! ( ( N - 3 ) ! ) N or less. Let the probability that a worst case occurs for our parallel algorithm be denoted by Pp. Then by using Theorem 5.1.,

N ( N - 1 ) ( N - 1 ) ! ( ( N - 3 ) ! ) N

(9)

316 s. s. TSENG AND R. C. T. LEE

T h e o r e m 5.2 indicates that t h e probability that the worst case occurs is extremely small. F o r example, let N be equal to 8. The probability that the worst case occurs is less t h a n 4 . 7 - 1 0 -16 . If N is equal to 16, then that probability is less t h a n 1.3- 10 -45 .

6. Conclusions and future research.

In this paper we have s h o w n t h a t the stable marriage p r o b l e m can be solved by a d i v i d e - a n d - c o n q u e r a p p r o a c h . Because of this, the p r o b l e m can be solved in a parallel fashion.

M u c h research can be d o n e in the future.

(1) The stable marriage p r o b l e m is a special case of the general assignment p r o b l e m [4] in o p e r a t i o n s research. We believe that it will be a p p r o p r i a t e to a t t a c k the general assignment p r o b l e m directly to see if that class of problems can be solved in parallel.

(2) We conjecture that for the worst case; the c o l u m n vectors, except the last one, share the same property, as stated in L e m m a 5.3. We h o p e that we can prove this p r o p e r t y in the future.

(3) T h e average p e r f o r m a n c e o f o u r parallel a l g o r i t h m is quite important. It a p p e a r s to be very difficult to o b t a i n the average performance, a n d we are presently l o o k i n g into this problem.

R E F E R E N C E S

1. L. Allison, Stable marriaoes by coroutines, Information Processing Letters, Vol, 16, No. 2 (Feb. 1983), 61-65.-

2. J. L. Bentley, Multidimensional Divide-and-conquer, Communications of the ACM, Vol. 23, No. 4, (Apr. 1980), 214-239,

3. D. Gale and L. S. Shapley, College admissions and the stability of marriage, Am. Math. Monthly 69 (1962), 9-15.

4. F. S. Hiller and G. J. Lieberman, Introduction to Operations Research, 3rd ed., Holden-Day, San Francisco (1980).

5. D. G. McVitie and L. B. Wilson, Stable marriaoe assignment for unequal sets, BIT 10 (t970), 295-309.

6. D. G. McVitie and L. B. Wilson, The stable marriaoe problem, Communications of the ACM, Vol. 14, No. 7, (July 1971), 48~490.

7. D. G. McVitie and L. B, Wilson, Algorithm 411, Pts. 1-3, Three procedures for the stable

marriaoe problem, Communi~ations of the ACM, Vol. 14, No. 7, (July 1971), 491-492. 8. L. B. Wilson, An analysis" of the stable marriaoe assionment aloorithm, BIT 12 (1972), 569-575.

參考文獻

相關文件

• In the worst case, what is the growth of the function the optimal algorithm of the problem takes Design Step.

Root the MRCT b T at its centroid r. There are at most two subtrees which contain more than n/3 nodes. Let a and b be the lowest vertices with at least n/3 descendants. For such

Using

The execution of a comparison-based algorithm can be described by a comparison tree, and the tree depth is the greatest number of comparisons, i.e., the worst-case

[This function is named after the electrical engineer Oliver Heaviside (1850–1925) and can be used to describe an electric current that is switched on at time t = 0.] Its graph

Write the following problem on the board: “What is the area of the largest rectangle that can be inscribed in a circle of radius 4?” Have one half of the class try to solve this

Teachers may consider the school’s aims and conditions or even the language environment to select the most appropriate approach according to students’ need and ability; or develop

Then, it is easy to see that there are 9 problems for which the iterative numbers of the algorithm using ψ α,θ,p in the case of θ = 1 and p = 3 are less than the one of the