Counting Popular Matchings in House Allocation Problems
We study the problem of counting the number of popular matchings in a given instance. A popular matching instance consists of agents and houses , where each agent ranks a subset of houses according to their preferences. A matching is an assignment of agents to houses. A matching is more popular than matching if the number of agents that prefer to is more than the number of people that prefer to . A matching is called popular if there exists no matching more popular than . McDermid and Irving gave a poly-time algorithm for counting the number of popular matchings when the preference lists are strictly ordered.
We first consider the case of ties in preference lists. Nasre proved that the problem of counting the number of popular matching is #P-hard when there are ties. We give an FPRAS for this problem.
We then consider the popular matching problem where preference lists are strictly ordered but each house has a capacity associated with it. We give a switching graph characterization of popular matchings in this case. Such characterizations were studied earlier for the case of strictly ordered preference lists (McDermid and Irving) and for preference lists with ties (Nasre). We use our characterization to prove that counting popular matchings in capacitated case is #P-hard.
A popular matching problem instance comprises a set of agents and a set of houses. Each agent in ranks (numbers) a subset of houses in (lower rank specify higher preference). The ordered list of houses ranked by is called ’s preference list. For an agent , let be the set of pairs such that the house appears on ’s preference list. Define . The problem instance is then represented by a bipartite graph . A of is a matching of the bipartite graph . We use to denote the house assigned to agent in and to denote the agent that is assigned house in . An agent prefers a matching to a matching if is matched in and unmatched in , or is matched in both and but prefers the house to . Let denote the number of agents that prefer to . We say is more popular than if , and denote it by . A matching is called popular if there exists no matching such that .
The popular matching problem was introduced in  as a variation of the stable marriage problem . The idea of popular matching has been studied extensively in various settings in recent times [1, 14, 12, 10, 8, 11, 13], mostly in the context where only one side has preference of the other side but the other side has no preference at all. We will also focus on this setting. Much of the earlier work focuses on finding efficient algorithms to output a popular matching, if one exists.
The problem of counting the number of “solutions” to a combinatorial question falls into the complexity class #P. An area of interest that has recently gathered a certain amount of attention is the problem of counting stable matchings in graphs. The Gale-Shapely algorithm  gives a simple and efficient algorithm to output a stable matching, but counting them was proved to be #P-hard in . Bhatnagar, Greenberg and Randall  showed that the random walks on the stable marriage lattice are slowly mixing, even in very restricted versions of the problem.  gives further evidence towards the conjecture that there may not exist an FPRAS at all for this problem.
Our motivation for this study is largely due to the similarity of structures between stable matchings and popular matchings (although no direct relationship is known). The interest is further fueled by the existence of a linear time algorithm to exactly count the number of popular matchings in the standard setting . We look at generalizations of the standard version - preferences with ties and houses with capacities. In the case where preferences could have ties, it is already known that the counting version is #P-hard . We give an FPRAS for this problem. In the case where houses have capacities, we prove that the counting version is #P-hard. While the FPRAS for the case of ties is achieved via a reduction to a well known algorithm, the #P-hardness for the capacitated case is involving, making it the more interesting setting of the problem.
We now formally describe the different variants of the popular matching problem (borrowing the notation from ) and also describe our results alongside.
House Allocation problem (HA) These are the instances where the preference list of each agent is a linear order. Let and . In , Abraham et al. give a complete characterization of popular matchings in an HA instance, using which they give an time algorithm to check if the instance admits a popular matching and to obtain the largest such matching, if one exists. The question of counting popular matchings was first addressed in , where McDermid et al. give a new characterization by introducing a powerful structure called the switching graph of an instance. The switching graph encodes all the popular matchings via switching paths and switching cycles. Using this structure, they give a linear time algorithm to count the number of popular matchings.
House Allocation problem with Ties (HAT) An instance of HAT can have applicants whose preference list contains ties. For example, the preference list of an agent could be , meaning, house gets rank 1, houses and get a tied rank 2 and house gets the rank 3. A characterization for popular matchings in HAT was given in . They use their characterization to give an time algorithm to solve the maximum cardinality popular matching problem. We outline their characterization briefly in Section 2 where we consider the problem of counting popular matchings in HAT. In , Nasre gives a proof of P-hardness of this problem. We give an FPRAS for this problem by reducing it to the problem of counting perfect matchings in a bipartite graph.
Capacitated House Allocation problem (CHA) A popular matching instance in CHA has a capacity associated with each house , allowing at most agents to be matched to house . The preference list of each agent is strictly ordered. A characterization for popular matchings in CHA was given in , along with an algorithm to find the largest popular matching (if one exists) in time , where , and is the total capacity of the houses. In Section 3, we consider the problem counting popular matchings in CHA. We give a switching graph characterization of popular matchings in CHA. This is similar to the switching graph characterization for HA in . Our construction is also motivated from , which gives a switching graph characterization of HAT. We use our characterization to prove that it is #P-Complete to compute the number of popular matchings in CHA.
Remark: A natural reduction exists from a CHA instance to an HAT instance. The reduction is as follows. Treat each house with capacity as different houses of unit capacity, which are always tied together and appear together wherever appears in any agent’s preference list. Let the HAT instance thus obtained be . It is clear that every popular matching of is a popular matching of . Hence, for example, an algorithm which finds a maximum cardinality popular matching for HAT can be used to find a maximum cardinality popular matching for the CHA instance . In the context of counting, it is important to note that one popular matching of may translate to many popular matchings in . It is not clear if there is a useful map between these two sets that may help in obtaining either hardness or algorithmic results for counting problems.
2 Counting in House Allocation problem with Ties
In this section we consider the problem of counting the number of popular matchings in House Allocation problem with Ties (HAT). We first describe the characterization given in  here using similar notations. Let be an HAT instance. For any agent , let define the set of first choices of . For any house , define . A house for which is called an -house. To simplify the definitions, we add a unique last-resort house with lowest priority for each agent . This forces every popular matching to be an applicant complete matching.
The first choice graph of is defined to be , where is the set of all rank one edges.
If is a popular matching of , then is a maximum matching of .
Let be any maximum matching of . The matching can be used to identify the houses that are always matched to an agent in the set . In this direction, we observe that defines a partition of the vertices into three disjoint sets - even, odd and unreachable: a vertex is even (resp. odd) if there is an even (resp. odd) length alternating path from an unmatched vertex (with respect to ) to ; a vertex is unreachable if there is no alternating path from an unmatched vertex to . Denote the sets even, odd and unreachable by , and respectively. The following is a well-known theorem in matching theory .
Lemma 2 (Gallai-Edmonds Decomposition)
Let and define the partition , and as above. Then,
The sets , and are pairwise disjoint, and every maximum matching in partitions the vertices of into the same partition of even, odd and unreachable vertices.
In any maximum matching of , every vertex in is matched with another vertex in , and every vertex in is matched with some vertex in . No maximum matching contains an edge between a vertex in and a vertex in . The size of a maximum matching is .
contains no edge connecting a vertex in with a vertex in .
We show the decomposition of in Figure 1, where we look at the bipartitions of , , and . Since only contained edges resulting from first-choices, every house in and is an -house. From Lemma 2, each such house is matched with an agent in in every maximum matching of , and correspondingly in every popular matching of (Lemma 1).
For each agent , define to be ’s most preferred house(s) in . Note that always exists after the inclusion of last-resort houses . The following is proved in .
A matching is popular in if and only if
is a maximum matching of , and
for each applicant , .
The following hardness result is from .
Counting the number of popular matchings in HAT is #P-hard.
We now give an FPRAS for counting the number of popular matchings in the case of ties. As before, let be our HAT instance. We assume that that admits at least one popular matching (this can be tested using the characterization). We reduce our problem to the problem of counting perfect matchings in a bipartite graph. We start with the first-choice graph of , and perform a Gallai-Edmonds decomposition of using any maximum matching of . In order to get a perfect matching instance, we extend the structure obtained from Gallai-Edmonds decomposition described in Figure 1. Let be the set of -houses and be the set of -houses. We make use of the following observations in the decomposition.
Every agent in and gets one of their first-choice houses in every popular matching.
can be further partitioned into the following sets:
can only match with houses in in every popular matching.
These observations are described in Figure 2(a).
Next, we observe that every agent in that is already not matched to a house in , must match to a house in . We facilitate this by adding all edges for each agent in . Finally, we add a set of dummy agent vertices on the left side to balance the bipartition. The size of is . This difference is non-negative as long as the preference-lists of agents are complete. We make the bipartition a complete bipartite graph by adding the appropriate edges. This allows us to move from one popular matching to another by switching between first and second-choices and, among second choices of agents. Finally, we remove set from the right side. The new structure is described in Figure 2(b). Denote the new graph by .
The number of popular matchings in is times the number of perfect matchings in .
Consider a perfect matching of . Let the matching be obtained by removing from all the edges coming out of the set . Observe that is a maximum matching of . This is because the sets , and are always matched in (or else would not be a perfect matching of ) and that the size of a maximum matching in is by Lemma 2. Also, each agent in is matched to either a house in or in by the construction of graph . Using Lemma 3, we conclude that is a popular matching of . Finally, observe that every popular matching in in can be augmented to a perfect matching of by adding exactly edges. This follows again from Lemma 2 and Lemma 3. ∎
We now make use of the following result of Jerrum et al. from .
There exists an FPRAS for the problem of counting number of perfect matchings a bipartite graph.
There exists an FPRAS for counting the number of popular matchings in the House Allocation problem with Ties.
3 Counting in Capacitated House Allocation problem
In this section, we consider the structure of popular matchings in Capacitated House Allocation problem (CHA). A CHA instance consists of agents and houses . Let and . Let be the capacity function for houses. Each agent orders a subset of the houses in a strict order creating its preference list. The preference list of defines a set of edges from to houses in . Define . The problem instance can then be represented by a bipartite graph .
For the instance , a matching is a subset of such that each agent appears in at most one edge in and each house appears in at most edges in . The definitions of more popular than relationship between two matchings and popular matching is same as described earlier in Section 1.
We now outline a characterization of popular matchings in CHA from . As before, denote by the first choice of an agent . A house which is the first choice of at least one agent is called an -house. For each house , define . For each agent , we add a unique last-resort house with least priority and capacity 1.
If is a popular matching then for each -house , .
For each agent , define to be the highest ranked house on ’s preference list such that one of the following is true:
is not an -house, or,
is an -house but and .
Notice that always exists after the inclusion of last-resort houses . The following lemma gives the characterization of popular matchings in .
A matching is popular if and only if
for every -house ,
if , then every agent in is matched to the house ,
else, house is matched to exactly agents, all belonging to ,
is an agent complete matching such that for each agent , .
3.1 Switching Graph Characterization of CHA
We now give a switching graph characterization of popular matchings for instances from this class. Our results are motivated from similar characterizations for HA in  and for HAT in . A switching graph for an instance allows us to move from one popular matching to another by making well defined walks on the switching graph.
Consider a popular matching of an instance of CHA. The switching graph of with respect to is a directed weighted graph , with the edge set defined as follows. For every agent ,
add a directed edge from M(a) to ,
if , assign a weight of on this edge, otherwise assign a weight of .
Associated with the switching graph , we have an unsaturation degree function , defined . A vertex is called saturated if its unsaturation degree is 0, i.e. . If , is called unsaturated. We make use of the following terminology in the foregoing discussion. We now describe some useful properties of the switching graph .
Property 1: Each vertex can have out-degree at most .
Proof. Each edge is from a matched house to an unmatched house and since the house has a maximum capacity , it can only get matched to at most agents. ∎
Property 2: Let and be two different popular matchings in and let and denote the switching graphs respectively. For any vertex house , the number of outgoing edges from is invariant across and . The number of incoming edges on is also invariant across and .
Proof. From Lemma 6, in any popular matching, each -house is matched to exactly agents and this is also the number of outgoing edges with weight . A similar argument can be made for weighted incoming edges. ∎
Property 3: No weighted edge can end at an unsaturated vertex.
Proof. If a weighted edge is incident on a vertex , this means that the house is an -house for some agent that is still not matched to it in . But if is unsaturated then it still has some unused capacity. The matching obtained by just promoting to is popular than , which is a contradiction. ∎
Property 4: There can be no incoming weighted edge on a saturated vertex if all its outgoing edges have weight .
Proof. A weighted edge on a vertex implies that the house is an -house for some agent . But if is saturated with all outgoing edges having a weight of , then all the capacity of has been used up by agents who had as their first choice. But by definition, can not be an -house for any other agent. ∎
Property 5: For a given vertex , if there exists at least one weighted incoming edge, then all outgoing edges are of weight and there can be no weighted incoming edge on .
Proof. Let agent correspond to any weighted incoming edge. Suppose has an outgoing edge ending at a vertex and agent corresponds to this edge. We can promote agents and to their first choices and demote any agent which is assigned house . This leads to a matching popular than . Hence all outgoing edges from must be of weight . Further, Property 3 and Property 4 together imply that there can be no incoming edge on of weight . ∎
We now describe the operation on the switching graph which takes us from one popular matching to another. We make use of the following terminology with reference to the switching graph . Note that the term “path” (“cycle”) implies a “directed path” (“directed cycle”). A “ edge”(“ edge”) means an “edge with weight ” (“edge with weight ”).
A path is called an alternating path if it starts with a edge, ends at a edge and alternates between and edges.
A switching path is an alternating path that ends at an unsaturated vertex.
A switching cycle is an even length cycle of alternating and weighted edges.
A switching set is a union of edge-disjoint switching cycles and switching paths, such that at most switching paths end a vertex of unsaturation degree .
A switching move is an operation on by a switching set in which, for every edge in , we reversed the direction of and flip the weight of ().
Observe that every valid switching graph inherently implies a matching (in the context of CHA) of .
Let and be the switching graphs associated with popular matchings and of the CHA instance . Observe that the underlying undirected graph of and are same. We have the following.
Let be the set of edges in that get reversed in . Then, is a switching set for .
We prove this algorithmically in stages.
Every directed cycle in is a switching cycle of .
Let be any cycle in . From Property 5 of switching graphs, we know that no vertex in can have an incoming edge and an outgoing edge of same weight . Similarly, since is the set of edges in which have opposite directions and opposite weights in , we observe that can not contain any vertex with incoming and outgoing edges both having weight (again from Property 5). This forces the weights of cycle to alternate between and . Moreover, this alternation forces the cycle to be of even length.
At this stage we apply the following algorithm to the set .
1. while (there exists a switching cycle in ):
2. while ( is non-empty):
find a longest path in which alternates between weights and
At the end of every iteration of the while loop in Step 1, Lemma 8 still holds true. We now prove a very crucial invariant of the while loop in Step 2.
In every iteration of the while loop in Step 2 of the algorithm Reduction, the longest path in step is a switching path for .
Let us denote the stages of the run of algorithm Reduction by . Initially, at , before any of the while loops run, is exactly the difference of edges in and . Let the while loop in Step 1 runs times and the while loop in Step 2 runs times.
Let the current stage be . Let be the maximal path in step at this stage. We show that starts with an edge of weight . For contradiction, let be an edge of weight and that this is the first edge of path . Let be the agent associated with the edge .
The Property 5 of switching sets precludes any incoming edge of weight on the vertex . Hence, no switching path could have ended at at any stage . Similarly, no switching cycle with an incoming edge was incident on at an earlier stage.
Let us assume that there were cycles that were incident at at . At stage , let the number of outgoing edges be . Hence at , had incoming edges and outgoing edges. But this would also imply that at , had incoming edges in . This contradicts Property 2, requiring the number of incoming edges to be constant in the switching graphs corresponding to different popular matchings.
A similar argument can be made for the fact that the path can only end at an edge with weight and that ends at an unsaturated vertex.
The following theorem establishes the characterization for popular matchings in CHA.
If is the switching graph of the CHA instance with respect to a popular matching , then
(i) every switching move on generates another popular matching, and
(ii) every popular matching of can be generated by a switching move on .
We verify that the new matching generated by applying a switching move on satisfies the characterization in Lemma 7. Call the new switching graph and the associated matching . First, observe that is indeed an agent complete matching since still has a directed edge for each agent in . Next, each agent is still matched to or as the switching move either reverses an edge of or leaves it as it is. Finally, for each house , if and with otherwise. This is true because , by the definition of switching moves.
This is implied by Theorem 3.1.
3.2 Hardness of Counting
In this section we prove the #P-hardness of counting popular matchings in CHA. We reduce the problem of counting the number of matchings in a bipartite graph to our problem.
Let be a bipartite matching instance in which we want to count the number of matchings. From we create a CHA instance such that the number of popular matchings of is same as the number of matchings of .
Observe that a description of a switching graph gives the following information about its instance:
the set of agents ,
for each agent , it gives and , and
for each -house or -house , the unsaturation degree gives the capacity .
Using this information, we can create the description of the instance so that it meets our requirement. For simplicity, we assume to be connected (as isolated vertices do not affect the count). We orient all the edges of from to and call the directed graph . Using , we construct a graph , which will be the switching graph.
Let , and . is constructed by augmenting . We keep all the vertices and edges of in and assign each edge a weight of . Further, for each vertex , add a copy and add a directed edge from to , and assign a weight of to the edge. Call the new set of vertices . The sets and contain -houses and the set contains -houses. We label every vertex in and as saturated and for each vertex in , we label as unsaturated with unsaturation degree 1. Hence, the switching graph has vertices and edges.
The CHA instance corresponding to the switching graph has houses and agents. Each agent has a preference list of length that is naturally defined by the weight of edges in .
Let the popular matching represented by be . This corresponds to the empty matching of . Every non-empty matching of can be obtained by a switching move on . We make this more explicit in the following theorem.
The number of matchings in is same as the number of popular matchings in .
We prove this by showing that each matching in corresponds to a unique set of edge disjoint switching paths in the switching graph of .
Consider a matching of and let . We look at the length directed path in that is obtained by extending in the reverse direction: with . It’s easy to see that this is a switching path for . Moreover, the set of switching paths obtained from any matching of forms a valid switching set (as every pair of such paths arising from a matching are always edge disjoint).
For the converse, observe that can only have switching paths of length and it has no switching cycles. An edge disjoint set of such paths corresponds to a matching of . By the definition of , it’s easy to see every matching in can be obtained by a switching set of .
Conclusions and Acknowledgement: Our main contribution is the #-P hardness and an FPRAS for the Capacitated House Allocation problem. We believe that the switching graph characterization may be useful in other problems in the setting of CHA.
We thank Meghana Nasre for fruitful discussions. We also thank anonymous reviewers for their input.
-  David J. Abraham, Robert W. Irving, Telikepalli Kavitha, and Kurt Mehlhorn. Popular matchings. SIAM J. Comput., 37(4):1030–1045, 2007.
-  Nayantara Bhatnagar, Sam Greenberg, and Dana Randall. Sampling stable marriages: why spouse-swapping won’t work. In SODA, pages 1223–1232, 2008.
-  Prasad Chebolu, Leslie Ann Goldberg, and Russell A. Martin. The complexity of approximately counting stable matchings. In APPROX-RANDOM, pages 81–94, 2010.
-  David Gale and Lloyd S Shapley. College admissions and the stability of marriage. The American Mathematical Monthly, 69(1):9–15, 1962.
-  Peter Gärdenfors. Match making: assignments based on bilateral preferences. Behavioral Science, 20(3):166–173, 1975.
-  Robert W. Irving and Paul Leather. The complexity of counting stable marriages. SIAM J. Comput., 15(3):655–667, 1986.
-  Mark Jerrum, Alistair Sinclair, and Eric Vigoda. A polynomial-time approximation algorithm for the permanent of a matrix with non-negative entries. In STOC, pages 712–721, 2001.
-  Telikepalli Kavitha, Julián Mestre, and Meghana Nasre. Popular mixed matchings. Theor. Comput. Sci., 412(24):2679–2690, 2011.
-  L. Lovász and M. D. Plummer. Matching theory, volume 121 of North-Holland Mathematics Studies. North-Holland Publishing Co., Amsterdam, 1986. Annals of Discrete Mathematics, 29.
-  Mohammad Mahdian. Random popular matchings. In ACM Conference on Electronic Commerce, pages 238–242, 2006.
-  Richard Matthew McCutchen. The least-unpopularity-factor and least-unpopularity-margin criteria for matching problems with one-sided preferences. In LATIN, pages 593–604, 2008.
-  Eric McDermid and Robert W. Irving. Popular matchings: structure and algorithms. J. Comb. Optim., 22(3):339–358, 2011.
-  Meghana Nasre. Popular matchings: Structure and cheating strategies. In STACS, pages 412–423, 2013.
-  Colin T. S. Sng and David Manlove. Popular matchings in the weighted capacitated house allocation problem. J. Discrete Algorithms, 8(2):102–116, 2010.