MAS334 Combinatorics

6. Matching problems

A large part of this course will be about matching problems. A typical example is as follows. We have a set J of jobs, and a set P of people. Each person is qualified to do some subset of the jobs. Ideally, we would like to give every person a job that they are qualified to do, in such a way that every person has exactly one job, and every job is filled. Of course this is only possible if the number of jobs is the same as the number of people. If there are more people than jobs, we can still hope to fill every job, leaving some people unemployed. This still might not be possible, if we have a large number of difficult jobs, and not many highly skilled people. If a perfect matching is not possible, we might try to find partial matchings that fill as many jobs as possible. We might also ask how many different partial matchings are possible.

As well as the basic problem mentioned above, there are a number of possible variants. We could have jobs that need a team of people rather than just a single person. We could have a subset of enthusiastic people who really want a job, and we could try to organise the matching so that all of them are employed. We could try to account for the fact that some people are more qualified than others, rather than just distinguishing qualified people from unqualified people.

We can also apply the same mathematical ideas in different contexts. Instead of allocating people to jobs, we could allocate A-level students to university places, or junior doctors to hospitals, or processes to processors in a multiprocessor computer. We could also match romantic partners to each other; some of the earliest mathematical literature on matching was written in terms of this problem. Moreover, there are many purely abstract mathematical applications of the same theory.

Definition 6.1.

A matching problem consists of finite sets A and B, together with a subset EA×B. A row in A×B is a set of the form {a}×B, and a column is a set of the form A×{b}. A partial matching for E is a subset ME that contains at most one element in each row, and at most one element in each column. We say that M is row-full if it meets every row, and column-full if it meets every column.

Example 6.2.

A could be a set of people, B could be a set of jobs, and E could be the set of pairs (a,b) such that person a is qualified for job b. Each person a gives a row {a}×B, and the intersection ({a}×B)E tells us the set of jobs that person a is qualified to do. Each job b gives a column A×{b}, and the intersection (A×{b})E tells us the set of people that are qualified to do job b. Given a partial matching ME, we can allocate job b to person a for every pair (a,b)M. Part of the definition of a partial matching says that ME; this ensures that we only allocate people to jobs that they are qualified to do. Another part of the definition says that every row contains at most one element of M; this ensures that no one has more than one job. The last part of the definition says that every column contains at most one element of M; this ensures that we do not give the same job to more than one person. The matching M is row-full iff everyone gets a job, and it is column-full iff every job is filled.

Example 6.3.

A and B could be two disjoint sets of people, so that everyone in A wants to marry someone from B and vice-versa. Then E could be the set of pairs (a,b) such that a and b would be content to marry each other. A partial matching then gives a set of disjoint compatible couples. The matching is row-full if everyone in A has a partner, and column-full if everyone in B has a partner.

Example 6.4.

Consider again a sports club as in Problem 5.2. Suppose that the committee is supposed to have a Tennis Officer, a Squash Officer and a Badminton Officer. These are required to be three different people, who must be players of the relevant sport. To choose these officers, we can consider an appropriate matching problem. We take P to be the set of members and S to be the set of sports. We then put

E={(p,x)P×S| person p plays sport x }.

Suppose we have a partial matching ME that is column-full. Then M must have the form {(p,t),(q,s),(r,b)} where p is a tennis player, q is a squash player and r is a badminton player, and p, q and r are all different. Thus, we could make p the Tennis Officer, q the Squash Officer and r the Badminton Officer.

Remark 6.5.

We can reformulate the description of a matching problem as follows.

  • For each aA we put Ra={bB|(a,b)E}, and call this the a’th row set for E.

  • For each bB we put Cb={aA|(a,b)E}, and call this the b’th column set for E.

We note that

E ={(a,b)|bRa}={(a,b)|aCb}
Ra ={b|(a,b)E}={b|aCb}
Cb ={a|(a,b)E}={a|bRa}.

Thus, if we know the row sets we can determine the column sets and the set E. Similarly, if we know the column sets then we can determine the row sets and the set E. In the job allocation context of Example 6.2, we just have

