Hierarchical bMatching
Abstract
A matching of a graph is a subset of edges no two of which share a common vertex, and a maximum matching is a matching of maximum cardinality. In a matching every vertex has an associated bound , and a maximum matching is a maximum set of edges, such that every vertex appears in at most of them. We study an extension of this problem, termed Hierarchical bMatching. In this extension, the vertices are arranged in a hierarchical manner. At the first level the vertices are partitioned into disjoint subsets, with a given bound for each subset. At the second level the set of these subsets is again partitioned into disjoint subsets, with a given bound for each subset, and so on. In an Hierarchical bmatching we look for a maximum set of edges, that will obey all bounds (that is, no vertex participates in more than edges, then all the vertices in one subset do not participate in more that that subset’s bound of edges, and so on hierarchically). We propose a polynomialtime algorithm for this new problem, that works for any number of levels of this hierarchical structure.
Department of Industrial Engineering and Management, Technion, Haifa, Israelyemek@technion.ac.ilhttps://orcid.org/0000000231233451 Department of Industrial Engineering and Management, Technion, Haifa, Israelkutten@technion.ac.il TelHai Academic College, Upper Galilee, 12210, Israelcmshalom@telhai.ac.ilhttps://orcid.org/0000000226885703 Department of Computer Science, Technion, Haifa, Israel, and School of Engineering, Ruppin Academic Center, Israel.zaks@cs.technion.ac.ilhttps://orcid.org/0000000156374923 \CopyrightYuval Emek and Shai Kutten and Mordechai Shalom and Shmuel Zaks\ccsdesc[100]General and reference\fundingThis research was supported in part by PetaCloud  a project funded by the Israel Innovation Authority.\EventEditorsJohn Q. Open and Joan R. Access \EventNoEds2 \EventLongTitle42nd Conference on Very Important Topics (CVIT 2016) \EventShortTitleCVIT 2016 \EventAcronymCVIT \EventYear2016 \EventDateDecember 24–27, 2016 \EventLocationLittle Whinging, United Kingdom \EventLogo \SeriesVolume42 \ArticleNo23
1 Introduction
A matching of a graph is a subset of its edges such that no two edges share a common vertex. The maximum matching problem is the problem of finding a matching of maximum cardinality in a given graph. The maximum weighted matching problem is an extension of the problem for edgeweighted graphs in which one aims to find a matching of maximum total weight. Both problems are fundamental in graph theory and combinatorial optimization. As such, they have been extensively studied in the literature. While pioneering works focused on the nonweighted bipartite case, later work considered general graphs and weights. The general case is solved in [18] and a more efficient algorithm is proposed later in [22].
An important extension of these problems is the following maximum matching problem. We are given a (possibly weighted) graph and a positive integer for every vertex of the graph. A matching of the graph is a multiset of its edges such that, for every vertex , the number of edges of incident to does not exceed . Clearly, a matching is a special case of matching in which for every vertex . The problems of finding a matching of maximum cardinality and of maximum weight are widely studied. The weighted version of the problem is solved in [24]. A faster algorithm is later proposed in [14]. This result is recently improved in [19]. Being a fundamental problem, the matching problem is considered in the literature in specific graph classes (e.g. [25], [17]). The matching model is used to solve numerous problems in different areas, e.g. [26]. See [21] for an excellent reference for matching theory, and [20] for flow techniques and other algorithmic techniques used to solve matching problems.
In this work, we consider an extension of the maximum cardinality matching problem and propose a polynomialtime algorithm for it. In this extension, the vertices are arranged in a hierarchical manner, such that every set is either a single vertex or the union of other sets, and with each set, there is an associated upper bound on the sum of the degrees of the vertices in it.
This problem can arise in hierarchical structures, for instance as in the following scenario. Pairs of researchers are willing to pay mutual visits to each other. However, every researcher has a budget that allows her to exercise at most visits. The goal is to find a maximum number of such pairs (that will visit each other) without exceeding the individual budget of any researcher. This problem can be modeled as a matching problem. Now we extend this scenario to the hierarchical case. Some institutions assign budgets not only to individual researchers but also to research groups, departments, faculties and so on. In this case a set of pairs is feasible if the number of visits to be done by every individual researcher, every research group, every department and every faculty is within its assigned budget.
2 Preliminaries
For two nonnegative integers , denote by the set of integers that are not smaller than and not larger than . is a shorthand for , and denotes the union operator of multisets, i.e., is a multiset in which the multiplicity of an element is the sum of its multiplicities in and . A set system over a set of elements is laminar if for every two sets one of the following holds: , , or . We consider laminar set systems of distinct sets and . In this case, at most one of the conditions may hold. Since adding and all the singletons of to preserves laminarity, we assume without loss of generality that and for every .
The next Lemma summarizes well known fact about laminar set systems: {lemma}

