Diskrete Mathematik Und Optimierung
Diskrete Mathematik Und Optimierung
Diskrete Mathematik Und Optimierung
FernUniversität in Hagen
Lehrgebiet Mathematik
Lehrstuhl für Diskrete Mathematik und Optimierung
D – 58084 Hagen
2000 Mathematics Subject Classification: 91A12, 91B68
Keywords: Assignment Game, Core, Hungarian Method, Stable Matching
The Hungarian Method in a Mixed Matching
Market
Winfried Hochstättler Hui Jin
Department of Mathematics Department of Mathematics
FernUniversität in Hagen BTU Cottbus
D-58084 Hagen D-03013 Cottbus
Robert Nickel
Department of Mathematics
FernUniversität in Hagen
D-58084 Hagen
November 24, 2005
Abstract
We present an algorithm that computes a stable matching in a common
generalization of the marriage and the assignment game in O(n4 ) time.
1 Introduction
Since its introduction by Gale and Shapley [11] the stable marriage problem has
become quite popular among scientists from different fields such as game theory,
economics, computer science, and combinatorial optimization. Among others
this is mirrored by three monographs: Knuth [15], Gusfield and Irving [13], Roth
and Sotomayor [21]. The problem is the following: Given two disjoint groups of
players (men-women or workers-firms etc.), where each player is endowed with
a preference list on the other group, the objective is to match the players from
one group to players from the other group such that there is no pair which is
not matched but prefers each other over their partners. Gale and Shapley [11]
showed that such a stable matching always exists. The proof is algorithmic
and the algorithm has become famous under the name “men propose – women
dispose”.
In their award winning book Roth and Sotomayor [21] observed that the
set of stable solutions from another game on bipartite matching, namely the
assignment game [22], has several structural similarities with the set of stable
matchings. They challenged the readers to find a unifying theory for the two
games. In the assignment game we are given a weighted bipartite graph. A
solution consists of a matching and an allocation of its weight to the players.
1
A solution is stable if no pair gets allocated less than the weight of its con-
necting edge. Shapley and Shubik [22] observed that this condition is identical
to the dual constraints of the linear programming model for weighted bipartite
matching, thus the dual variables in an optimal solution coincide with the stable
allocations. However, algorithms and complexity issues of game theoretic solu-
tion concepts have raised attention only recently (see e. g. [3], [6], [2]) and the
classical algorithm for weighted bipartite matching, namely what is nowadays
called the Hungarian Method ([8]), is not as prominent in game theory as it
is in combinatorial optimization. However, Demange et al. [1] claim that their
“exact” auction procedure that proves the existence of stable solutions were a
variant of Kuhn’s [16] method.
Roth and Sotomayor [20] themselves presented a first model unifying stable
matching and the assignment game and showed that its set of stable solutions, if
it is non-empty, has the desired structural properties. Eriksson and Karlander [5]
modified this model to the one presented in this paper and gave an algorithmic
proof of the existence of a stable solution. For the classical special cases, their
algorithm coincides with “men propose – women dispose”, respectively with
the “exact” auction procedure of [1]. As implemented, this algorithm is not
polynomial time but pseudopolynomial. Also it yields a proof of the existence
of stable solutions in presence of irrational data only via arguments from non-
standard analysis. A careful analysis [14] of the algorithm, though, reveals that
a proper implementation solves the problem in O(n4 ) similar to the algorithm
presented here.
Sotomayor [23] gave an alternative proof of the existence of stable solutions
of the model of Eriksson and Karlander. The purpose of the present paper is
to extract an algorithm from the key lemma of Sotomayor [23] that computes a
stable solution in O(n4 ). In the case of the assignment game this algorithm
specializes to the implementation of the Hungarian Method where a search
tree (and not a forest) is grown starting from a single unmatched vertex. For
stable marriage we derive a sort of asynchronous implementation of the original
“men propose – women dispose” that does not proceed in rounds and, hereby,
corresponds to efficient implementations of that algorithm (see e. g. Gusfield and
Irving [13]).
Fujishige and Tamura [9] presented a market model in the theory of discrete
convex analysis (see [19]) with M \ -concave utility functions that contains the
Stable Marriage Model of [11], the Assignment Game of [22], and the model
of Eriksson and Karlander [5], as well as other recently published models ([4],
[7], [10]) as special case. They present a pseudopolynomial time algorithm to
find a stable solution for the general model which becomes polynomial when
restricted to instances of the present model. A careful analysis reveals that it
can be implemented with only slightly worse complexity. In the last section we
will discuss this in more detail.
In the next section we introduce the model, discuss its special cases in Sec-
tion 3 and present and analyze our algorithm in Section 4. We assume some
familiarity with bipartite matching and combinatorial optimization. Our nota-
tion should be fairly standard.
2
2 Notation
The following model, originally introduced by Eriksson and Karlander [5], dis-
plays a two-sided market, where we have two types of players, P and Q which
we call firms and workers. Moreover, both sets are again subdivided into flexible
(F ) and rigid players (R) so that P ∪Q ˙ = F ∪R.
˙ If a firm i ∈ P is matched to
a worker j ∈ Q they get a certain benefit aij + bij from that relationship. If
both players are flexible, they can negotiate on how to split up this amount. If
at least one player is rigid i receives aij and j receives bij .
Thus, mathematically we have the following. Let G = (P ∪ Q, E, a, b) be a
complete bipartite graph with two non-negative weight functions a, b : E → R+
˙ = F ∪R
and P ∪Q ˙ another partition of the vertices.
A set M ⊆ E is called a matching if each vertex of G is contained in at most
one edge of M and we denote by VM ⊆ V the set of matched vertices of G. A
pair of functions u : P → R and v : Q → R is called a payoff. An outcome of
the game is a triple (u, v; M ) consisting of a payoff and a matching. Such an
outcome (u, v; M ) is called feasible if
Note that this notion of stability coincides with Eriksson and Karlander [5]
and [23] only for outcomes. A pair (i, j) ∈ P × Q that violates one of (i) and (ii)
of Definition 2.1 is called a blocking pair. For any blocking pair (i, j) we define
if (i, j) ∈ F ∗
aij + bij − vj
uji :=
aij if (i, j) ∈ R∗ .
A blocking partner j that maximizes uji is called i’s favorite blocking partner.
3
3 Special Cases
If one of F or R is empty the model from the last section reduces to the well-
known stable marriage resp. assignment game. In this section we will discuss
these models and recall an algorithm for each of them that we will merge into
a single algorithm for the mixed model in Section 4.
4
Algorithm 2 Modified Hungarian Method
1: procedure WeightedBipartiteMatching
2: for all i ∈ P do
3: ui ← max({aij + bij | j ∈ Q})
4: end for
5: while (u, v; M ) is not stable do
6: if ∃ augmenting path P in G(u,v;M ) then
7: alternate(P)
8: else
9: i ← unmatched firm
10: HungarianUpdate(i)
11: end if
12: end while
13: end procedure
5
as a directed subgraph of G with edge set
E(u,v;M ) := {(j, i) | (i, j) ∈ M } ∪ {(i, j) | j ∈ Di (u, v; M )},
where
Di (u,v; M ) := {i’s favorite blocking partners}
∪ {j ∈ Q | (i, j) ∈ F ∗ \ M and ui + vj = aij + bij }
∪ {j ∈ Q | (i, j) ∈ R∗ \ M and ui = aij and vj < bij }.
The following path augmentation argument is a slight modification of So-
tomayor [23, Lemma 1].
Lemma 4.1. Let (u, v; M ) be a feasible outcome such that no matched firm is
contained in a blocking pair. If there is an unmatched firm i1 with a blocking
partner then there exists a feasible outcome (ũ, ṽ; M ) and an oriented path P in
G(ũ,ṽ;M ) starting from i1 that reaches a player of R, an unmatched worker or a
firm with payoff zero.
Proof. Let P̄ ⊆ P and Q̄ ⊆ Q be the firms and workers reachable from i1
in G(u,v;M ) (let i1 be included in P̄ ). If i1 ∈ R we can set P = {i1 } and
(ũ, ṽ; M ) = (u, v; M ). Now let i1 ∈ F and assume there is no such path. Then
(P̄ ∪ Q̄) ∩ R = ∅, VM ∩ Q̄ = Q̄ and ui > 0 ∀i ∈ P̄ \ {i1 }. If i ∈ P̄ \ {i1 } then i
is matched and by assumption is not contained in any blocking pair, i. e. for all
j ∈ Q ui ≥ aij + bij − vj and if j ∈ R then either ui ≥ aij or vj ≥ bij . For each
edge (i, j) ∈ (P̄ \ {i1 }) × (Q \ Q̄) it, thus, follows from the definition of G(u,v;M )
that ui > aij + bij − vj and if j ∈ R and vj < bij then ui > aij . Now let
6
The modification of the payoffs in the above proof is similar to the update
of the dual variables in HungarianUpdate. A major difference is that the
Hungarian Method always ensures dually feasible variables, namely ui + vj ≥
aij + bij ∀(i, j) ∈ P × Q. In our terms this corresponds to a stable payoff.
We adapt this idea and introduce virtual payoffs denoted by ūi for all firms
such that no edge (i, j) ever forms a blocking pair in the (infeasible) outcome
(ū, v; M ) during the algorithm. Thus ui is the allocation that we can afford
from the current matching and ūi is an upper bound on the highest possible
benefit of firm i from the current market situation. Our approach thus becomes
similar to complementarity algorithms known from combinatorial optimization:
We have a (primal) feasible matching M and a stable (dual feasible) payoff
(ū, v). Optimality is reached when ūi > 0 implies that i is matched for all i.
The algorithm then can be outlined as follows: We start with an empty
matching, payoff zero for all workers, and the maximum possible individual vir-
tual payoff for each firm. Throughout the algorithm we ensure that no firm
that has a matching partner belongs to a blocking pair. As long as there are
blocking pairs, we consider the connected component of the corresponding un-
matched firm i formed by Di and construct a path as in Lemma 4.1. For that
purpose we, eventually, modify the outcomes. Once such a path is found we
either increment the matching, check off a firm, or check off an edge from R∗ .
We first adjust HungarianUpdate choosing ∆ as in (1-3). Furthermore we
modify ū for all vertices in P̄ and u for all vertices in P̄ \ {i1 } (see Algorithm 3).
In the next section we will discuss how we implement the update of the
7
Algorithm 4 Construction of a Stable Outcome
1: (u, v; M ) ← (0, 0; ∅)
2: for all i ∈ P do
3: ūi ← max ({aij + bij | (i, j) ∈ F ∗ } ∪ {aij | (i, j) ∈ R∗ })
4: end for
5: while blocking pair (i1 , j) exists do
6: while there is no path P as in Lemma 4.1 do
7: HungarianUpdate(i1 )
8: end while
9: PathUpdate(P)
10: end while
outcome according to P.
CheckOff(i) sets ūi ← ui ← 0. Such a firm will never ever form a blocking
pair.
8
Algorithm 5 Augmentation along the path P
procedure PathUpdate(P)
F
z }| {
if P = (i1 , j1 , . . . , is , js ) and js unmatched then . CASE 1
Alternate(P)
Update(i1 , j1 )
Update(is , js )
F
z }| {
else if P = (i1 , j1 , . . . , is−1 , js−1 , is ), uis = 0 then . CASE 2
Alternate(P)
Update(i1 , j1 )
CheckOff(is )
else
if P = (. . . , is ) and Dis (u, v; M ) 6= ∅ then
P ← Pjs for some js ∈ Dis (u, v; M )
end if
R∗
if P = (i1 , j1 ) then . CASE 3.1
Unmatch(j1 )
Alternate((i1 , j1 ))
Update(i1 , j1 )
F
z }| { R∗
else if P = (i1 , j1 , . . . , is−1 , js−1 , is , js ) then . CASE 3.2
Unmatch(js )
Alternate(P)
Update(i1 , j1 )
Update(is , js )
F
z }| { R F
else if P = (i1 , j1 , . . . , ik , jk = js , . . ., is , js ) then . CASE 3.3
Alternate(P[jk ,js ] )
Update(is , js )
F
z }| { R
else if P = (i1 , j1 , . . ., is ) and Dis (u, v; M ) = ∅ then . CASE 3.4
Unmatch(js−1 )
Alternate(P[i1 ,js−1 ] )
Update(i1 , j1 )
if is has blocking partner then . CASE 3.4a
js ← favorite blocking partner of is
PathUpdate((is , js ))
else . CASE 3.4b
CheckOff(is )
end if
end if
end if
end procedure
9
4.2 Correctness and Complexity
We are now going to prove that Algorithm 4 is correct and show at first that
Algorithm 5 covers all cases. If P is a path that lies completely in F, then, by
construction, P either ends in an unmatched worker (CASE 1) or a firm with
payoff zero (CASE 2). Now let the end vertex k of P be in R. If k ∈ Q then
CASE 3.1 or CASE 3.2 applies. Now let is ∈ P ∩ R be the end vertex of P.
If Dis (u, v; M ) = ∅ then CASE 3.4 applies. Otherwise, PathUpdate chooses
some js ∈ Dis (u, v; M ). If js is already contained in P we add js to the end
of P and are in CASE 3.3. Otherwise, we add js to the end of P and are in
CASE 3.1 or 3.2. The correctness of the main procedure now directly follows
from some invariants of the algorithm.
a) (u, v; M ) is feasible.
d) (ū, v) is stable.
h) Once a firm has been checked off it will never be matched again.
Proof. In the first step of the algorithm all conditions hold as we start with a
sufficiently large virtual payoff ū and an outcome (0, 0; ∅). Now assume condi-
tions a) to h) are true for the current step of the algorithm. We show that this
is still true after the next call of the procedures considered.
10
h) A firm i is checked off in CASE 2, if it was matched, and thus had no
blocking partner by b), with ui = ūi = 0 and has become unmatched. Or
it has become unmatched, enforcing ui = 0 and has no blocking partner in
CASE 3.4. In that case we can set ūi = 0 and remain dually feasible. By
f) and as aij and bij are non-negative i will never have a blocking partner
again. After the algorithm has terminated we may match such a firm to
some unmatched vj , necessarily satisfying aij = 0.
Hence, d) holds as in any case ūi + vj ≥ aij + bij holds for all edges in F ∗
and ūi ≥ aij for all edges in R∗ . As ūi changes at most if i was unmatched,
e) follows from the fact that ūi was dually feasible before the procedure
call and is now changed to the minimal value guaranteeing dual feasibility.
CASES 1 and 2 : All edges along P are tight except for the first edge which is
made tight by Update. Hence, all newly matched edges are tight. Before
11
(i, j) is updated we have
and therefore ui1 > 0 after the update and the outcome is feasible. There
are no new blocking pairs since v is not changed, i1 is matched to its
favorite blocking partner and there is no other newly matched firm. In
CASE 2 a firm is checked off but actually this step does nothing as has
been discussed before.
CASE 3.1: The feasibility is obvious and there are no newly matched firms
instead of i1 which is matched to its favorite blocking partner.
CASE 3.2: Again, the new outcome is still feasible. i1 has no blocking partner
after it is matched to its favorite. Since (is , js ) ∈ R∗ we have uis = ais js
and vjs < bis js . Hence, an update does not change the outcome of is and
makes js less attractive to other firms.
CASE 3.4: If is does not have any new blocking partner then vj ≥ ais j + bis j
for all j ∈ Q and we can set ūis ← 0 without violating d). Therefore a)
and b) are obviously still true. Otherwise, is is matched to its favorite
blocking partner.
Proposition 4.3. After every call of PathUpdate one of the following state-
ments holds:
12
CASE: 1 2 3.1 3.2 3.3 3.4a 3.4b
|M | increases • – ◦ ◦ – ◦ –
firm checked off – • – – – – •
rigid edge checked off – – • • • • –
Any column in Table 1 contains a bullet, hence at least one statement holds.
Proof. From Lemma 4.1 we conclude that as long as there is some blocking pair
there also must be a path P in line 9 of Algorithm 4. The matching can be
augmented at most |Q| times, there are only |P | firms to check off, and at most
|P | · |Q| edges to be checked off in R∗ . The correctness thus follows from Lemma
4.2 and Proposition 4.3.
There is not much work left to derive an implementation that runs in O(n4 ).
By Proposition 4.3 all that is left to show is that we can implement the while-
loop in line 6 of Algorithm 4 to be passed in O(n2 ). For that purpose we use a
standard implementation of the Hungarian Method see e. g. Galil [12].
For any fixed j ∈ Q we store a value ∆j corresponding to ∆ in (1)-(3) being
the gap between j and P̄ ∪ Q̄, i. e.
13
unmatched firm becomes a tree which is rooted by a matched player. We had
no idea of a data structure that could help to efficiently recycle the data.
The advantage of the implementation discussed in the proof of Theorem 4.4
is that in any stage of the hungarian update one keeps track of the “distance” of
unmatched and rigid players from the current component P̄ ∪ Q̄. Those values
can be updated in linear time when the payoffs in P̄ ∪ Q̄ are altered by ∆. In the
situation described in the above paragraph it seems to be difficult to update this
data in linear time. Such a linear time update would lead to an O(n3 )-algorithm
having the same complexity as the Hungarian Method.
Example 1. Let P = {1, 2}, Q = {3, 4}, F = {1, 3, 4}, R = {2}, and
a13 a14 10 5 b13 b14 0 0
:= and := .
a23 a24 6 2 b23 b24 6 2
For this example Algorithm 4 gives the stable outcome (u, v; M ) with
14
5.2 The Algorithm of Fujishige and Tamura [9] for a More
General Model
Fujishige and Tamura [9] introduce a more general market model that contains
the models of [11, 22, 5, 7, 4, 10] as special cases and constructively prove
the existence of a pairwise stable outcome by presenting an algorithm that is
pseudopolynomial with respect to the volume of the domain of an M \ -concave
function. This algorithm becomes polynomial if restricted to instances of the
model of Eriksson and Karlander [5] and furthermore, in some aspects reminds
of the algorithm in [14]. It also consists of two main stages where the first
stage ensures that any firm gets at most one rigid proposal ([9, Case 1]) and
the second stage either finds an augmenting path or adjusts payoffs until such a
path exists ([9, Case 2]). However, the concepts of augmenting paths differ and
the augmentation graph used in [9] is different since vertices are identified with
edges of the original graph. Since the augmentation graph is sparse, a careful
analysis of the algorithm in [9] yields a complexity of O(n2 (n2 + g(n2 , n2 , C) +
h(n2 , n2 , C))), where g(n, m, C) is the complexity of a procedure that computes
the shortest distances from a fixed set of sources S to all other vertices, and
h(n, m, C) is the complexity to compute one shortest path from S to T using
a minimum number of arcs, both in a digraph with n vertices, m arcs, and
positive arc weights bounded by C = max(i,j)∈P ×Q {aij + bij }.
For further details of the algorithm which go beyond the scope of this paper
we refer the reader to Fujishige and Tamura [9] and Moriguchi and Murota [18].
References
[1] Gabrielle Demange, David Gale, and Marilda Sotomayor. Multi-item auc-
tions. Journal of Political Economy, 94(4):863–872, 1986.
[2] Xiaotie Deng, Toshihide Ibaraki, and Hiroshi Nagamochi. Combinatorial
optimization games. In Proceedings of the 8th Annual ACM-SIAM Sympo-
sium on Discrete Algorithms, pages 720–729, New Orleans, LA, 1997.
[5] Kimmo Eriksson and Johan Karlander. Stable matching in a common gen-
eralization of the marriage and assignment models. Discrete Mathematics,
217(1-3):135–156, 2000.
15
[6] Ulrich Faigle, Sandor P. Fekete, Winfried Hochstättler, and Walter Kern.
On the complexity of testing membership in the core of min cost spanning
tree games. International Journal of Game Theory, 26:361–366, 1997.
[10] Satoru Fujishige and Akihisa Tamura. A general two-sided matching mar-
ket with discrete concave utility functions. Discrete Applied Mathematics,
154(6):950–970, 2006.
[11] David Gale and Lloyd S. Shapley. College admissions and the stability of
marriage. American Mathematical Monthly, 69:9–15, 1962.
[12] Zvi Galil. Efficient algorithms for finding maximum matchings in graphs.
ACM Computing Surveys, 18(1):23–38, 1986.
[13] Dan Gusfield and Robert W. Irving. The stable marriage problem: Struc-
ture and algorithms. MIT Press, Cambridge, MA, USA, 1989.
[14] Winfried Hochstättler, Hui Jin, and Robert Nickel. Note on an auction
procedure for matching games in polynomial time. In AAIM Proceedings,
pages 387–394, 2006.
[15] Donald E. Knuth. Stable marriage and its relation to other combinatorial
problems. In CRM Proceedings and Lecture Notes, volume 10. American
Mathematical Society, 1997.
[16] Harold W. Kuhn. The Hungarian method for the assignment problem.
Naval Research Logistics Quaterly, 2:83–97, 1955.
[17] Harold W. Kuhn. Variants of the Hungarian method for the assignment
problem. Naval Research Logistics Quaterly, 3:253–258, 1956.
[18] Satoko Moriguchi and Kazuo Murota. Capacity scaling algorithm for scal-
able M -convex submodular flow problems. Optimization Methods and Soft-
ware, 18(2):207–218, 2003. The Second Japanese-Sino Optimization Meet-
ing, Part I (Kyoto, 2002).
16
[19] Kazuo Murota. Discrete convex analysis. SIAM Monographs on Discrete
Mathematics and Applications. Society for Industrial and Applied Mathe-
matics (SIAM), Philadelphia, PA, 2003.
[20] Alvin E. Roth and Marilda Sotomayor. Stable outcomes in discrete and
continuous models of two-sided matching: A unified treatment. Revista
de Econometria, The Brazilian Review of Econometrics, 16(2), November
1996.
[22] Lloyd S. Shapley and Martin Shubik. The assignment game I: The core.
International Journal of Game Theory, 1:111–130, 1972.
[23] Marilda Sotomayor. Existence of stable outcomes and the lattice property
for a unified matching market. Mathematical Social Sciences, 39:119–132,
2000.
17