Abstract

A many-to-many matching (MM) between two sets matches each element of one set to at least one element of the other set. A general case of the MM is the many-to-many matching with demands and capacities (MMDC) satisfying given lower and upper bounds on the number of elements matched to each element. In this article, we give a polynomial-time algorithm for finding a minimum-cost MMDC between two sets using the well-known Hungarian algorithm.

1. Introduction

Let and with . A many-to-many matching (MM) between two sets and maps each element of to at least one element of and vice-versa. Let be an MM between and . The cost of denoted by is the sum of the costs of all matched pairs . Given an undirected bipartite graph , a matching in is a subset of the edges such that each vertex is incident to at most one edge of . A perfect matching in is a matching covering all vertices . A matched vertex is a vertex that is incident to an edge in . A vertex that is not matched is a free vertex. Let denote the weight of the edge . The weight of the matching is the sum of the weights of all edges in , hence

The first polynomial algorithm for computing a minimum-weight perfect matching in with is the well-known Hungarian algorithm proposed in [1], later implemented faster by the running time in dense graphs [2] and in sparse graphs [3], where . Eiter and Mannila [4] solved the minimum-cost MM problem in time by reducing it to the minimum-weight perfect matching problem in a bipartite graph. A modified Hungarian algorithm which is more complex than the approach given in [4], performing shortest path searches using Dijkstra’s algorithm by advantage of Fibonacci heaps [5], runs in time [6]. When the weights of the edges are integers, a scaling algorithm was proposed by Gabow and Tarjan [7] running in time, where . For a more detailed discussion on the matching theory and algorithms, see [810]. When and are two sets of points in the plane, a modified Hungarian algorithm computes an MM between and in time due to Bandyapadhyay et al. [11]. Colannino et al. [12] proposed an time algorithm for the one-dimensional MM (OMM) problem, where and are two sets of points lying on the real line.

Without loss of generality, let . In a two-sided matching (TSM) between two sets and , each element of must be matched to an element of , and each element of can be matched to at most one element of , implying that elements of remain free [13]. In a stable TSM problem, each element of one set provides preference information over the elements of the other set based on which the optimal matching is computed [14, 15]. A TSM denoted by is a stable TSM if for any matched pair , and do not prefer to be matched to rather than and rather than , respectively [13]. Two types of stable TSM problems have been considered in the literature, multiattribute stable TSM problems in which each element of one set provides its preference over the elements of the other set using multiple attributes, and stable TSM problems with preference structures such as preference ordinals and relations [14, 15]. Although some special cases of stable TSM problems can be solved in polynomial time, most stable TSM problems are NP-hard and can be solved by optimization models such as linear and nonlinear programming models [1315].

In a limited-capacity MM (LCMM) between and , each element can be matched to a limited number of the elements, denoted by . A degree-constrained subgraph (DCS) in a general graph is a subgraph in which for each vertex with degree , we have ( and denote integer bounds). The DCS problem in was solved in time [16], where and . The minimum-cost LCMM problem can be reduced to finding a minimum-weight DCS in an undirected bipartite graph. A one-dimensional LCMM (OLCMM), an LCMM where and lie on the real line, was solved in time [17]. A simple b-matching in is a subset of the edges in which there is a quota on the vertices such that for all . When the edge weights are integers, the optimal simple b-matching problem in the bipartite graph was solved in the time complexity of [9], where and .

The many-to-many matching with demands and capacities (MMDC) is a generalization of the LCMM in which each element is matched to elements of , and each element is matched to elements of . Observe that we can consider the minimum-cost MMDC problem a special case of the optimal DCS problem in a bipartite graph, and solve it using the algorithm proposed in [16]. In this article, we present an algorithm that computes a minimum-cost MMDC between and in time using the basic Hungarian algorithm. Also, our algorithm computes an MMDC between two sets of points in the plane in time using the modified Hungarian algorithm proposed in [11]. In fact, our algorithm imposes upper and lower bounds on the number of elements that can be matched to each element in any version of the Hungarian algorithm (see e.g., [18, 19] for further discussion and references). Note that when , our algorithm runs in time improving the previous time algorithm. Also, our algorithm runs faster than its worst time complexity in bipartite graphs with low-range edge weights and dense graphs [19]. In Section 2, we present our algorithm and a numerical example for it.