Let be a laminar set system over a set . Then

the elements of can be represented as a rooted tree , in which the root corresponds to and the leaves to the singletons for every .

Every nonleaf node of has at least two children.

The number of sets in is at most .
Note that in this lemma: ii) follows from the fact that we assumed that a laminar set system consists of distinct sets, and iii) follows from ii), with equality (i.e. the number of elements is exactly ) if and only if is a full binary tree. See Figure 1 for an example.
Identifying the sets of with the nodes of and we say that a set is the parent of , or that is a child of . Denote by the set of all children of .
We use standard terminology and notation for graphs, see for instance [16]. Given a simple undirected graph , denote by the set of vertices of and by the set of the edges of . Denoting an edge between two vertices and as , we say that the edge is incident to and , and are the endpoints of , and is adjacent to (and vice versa). For directed graphs, the arc is said to be from to . Denote by the set of all edges incident to the vertex of , i.e., . The number of these edges is the degree of in . When there is no ambiguity, the subscript is omitted and written simply as and . A walk of a graph (resp. directed graph) is a sequence where every is a vertex of , every is an edge (resp. arc) of , and for every . A trail is a walk whose edges are distinct, i.e. whenever , . A walk (resp. trail) is closed if and open otherwise.
Let be a graph and a set of vertices of and a multiset over the edges of where denotes the multiplicity of in . The degree of in is the sum of the degrees (in ) of its vertices, i.e. . ( is the degree of in the graph induced by the edges of .) Clearly, for a singleton , we have . Let be a laminar set system over , a vector of positive integers indexed by the edges of , and a vector of positive integers indexed by the sets in . A multiset is a Hierarchical matching (or Hmatching for short) of if the multiplicity of every edge of is at most , and for every . In this work, we consider the following problem
Max Hmatching Input: A quadruple where is a graph, is a laminar set system over , is a vector of positive integers indexed by (the sets of) , and is a vector of positive integers indexed by the edges of . Output: An Hmatching of of maximum cardinality.
Without loss of generality the vertex set of is , with , for every , is the root of , for every , and for every edge () of .
Assume also without loss of generality that

for every nonleaf , and

for every edge of .
In fact, if this is not the case, the vectors and can be modified as follows without affecting the set of feasible solutions. First process the sets in a preorder manner and set whenever . Then process the sets in a postorder manner and set whenever .
Given an Hmatching of , define the slackness of an edge as , and the slackness of a set as . Whenever no ambiguity arises, the name of the matching in the indices is omitted, and is written instead of , and , respectively. A set or an edge of ) is tight in if its slackness in is zero. A vertex is tight in if there is at least one tight set that contains .
A matching of is an Hmatching of where consists of and its singletons, for every edge of , for every vertex of and . A matching matches (or saturates) a vertex if and it exposes otherwise (i.e., ). saturates (resp. exposes) a set of vertices , if saturates (resp. exposes) all the vertices of . Denote by (resp. ) the set of vertices matched (resp. exposed) by .
3 Hierachical bMatching
Given a matching of a graph , an augmenting path of is a path of odd length that starts with an edge that is not in and its edges alternate between edges and nonedges of . It is well known that a matching is of maximum cardinality in a graph if and only if does not contain an augmenting path (Berge’s Lemma [15]). Since finding an augmenting path can be done in linear time, this implies a polynomialtime algorithm that starts with any matching (e.g., the empty one) and improves it using augmenting paths until no such path is found.
Our design of the polynomialtime algorithm for Max Hmatching consists of three parts. We start by proving an analogous Lemma for Hmatchings. This implies a pseudopolynomial algorithm to augment a given Hmatching. Applying this algorithm starting from an empty Hmatching, until an augmentation is impossible, implies a pseudopolynomial algorithm for Max Hmatching. This is done in Section 3.1. We then improve the result to get a polynomialtime algorithm for a single augmentation step, and extend the technique introduced in [14] to improve the overall algorithm to run in polynomial time. This is done in Section 3.2.
3.1 A pseudopolynomial algorithm
We now present a pseudopolynomial algorithm for the Max Hmatching problem. Our solution reduces the problem to the problem of finding a maximum cardinality matching of a graph using a pseudopolynomial reduction.
Consult Figure 1 and Figure 2 for the following definition. {definition} The representing graph of an instance of Max Hmatching is the graph where

