Perfect Matching

Abstract

This is pseudocode for Perfect Matching in Bipartite Graphs, adapted from the paperback edition of A Gentle Introduction to Optimization, B. Guerin et al. This is used as a subroutine to find any perfect matching on a subgraph of the larger bipartite graph in the Hungarian Algorithm, whose goal is to find a minimum weight perfect matching.

The operator Δ is essentially an exclusive OR (XOR) of the two sets:

M⁢Δ⁢P=(M∪P)∖(M∩P). (1)

Executed on an alternating paths of links included in versus excluded from the set and a second path including at leaast part of that first set, it has the behavior of flipping the ones included versus excluded.

I believe this algorithm as stated assumes that the input graph H is connected.

\SetAlgoCaptionSeparator

.4

{algorithm}

Perfect Matching

\AlgoDisplayBlockMarkers\AlgoDisplayGroupMarkers\SetAlgoBlockMarkers

{ } \SetAlgoNoEnd\SetAlgoNoLine

\SetKwInOut

InputInput\SetKwInOutOutputOutput \InputBipartite graph H=(V,E) with bipartition U,W where |U|=|W|≥1 \OutputA perfect matching M, or a deficient set B ⊆ U. M:=∅
T:=({r},∅) where r∈U is any M-exposed vertex
\While(1) \uIf∃ u⁢v where u ∈ B⁢(T) and v∉V⁢(T) \uIfv is M-exposed P:=Tr⁢u∪{u⁢v}
M:=M⁢Δ⁢P
\lIfM is a perfect matchingstop T:=({r},∅) where r∈∪ is any M-exposed vertex. \Else Let w∈V where v⁢w∈M
T:=(V⁢(T)∪{v,w},E⁢(T)∪{u⁢v,v⁢w}) \Else stop B⁢(T)⊆U is a deficient set