2. Matching Algorithm

Given two sets and , in this section, we present our algorithm for computing an MMDC between and . We construct a complete bipartite graph such that by running the Hungarian algorithm on , the demands and capacity limitations of elements of and are satisfied. In the following, we explain how our complete bipartite graph is constructed. Note that we assume there exists at least one MMDC between and ; this can be checked in time [20].

We represent a set of related vertices using a rectangle, an edge with a line, and each vertex with a circle. In a complete connection between two sets, each vertex of one set is connected to all vertices of the other set. We show a complete connection using a line connecting the two corresponding sets. The Hungarian algorithm computes a perfect matching in which each vertex is incident to a unique edge. We aim to find an MMDC between two sets and where two or more elements may be mapped to the same element, that is, more than one element may be matched to any of the elements. Therefore, our constructed graph contains multiple copies of each element to simulate this situation. Also, the input of the Hungarian algorithm is a complete bipartite graph with , i.e., both parts of the input bipartite graph have an equal number of vertices. Therefore, we should balance two parts of our constructed bipartite graph before using the Hungarian algorithm.

Let be a bipartition of with and (see Figure 1). Let be the set of copies of the element for . Note that each element has a limited capacity, i.e., it can be matched to at most a given number of elements of . Thus, each is copied times to constitute the set for . Each set is a copy of the set . Assume that all vertices with constitute the set . In fact, each set includes copies of for . We use the set to limit the number of elements matched to . The set compensates our bipartite graph ( balances and ). Also, the sets for guarantee that the output MMDC is a minimum-cost MMDC.

The vertices of the sets , , and for are called main vertices, since they are copies of elements of . On the other hand, the vertices of the sets , , and for are called dummy vertices. All edges whose both end vertices are main vertices, i.e., for , are called main edges.

Each set is completely connected to the set . This complete connection is shown using a line connecting the two corresponding rectangles of and . Note that for , where is the cost of matching to . Each set guarantees that the element is matched to at least elements of . Each set is completely connected to the set , where is equal to for . The sets guarantee that each element is matched to at least elements of . Moreover, each set assures that is matched to at most elements.

Let . Given an arbitrary real value with , there is a complete connection with weighted edges between and for . Also, there is a zero weighted complete connection between and .

The compensator set with is inserted in as follows. Note that we assume (and ), since otherwise, there would not exist any MMDC between and . Let . Each set is completely connected to with weighted edges, where is an arbitrary real value with . Thus, the priority of each set is the vertices of . We also have a complete connection between and whose edge weights equal a real value . Note that the priority of the vertices of is the vertices of , thus .

Notice moreover that, since for each vertex , the vertices of should have priority over the vertices of , we havefor all , , and . Thus,for all and . Therefore,

Therefore, we have

Observe that , since otherwise, we would have , and thus, . This is a contradiction.

Observe that we have

Note that must be a complete bipartite graph. Thus, if there does not exist an edge between any two vertices and , we assume that an infinite weighted edge connects and , i.e., .

We claim that from a minimum-weight perfect matching in denoted by , we can get a minimum-cost MMDC between and . Let be the set of the main edges of . Let denote a minimum-cost MMDC between and . In the following, we prove that the weight of , i.e., , is equal to the cost of , i.e., .

Lemma 1. .

Proof. We get from a perfect matching in our complete bipartite graph such that the weight of equals the cost of , i.e., .
Let be the number of the elements with matched to in . It is obvious that . Firstly, for each pairing with in , we select the edge of connecting to an arbitrary free vertex with , and add to until there does not exist any free vertex in . Then, depending on the value of , two cases arise as follows:(i)either . In this situation, we select the weighted edges of connecting each to an arbitrary free vertex of for and add to .(ii)or . In this case, we match number of vertices of to the vertices of as follows. For each of the remaining pairings with in that have no equivalent edges in , we add the edge of connecting to an arbitrary free vertex with to . Then, if there exist free vertices in (since ), for each of them, we select an edge of connecting it to an arbitrary free vertex of and add to .Then, we add the edges of connecting each to an arbitrary free vertex of for to . Now, the vertices of are matched to the vertices of , unless no free vertices remain in . Thus, we first add the edges connecting the vertices of pairwise to the remaining free vertices of . Then, we add the edges connecting the free vertices of , if exist, to the free vertices of pairwise to .
Observe that is a perfect matching, since each vertex of is incident with exactly one edge in . For each , there exists an edge with equal weight in , thus .