, , and every set and consists of vertices,

, and every set consists of vertices,

contains edges for every connecting the vertices of with the vertices of so that induces a perfect matching,

contains edges between the vertices of and the vertices of so that induces a complete bipartite graph, whenever is the parent of in . Moreover, contains edges between the vertices of and the vertices of for every edge of .

contains edges between the vertices of and the ) vertices of so that induces a perfect matching.
Let be an Hmatching of . The representing matching of is the matching of constructed as follows.

Start with the empty matching .

Processing the edges of in some predefined order, for every edge of , add to

the last edges of , and

the edges connecting the first vertices of to the first vertices of that are yet unmatched in .
Note that at this point (a) all the vertices of are matched by , and (b) the number of vertices of matched by is for every .


Process the sets in some predefined postorder traversal of .

Assume that the number of vertices of matched by is at the time it is processed. As was already mentioned, this assumption holds when a leaf (i.e., a singleton) of is processed.

Add to the perfect matching induced by the last vertices of and the last vertices of . At this point, all the vertices of are matched by and the number of unmatched vertices of is .

Add to the edges that connect the first vertices of with the first vertices of that are yet unmatched by where is the parent of . At this point all the vertices of are matched by .

We note that after all the children of a set have been processed, the number of vertices of matched by is , i.e. our assumption holds when is processed.

The following Lemma is implied by the above description. {lemma} Let be an Hmatching of , and . Then

, and

the number of edges of between and is equal to for every .
Moreover, . Informally, Lemma 3.1 states that the number of matched vertices in the set is , and the number of unmatched vertices of in is equal to the number of pairs matched by between the sets and for every , and in addition the unmatched vertices of are all in the set . In our example, the unmatched vertices are all in , and the number of matched vertices in is . As for , for example, the slack of is , and correspondingly there are no matched pairs between and ; the slack of is , and correspondingly there are pairs of between and ; and the slack of is , and correspondingly there are pairs of between and .
We now prove the opposite direction. Informally it states that starting from a given matching of Max Hmatching in which the unmatched vertices all belong to the set , we can construct, in polynomial time, an Hmatching of , such that , and satisfies properties and of that Lemma.
Let be an instance of Max Hmatching, and be a matching of such that . Then there exists an Hmatching of such that , and it satisfies

,

the number of edges of between and is equal to for every .
Moreover, can be found in time linear in the size of .
Proof.
Consider an edge of , and the sets of vertices of . For every vertex of let be its corresponding vertex in . Then exactly one of the following holds: a) , b) is matched to a vertex of and is is matched to a vertex of by . Let be the multiset of edges of such that, for every edge of , equals to the number of vertices of for which condition b) holds. We claim that is an Hmatching of .
By definition of , the multiplicity of an edge in is at most . For every , the number of vertices of matched to a vertex of is . Let and for such that is an edge of . Then exactly one of the following holds: a) , b) is matched to some vertex of and is matched to some vertex of such that is a child of and is the parent of . From the above facts, it follows by induction on the structure of that the number of vertices of matched to a vertex of for some is . Therefore, for every we have . We conclude that is an Hmatching of .
It follows that the number of vertices of matched to a vertex of for some (i.e., the number of vertices of matched by ) is . ∎
FindRepresentingMatching is a pseudopolynomial algorithm for Max Hmatching.
Proof.
By Lemma 3.1 we have . We observe that for any matching obtained by applying a sequence of augmenting paths to , in particular for we have . Furthermore, is minimum. Therefore, is maximum. By Lemma 3.1 i), is maximum.
The size of is . Since we want to prove pseudopolynomial running time we assume that the values are bounded by for some fixed . Then, . Therefore the size of is . Since every step of the algorithm can be performed in time polynomial to we conclude the result. ∎
3.2 Polynomialtime algorithm
In this section we improve the pseudopolynomial algorithm of Section 3.1 to get a polynomialtime algorithm. We achieve this in two stages. First, we present (in Lemma 3.2) a polynomialtime algorithm to augment a given matching . Then, we present (in Lemma 3.2) a technique to bound the number of augmentations by a polynomial in the size of the input. Combining these two lemmas we get (in Theorem 3.2) our polynomialtime algorithm.
Let be an Hmatching of . The augmentation graph of is the 2edgecolored induced subgraph of obtained by

