Minimum Cost Perfect Matching

Abstract

This is pseudocode for the Hungarian Algorithm for Minimum Cost Perfect Matching in Bipartite Graphs, adapted from the paperback edition of A Gentle Introduction to Optimization, B. Guerin et al. This finds subgraphs of the original bipartite graph (which is often a complete bipartite graph), and uses the Perfect Matching algorithm as a subroutine to figure out if there is a perfect matching, in which case we are done.

\SetAlgoCaptionSeparator

.5

NH(S) is the set of neighbors of the set S on the graph H. One thing I do not like about this particular pseudocode is that the interface with the perfect matching subroutine is imprecise, and this algorithm depends on side effects from that subroutine. The subroutine might return (a) a new (larger) matching M, (b) a new (larger) tree T, or (c) a deficient set for that particular graph H.

{algorithm}

Minimum cost perfect matching in bipartite graphs (fast version)

\AlgoDisplayBlockMarkers\AlgoDisplayGroupMarkers\SetAlgoBlockMarkers

{ } \SetAlgoNoEnd\SetAlgoNoLine

\SetKwInOut

InputInput\SetKwInOutOutputOutput\SetKwRepeatDodoWhile\InputBipartite graph G=(V,E) with bipartition U,W where |U|=|W|1 \OutputA minimum cost perfect matching M or a deficient set S M:=
T:=({r},) where rU is any M-exposed vertex
yv:=12min{ce:eE}, for all vV

\While

(1) Construct graph H (a subset of the original graph G)
with vertices V and edges {uv E : cuv = yu + yv}
Invoke the subroutine (Algo. 3.4) with H,M, and T

\uIf

outcome (a) of subroutine occurs \uIfM is a perfect matching of H stop (M is minimum cost perfect matching of G) \ElseIfoutcome (c) of subroutine occurs Let S:=B(T)
\lIfall edges of G with an endpoint in S have an endpoint in NH(S) stop (G has no perfect matching) Otherwise, adjust the costs to create a new zero, and loop ϵ=min{cuv-yu-yv:uS,vV(T)}

yv:={yv+ϵ for vSyv-ϵ for vNH(S)yv otherwise  (1)
\ElseIf

outcome (b) of subroutine occurs Just loop again with augmented path