Lemma 2. Let be a minimum-weight perfect matching in . Then, for any perfect matching in denoted by , we have

Proof. Observe that we haveNote thatObserve that the set contains(i)the zero weighted edges connecting the vertices of to for , with a total number of ,(ii)the weighted edges connecting number of vertices of to for ,(iii)the weighted edges connecting number of vertices of to for ,(iv)the weighted edges connecting number of vertices of to for .Thus,So, we haveNote that is a minimum-weight perfect matching in , thusTherefore, we haveFrom the above lemma, we have . Notice that , thus

Lemma 3. .

Proof. From , we get an MMDC between and denoted by whose cost is equal to the weight of , i.e., . For each edge , we add the pairing to if or , and no pairing otherwise.
For each , there exists the set in with vertices, which are connected only to one set, i.e., , with finite edge weights. Thus, the vertices of each are matched to some vertices of , i.e., with . Hence, in , each is matched to at least elements of (and thus, the demand of is satisfied) for . In , there exist plus copies of each element , that is the vertices of plus the vertices of . Thus, in , the number of elements matched to each is at most .
Consider the sets with . Recall that and the vertices of are connected to by zero weighted edges. is connected only to (with finite edge weights), thus the vertices of are matched to vertices of , and vertices of remain free. Suppose that number of free vertices in are matched to some vertices of the sets for , then the remaining vertices of should be matched to other vertices. We discuss two cases, depending on the value of .(i)if , then . In this case, the vertices of are matched to number of the remaining vertices of . We havethus the remaining vertices of are matched to some vertices of the sets for . Note that and vertices of are matched to some vertices of the sets and , respectively, for . The demand of the element is satisfied, since(ii)if , then . Thus, all the remaining vertices of are matched to the vertices of .The cost of is equal to the weight of , i.e., , since for each edge of , we add a pairing with equal cost to . is a minimum-cost MMDC between and , thus . Therefore,

Theorem 1. Let be a minimum-weight perfect matching in , and let be a minimum-cost MMDC between and . Then, .

Proof. From Lemmas 1 and 3, we have and , respectively. Thus, .
Recall that the time complexity of the Hungarian algorithm is , where the number of vertices of the input graph is . Our complete bipartite graph has vertices (by construction), so our algorithm takes time. Observe that when , we have (for example, when a very large number of distributed access points must be matched to a much smaller number of mobile stations [21], or limited resources are matched to a massive number of targets [22]), and thus, our algorithm runs in time. Moreover, in bipartite graphs with low-range edge weights, our algorithm runs well due to [19]
As an example, consider two sets and withThen, we haveAlso, we haveOur constructed complete bipartite graph for the above example is shown in Figure 2.

3. Conclusion

In this article, we presented an algorithm for finding a minimum-cost MMDC between two sets and , where each element of (resp. ) must be matched to at least and at most given numbers of elements of (resp. ). We constructed a complete bipartite graph with , where . Then, we used the Hungarian algorithm with the input to find a minimum-cost MMDC between and in time. Our constructed complete bipartite graph can be used as the input for the modified Hungarian algorithm proposed in [11] for computing a minimum-cost MMDC between and in time when and are points in the plane. Observe that when , running the Hungarian algorithm (and the modified Hungarian algorithm proposed in [11]) on takes (and ) time. It is expected that the computational complexity of the MMDC problem will be reduced by exploiting the geometric information. One could study the two-dimensional MMDC as a future work, where and are points on the plane. We could also consider the case in which and are points on two perpendicular lines. The online MMDC is another open problem where the elements of arrive online.

Data Availability

No data were used to support this study.

Disclosure

The preprint of this article is available in [23].

Conflicts of Interest

The authors declare that they have no conflicts of interest.