coloring every edge of red, and every other edge blue,

marking blue and red edges between and for every ,

marking blue and red edges between and for every edge of , and finally

removing all vertices and edges that are not incident to any of the marked edges, except for two vertices of unmatched by .
In our example, the first step of coloring the edges of red and blue is depicted in Figure 2, where the red edges are as indicated in that figure, and all other edges are blue.
Though the above definition uses in order to construct , it is easy to see that it can be constructed in time , without constructing at the first place.
Let be an Hmatching of . Then

The only unmatched vertices in are and , and

is not of maximum cardinality if and only if contains an alternating (odd) path (connecting and ).
Proof.
follows immediately from the construction of . We now prove . To show sufficiency, suppose that contains a path as claimed. Since is a subgraph of , is a path of . Moreover, since red edges are edges of and blue edges are nonedges of it, is a augmenting path. Therefore, is not of maximum cardinality.
To show necessity, suppose that is not of maximum cardinality. Then, contains a augmenting path . We color those edges of that are in red, and the others blue. The path connects unmatched vertices, hence it must connect two vertices of and its end edges are blue. Let be the multigraph obtained by contracting every set and of vertices to a single vertex, and allowing parallel edges. Clearly, corresponds to an alternating trail of starting and ending with blue edges incident to . Note that whenever for some or for some edge of the corresponding vertices, namely , , and have multiplicity of one in the multigraph. Therefore, such vertices may appear at most once in . Let be the shortest trail of having these properties, and a vertex of . The trail does not contain even cycles, since by eliminating an even cycle one can get a shorter alternating trail. Therefore, the number of edges between any two occurrences of in must be odd. If occurs (at least) three times in then two of the occurrences must be at even distance from each other. We conclude that the number of occurrences of in is at most two. We can construct from a path of by a) splitting up every two parallel edges between some and into two disjoint edges, b) splitting up every two parallel edges (that necessarily have the same color) between some and into two disjoint edges, and c) splitting into two nonadjacent vertices any vertex that is still traversed twice by . See Figure 3 for this operation. Note that the only case that the resulting path is possibly not a path of is the case that a vertex is visited twice by but has multiplicity of one in the multigraph. However, as already observed, such vertices appear at most once in . ∎
Since can be constructed in time and an augmenting path of it can be found in time , Lemma 3.2 implies that given an Hmatching , one can find in time an Hmatching of cardinality or decide that is of maximum cardinality. Therefore,
A maximum cardinality Hmatching of can be found in time .
In the sequel we extend the technique introduced in [14] to bound the number of augmentations needed to find a maximum matching by a polynomial. This is done by finding a nearly optimal Hmatching by means of a flow network.
An Hmatching of cardinality at least can be found in time where is a maximum cardinality Hmatching of .
Proof.
We present an algorithm that works in three stages. In the first stage we construct a flow network corresponding the instance, and compute a maximum flow of it. In the second stage we use this maximum flow to find an optimal fractional solution of the Max Hmatching instance. Finally we round this fractional solution with a loss of .
We start by describing the construction of the flow network (see Figure 4). is a directed graph with vertex set . For every , there are two arcs and with capacity where is the parent of . There are two arcs and , with capacities . For every edge of , contains two arcs and with . Every Hmatching of implies a feasible flow of by setting for every edge of , for every such that , and . It is easy to verify that is a feasible flow and its value is . Therefore, for a maximum flow and an Hmatching of maximum cardinality, we have . The number of vertices of is which is linear in . The number of arcs of is dominated by . It is well known that, since all the capacities are integral, there is an integral maximum flow . Such a flow can be found in time [23]. If is symmetric, i.e. for every edge of then we may stop at this stage and induces an optimal solution of Max Hmatching.
In the second stage we compute for every pair of symmetric arcs and of . Clearly, is symmetric and . It remains to show that is a feasible flow. Clearly the flow on each edge is bounded by its capacity; moreover, it is easy to verify that satisfies flow conservation at each vertex , since satisfies it.
If is integral we can assign for every edge of to get an optimal solution of Max Hmatching. Since this is not necessarily the case, this assignment leads to a halfintegral fractional Hmatching with .
In the last stage we round with a small loss, to get a feasible solution with . We start with . Let be the graph induced by the edges of such that is nonintegral. As far as contains an even cycle , we pick a matching of consisting of half of its edges, increase by for every edge of the matching and decrease it by for all the other edges of . This modification does not affect the degrees of the vertices and thus the degrees of the sets of , in particular it does not affect . At this point all the cycles of are odd. These cycles are vertex disjoint, since otherwise there is an even cycle in . Therefore, the number of these odd cycles is at most . Let be an odd cycle of . We pick a maximum matching of , increase by for every edge of the matching and decrease it by for all the other edges of . This modification does not increase the degrees of the vertices and thus the degrees of the sets of , however it decreases by . Therefore, the total loss at this stage is at most . At this point is acyclic, i.e. a forest. If we decrease by in all the edges of the forest, decreases by at most . We conclude that . ∎
We are now ready to prove our main theorem. {theorem} A maximum cardinality Hmatching of can be found in time .
4 Conclusion and Open Problems
In this paper we studied the Hmatching problem, which is an extension of the matching problem, in which the vertices are organized in a hierarchical manner (independently of the structure of the graph). At each level the vertices are partitioned into disjoint subsets, with a given bound on the sum of degrees of every subset. The optimization problem is to find a maximum set of edges, that will obey all degree bounds. This problem is applicable to many social structures, where the organization is of hierarchical nature.
We have presented a polynomialtime algorithm for this new problem, in a few stages. We first reduced it to an ordinary matching in an associated larger graph, and this resulted in a pseudo polynomial algorithm for the problem. We then improved it to a polynomialtime algorithm. This was achieved by combining results of two stages: in the first stage we presented a polynomialtime algorithm to augment a given matching, and in the second one we presented a technique to bound the number of augmentations by a polynomial in the size of the input.
A few open problems are immediately related to our result. The first one is the weighted case of the problem, in which every edge has an associated weight and the goal is to find an Hmatching of maximum weight. To find an efficient algorithm for this problem, apparently requires the extension of the linear programming techniques used in [24]. Another problem is to consider the hierarchical case where the bounds on the sets are interpreted as a bound on the number of edges that connect the vertices of the set to the rest of the graph.
References
 [1] Richard P. Anstee. A polynomial algorithm for bmatchings: an alternative approach. Information Processing Letters, 24:153–157, 1987.
 [2] C. Berge. Two theorems in graph theory. Proceedings of the National Academy of Sciences of the United States of America, 43:842–844, 1957.
 [3] Reinhard Diestel. Graph Theory, 4th Edition, volume 173 of Graduate texts in mathematics. Springer, 2012.
 [4] Guillaume Ducoffe and Alexandru Popa. The bmatching problem in distancehereditary graphs and beyond. In 29th International Symposium on Algorithms and Computation, ISAAC 2018, December 1619, 2018, Jiaoxi, Yilan, Taiwan, pages 30:1–30:13, 2018. URL: https://doi.org/10.4230/LIPIcs.ISAAC.2018.30, doi:10.4230/LIPIcs.ISAAC.2018.30.
 [5] Jack Edmonds. Paths, trees, and flowers. Canadian Journal of Mathematics, 17:449–467, 1965. doi:10.4153/CJM19650454.
 [6] Harold N. Gabow. Data structures for weighted matching and extensions to bmatching and ffactors. ACM Trans. Algorithms, 14(3):39:1–39:80, June 2018. URL: http://doi.acm.org/10.1145/3183369, doi:10.1145/3183369.
 [7] E.L. Lawler. Combinatorial Optimization: Networks and Matroids. Holt, Rinehart and Winston, 1976. URL: https://books.google.co.il/books?id=w_lQAAAAMAAJ.
 [8] L. Lovász and M. D. Plummer. Matching Theory. AMS Chelsea Publishing, 2009.
 [9] Silvio Micali and Vijay V. Vazirani. An algorithm for finding maximum matching in general graphs. In Proceedings of the 21st Annual Symposium on Foundations of Computer Science, SFCS ’80, pages 17–27, Washington, DC, USA, 1980. IEEE Computer Society. URL: http://dx.doi.org/10.1109/SFCS.1980.12, doi:10.1109/SFCS.1980.12.
 [10] James B. Orlin. Max flows in o(nm) time, or better. In Proceedings of the Fortyfifth Annual ACM Symposium on Theory of Computing, STOC ’13, pages 765–774, New York, NY, USA, 2013. ACM. URL: http://doi.acm.org/10.1145/2488608.2488705, doi:10.1145/2488608.2488705.
 [11] R. Pulleyblank. Faces of Matching Polyhedra. PhD thesis, University of Waterloo, 1973.
 [12] Arie Tamir and Joseph S.B. Mitchell. A maximum bmatching problem arising from median location models with applications to the roommates problem. Mathematical Programming, 80:171–194, 1995.
 [13] Moshe Tennenholtz. Tractable combinatorial auctions and bmatching. Artificial Intelligence, 140(12):231–243, September 2002. URL: http://dx.doi.org/10.1016/S00043702(02)002291, doi:10.1016/S00043702(02)002291.