Rp ={ jobs that person p is qualified to do }J
Cj ={ people who are qualified to do job j }P.
Example 6.6.

We can give a more specific example of a job allocation problem as follows. We have a set P of people called Ann, Bob, Cath, Dave and Ella, abbreviated a,b,c,d,e. We have a set J of jobs: librarian, musician, nurse, optician, pilot, abbreviated l,m,n,o,p. A typical element of P×J is the pair (Bob,nurse)=(b,n); we will usually just write this as bn for brevity. We now need to specify the set

E={(x,y)| person x is qualified for job y }.

We take

E={al,am,ap,bl,bn,bo,cl,dm,dn,do,dp,ea,eo,ep}.

For example, the pair ap is an element of E, indicating that Ann is qualified to be a pilot. The pair cm is not an element of E, indicating that Cath is not qualified to be a musician.

It is generally more convenient to indicate this information graphically, rather than listing the elements of E explicitly. This can be done in several different ways. In the left hand picture below, the positions in E are marked by white squares, but the positions not in E are marked by black squares. For example, the top left position is al, which is an element of E, indicating that Ann is qualified to be a librarian, so the to left square is white. The middle square is cn, which is not in E, indicating that Cath is not qualified to be a nurse, so the middle square is black. We call this picture the chessboard diagram for the matching problem.

The middle picture is essentially the same as the left hand one, except that we have 1’s (instead of white squares) for the positions in E, and 0’s (instead of black squares) for the positions that are not in E. We call this the incidence matrix for the matching problem.

In the right hand picture, we have a red circle for each person, a blue square for each job, and a green line for each element of E. For example, there is a green line between a and m, reflecting the fact that amE, or that Ann is qualified to be a musician. There is no green line between b and p, reflecting the fact that bpE, or that Bob is not qualified to be a pilot. We call this picture the incidence graph.

As yet another way to represent the same information, we can list the row sets and the column sets:

Ra ={l,m,p} Cl ={a,b,c,e}
Rb ={l,n,o} Cm ={a,d}
Rc ={l} Cn ={b,d}
Rd ={m,n,o,p} Co ={b,d,e}
Re ={l,o,p} Cp ={a,d,e}.

The fact that Rb={l,n,o} means that Bob is qualified to be a librarian, nurse or optician, but not to do any other job. We can read this off by looking for white squares in the second row of the chessboard diagram, or by looking for 1’s in the second row of the incidence matrix, or by looking for nodes in the incidence graph that are connected by an edge to b. The fact that Cp={a,d,e} means that Ann, Dave and Ella (and nobody else) are qualified to be pilots. We can read this off by looking for white squares in the last column of the chessboard diagram, or by looking for 1’s in the last column of the incidence matrix, or by looking for nodes in the incidence graph that are connected by an edge to p.

Example 6.7.

We next discuss graphical representation of partial matchings. Recall that a partial matching is a subset ME that has at most one element in any row, and at most one element in any column. The condition ME means that M corresponds to a subset of the white squares in the chessboard diagram. We can mark this subset by placing a rook on each of the relevant squares. Recall the usual rules of chess: two rooks can attack each other horizontally if they lie in the same row, and they can attack each other vertically if they lie in the same column. Thus, the row and column conditions for a partial matching just say that none of the rooks can attack each other.

For instance, we can consider again the matching problem from Example 6.6. Take M={ap,cl,dn}. This can be shown graphically as follows:

In the chessboard diagram, we have placed rooks in positions ap, cl and dn. The rooks are all in white squares and cannot attack each other, so this is a valid partial matching. In the incidence matrix, we have circled the entries in positions ap, cl and dn. All the circled entries are 1’s, and no row contains more than one circle, and no column contains more than one circle. This is another way to express the fact that we have a valid partial matching. In the incidence graph, we have coloured the edges ap, cl and dn orange, and left them solid, while making the other edges dotted. The fact that the rooks cannot attack each other is reflected by the fact that the solid edges are disjoint.