References
 [14] Richard P. Anstee. A polynomial algorithm for bmatchings: an alternative approach. Information Processing Letters, 24:153–157, 1987.
 [15] C. Berge. Two theorems in graph theory. Proceedings of the National Academy of Sciences of the United States of America, 43:842–844, 1957.
 [16] Reinhard Diestel. Graph Theory, 4th Edition, volume 173 of Graduate texts in mathematics. Springer, 2012.
 [17] Guillaume Ducoffe and Alexandru Popa. The bmatching problem in distancehereditary graphs and beyond. In 29th International Symposium on Algorithms and Computation, ISAAC 2018, December 1619, 2018, Jiaoxi, Yilan, Taiwan, pages 30:1–30:13, 2018. URL: https://doi.org/10.4230/LIPIcs.ISAAC.2018.30, doi:10.4230/LIPIcs.ISAAC.2018.30.
 [18] Jack Edmonds. Paths, trees, and flowers. Canadian Journal of Mathematics, 17:449–467, 1965. doi:10.4153/CJM19650454.
 [19] Harold N. Gabow. Data structures for weighted matching and extensions to bmatching and ffactors. ACM Trans. Algorithms, 14(3):39:1–39:80, June 2018. URL: http://doi.acm.org/10.1145/3183369, doi:10.1145/3183369.
 [20] E.L. Lawler. Combinatorial Optimization: Networks and Matroids. Holt, Rinehart and Winston, 1976. URL: https://books.google.co.il/books?id=w_lQAAAAMAAJ.
 [21] L. Lovász and M. D. Plummer. Matching Theory. AMS Chelsea Publishing, 2009.
 [22] Silvio Micali and Vijay V. Vazirani. An algorithm for finding maximum matching in general graphs. In Proceedings of the 21st Annual Symposium on Foundations of Computer Science, SFCS ’80, pages 17–27, Washington, DC, USA, 1980. IEEE Computer Society. URL: http://dx.doi.org/10.1109/SFCS.1980.12, doi:10.1109/SFCS.1980.12.
 [23] James B. Orlin. Max flows in o(nm) time, or better. In Proceedings of the Fortyfifth Annual ACM Symposium on Theory of Computing, STOC ’13, pages 765–774, New York, NY, USA, 2013. ACM. URL: http://doi.acm.org/10.1145/2488608.2488705, doi:10.1145/2488608.2488705.
 [24] R. Pulleyblank. Faces of Matching Polyhedra. PhD thesis, University of Waterloo, 1973.
 [25] Arie Tamir and Joseph S.B. Mitchell. A maximum bmatching problem arising from median location models with applications to the roommates problem. Mathematical Programming, 80:171–194, 1995.
 [26] Moshe Tennenholtz. Tractable combinatorial auctions and bmatching. Artificial Intelligence, 140(12):231–243, September 2002. URL: http://dx.doi.org/10.1016/S00043702(02)002291, doi:10.1016/S00043702(02)002291.