fanny dufoss e & bora u˘carperso.ens-lyon.fr/bora.ucar/cr02/lecture-matching.pdf · matching...

62
Matching and the block triangular form Fanny Dufoss´ e & Bora U¸ car Inria, Grenoble Rhˆ one-Alpes & CNRS and ENS Lyon, France CR02: Combinatorial scientific computing, October 2019 http://perso.ens-lyon.fr/bora.ucar/CR02/ 1/62 CR02

Upload: others

Post on 19-Apr-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

Matching and the block triangular form

Fanny Dufosse & Bora Ucar

Inria, Grenoble Rhone-Alpes & CNRS and ENS Lyon, France

CR02: Combinatorial scientific computing, October 2019http://perso.ens-lyon.fr/bora.ucar/CR02/

1/62 CR02

Page 2: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Outline

1 The block triangular formThe BTF, computation and propertiesBipartite matching

2 Algorithms for max cardinality bipartite matching

2/62 CR02

Page 3: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Definitions: Reducibility

Reducible matrix: An n × n square matrix is reducible if there exists ann × n permutation matrix P such that

PAPT =

(A11 A12

O A22

),

where A11 is an r × r submatrix, A22 is an (n − r)× (n − r) submatrix,where 1 ≤ r < n.

Irreducible matrix: There is no such permutation matrix.

Theorem: An n × n square matrix is irreducible iff its directed graph isstrongly connected.

3/62 CR02

Page 4: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Definitions: Fully indecomposability

Fully indecomposable matrix: There is no permutation matrices P and Q suchthat

PAQ =

(A11 A12

O A22

),

with the same condition on the blocks and their sizes as above.

Decomposable matrix: There are permutation matrices P and Q such that thepermuted matrix PAQ is of the form above.

In general we are interested in fully indecomposable A11 and A22. That is, thematrices in the block triangular form

PAQ =

A11 A12 · · · A1K

O A22 · · · A2K

......

. . ....

O O · · · AKK

,

where each Akk is fully indecomposable.

4/62 CR02

Page 5: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Definitions: Fully indecomposability

Fully indecomposable matrix: There is no permutation matrices P and Qsuch that

PAQ =

(A11 A12

O A22

),

with the same condition on the blocks and their sizes as above.

Theorem: An n × n square matrix A is fully indecomposable iff for somepermutation matrix Q, the matrix AQ is irreducible and has a zero-freemain diagonal.

Gives a three step algorithm (we specify for square matrices):

1 Find a perfect matching in the bipartite graph of the matrix,

2 Permute the matrix to have a zero free diagonal,

3 Find the strong components of the directed graph of the permutedmatrix.

5/62 CR02

Page 6: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Solving Ax = b in BTF

Find Ax = b using PAQy = Pb, with

PAQ =

A11 A12 · · · A1K

O A22 · · · A2K

......

. . ....

O O · · · AKK

,

where Akk contains indices r(k)-to-r(k + 1)− 1.

A← PAQ. permute A in into BTFx← Pb. permute bfor k = K downto 1 do

I ← 1 : r(k)− 1. indices above the kth blockJ ← r(k) : r(k + 1)− 1. indices of the kth blockx(J)← A(J, J)\x(J)x(I )← x(I )− A(I , J)× x(J)

x ← Qx. undo the permutation

6/62 CR02

Page 7: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Define rank, structural rank

Rank of a matrix A: the size of the largest collection of linearlyindependent columns of A

Structural rank of A: the size of the maximum cardinality matching in itsbipartite graph. Called sprank in Matlab.

Are they equal (Class???)?

7/62 CR02

Page 8: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

BTF: Basic definitions

Bipartite graph representation is used for rectangular matrices andalso unsymmetric matrices.

The bipartite graph H of a matrix A has two sets of vertices (R andC ) corresponding to respectively the row and columns indices of Asuch that ar ,c 6= 0⇔ (r , c) ∈ H(A)

A bipartite graph with m rows and n columns (with m ≥ n) has theHall property if every set of k column vertices is adjacent to at leastk row vertices for all 0 < k ≤ n.

Hall’s theorem

A bipartite graph has a column matching iff it has the Hall property.

Proof later

8/62 CR02

Page 9: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Strong Hall property

A bipartite graph with m rows and n columns (with m ≥ n) has thestrong Hall property if every set of k column vertices is adjacent toat least k + 1 row vertices for all 0 ≤ k < n.

Any matrix that has Hall property, but not strong Hall can bepermuted in block triangular form, with square diagonal blocks.

Decomposable matrix: There are per-mutation matrices P and Q such that

PAQ =

A11 A12 · · · A1K

O A22 · · · A2K

......

. . ....

O O · · · AKK

,

with each diagonal block beingsquare and fully indecomposable (fora square matrix; rectangulars are afew slides ahead).

9/62 CR02

Page 10: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Finding the BTF

The block triangular form is based on a canonical decomposition ofbipartite graphs known as the Dulmage-Mendelsohn decomposition (late50s, early 60s; Pothen’84, Pothen and Fan’90, Duff and Ucar’09).

A two (or three) step algorithm (for square, full sprank sparse matrices)

1 Find a perfect matching in the bipartite graph of the matrix,

2 Permute the matrix to have a zero free diagonal,

3 Find the strong components of the directed graph of the permutedmatrix.

10/62 CR02

Page 11: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Matching in bipartite graphs and permutations

A matching in a graph is a set of edges no two of which share a commonvertex. We deal mostly with matchings in bipartite graphs.

In matrix terms, a matching in the bipartite graph of a matrixcorresponds to a set of nonzero entries no two of which are in the samerow or column.

A vertex is said to be matched if there is an edge in the matchingincident on the vertex, and to be unmatched otherwise. In a perfectmatching, all vertices are matched.

The cardinality of a matching is the number of edges in it. A maximumcardinality matching or a maximum matching is a matching of maximumcardinality.

11/62 CR02

Page 12: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Matching in bipartite graphs and permutations

Given a square matrix whose bipartite graph has a perfect matching, sucha matching can be used to permute the matrix such that the matchingentries are along the main diagonal.

1

r2

r3 3c

2c

1cr

1 2 3

1 × ×2 × ×3 ×

2 1 3

1 × ×2 × ×3 ×

=

1 2 3

1 × ×2 × ×3 ×

1 2 3

1 12 13 1

12/62 CR02

Page 13: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

The BTF

A two (or three) step algorithm for square full sprank matrices.

1 Find a perfect matching in the bipartite graph of the matrix,

2 Permute the matrix to have a zero free diagonal,

3 Find the strong components of the directed graph of the permutedmatrix.

The strong components found in the last step are independent of thematching found in the first step.

13/62 CR02

Page 14: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

The BTF

The strong components found in the last step are independent of thematching found in the first step (figure from J. Gilbert).!"#$%&'()**'+$,-.')#/'0%1/-/%1/%"'$2',)"+30%&!"#$%&'()**'+$,-.')#/'0%1/-/%1/%"'$2',)"+30%&

! "# $ % & '

!

"

#

$

%

&

'

! "# $ % & '

$

"

!

%

#

'

&

!

"

#

&

$

!

"

#

&

$

%

'

%

'

!

"

#

&

$

!

"

#

&

$

%

'

%

'

!! ##

&&

$$%%

''

""

$! !#

'&

%$

#%

&'

""

14/62 CR02

Page 15: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Matching: Definitions

A matching M is a set of edges if no two edges in M are incident on thesame vertex.

A vertex is said to be matched (with respect to a given matching) ifthere is an edge in the matching incident on the vertex, and to beunmatched otherwise.

15/62 CR02

Page 16: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Matching: Definitions

M-alternating walk is a sequence of edges where every second edge is inM.

M-alternating tour is an alternating walk that starts and ends at thesame vertex.

M-alternating path is a path whose edges are alternately in M and notin M.

uM−−→ v denotes that vertex u reaches vertex v with an M-alternating

path (we assume that u and v are different, in other words an alternatingpath has at least one edge).

M-alternating cycle is an alternating walk without repeated verticesother than the start and end vertices.

16/62 CR02

Page 17: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Hall’s theorem (proof)

A bipartite graph G with m rows and n columns (with m ≥ n) has acolumn matching iff it has the Hall property (every set S of k columnvertices is adjacent to a set N(S) of at least k row vertices for all0 < k ≤ n.

Proof

〈〈 On the board....

if G has a perfect matching, |S | ≤ |N(S)| for any S .

Assume for all S we have |S | ≤ N(S). Let us suppose that but wedo not have a perfect matching....Take a maximum matching, an unmatched vertex, and explore usingalternating paths, building a set S with |S | > N(S)

〉〉

17/62 CR02

Page 18: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Finding the BTF (general sparse matrix case)

A two (or three) step algorithm

1 Find a maximum cardinality matching in the bipartite graph of thematrix,

2 Decompose into strong Hall blocks

HC SC VC

HR AH ∗ ∗SR O AS ∗VR O O AV

. (1)

The block AH , formed by the rows in the set HR and the columns inthe set HC , is underdetermined;The block AS , formed by the rows in the set SR and the columns inthe set SC , is square and can itself have a btf with the blocks on thediagonal being all square (fine decomposition);The block AV , formed by the rows in the set VR and the columns inthe set VC , is overdetermined.

18/62 CR02

Page 19: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Finding the BTF (general sparse matrix case)

VR = {rows reachable via alt. path from some unmatched row}VC = {cols reachable via alt. path from some unmatched row}HR = { rows reachable via alt. path from some unmatched col}HC = { cols reachable via alt. path from some unmatched col }SR = R \ VR \ HR

SC = C \ VC \ HC

19/62 CR02

Page 20: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Finding the BTF (general sparse matrix case)!"#$%&'()'*+'#,-.*/+'0-$1-,232-*!"#$%&'()'*+'#,-.*/+'0-$1-,232-*

!

"

#

$

%

&

'

(

!#

)

!*

!!

! "# $ % & ' ( ) !* !!

!

#

"

$

%

'

&

!*

(

)

!#

!!

!

#

$

"

%

'

&

)

(

!!

!*

!"

#"

$"

!%

#%

$%

Figure from J. R. Gilbert.

20/62 CR02

Page 21: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Dulmage-Mendelsohn decomposition: Properties

The rows in HR are completely matched to the columns in HC . Thecolumns in SC are completely matched to the rows in SR and viceversa. The columns in VC are completely matched to the rows in VR .

The block triangular form is unique. In other words, any maximummatching yields the same sets HR , HC , SR , SC , VR , and VC .

The previous two properties also imply that all entries of a maximummatching should reside in the blocks on the diagonal of the btf.

In the block triangular form of a structurally rank deficient, squarematrix, the horizontal and vertical blocks both should be present.The square block may be missing. (Why?)

21/62 CR02

Page 22: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Dulmage-Mendelsohn decomposition: Properties

No edge joins VR and SC ; nor VR and HC ; nor SR and HC .

The subgraph induced by VR and VC has the strong Hall property.The transpose of the subgraph induced by HR and HC has thestrong Hall property.!"#$%&'()'*+'#,-.*/+'0-$1-,232-*!"#$%&'()'*+'#,-.*/+'0-$1-,232-*

!

"

#

$

%

&

'

(

!#

)

!*

!!

! "# $ % & ' ( ) !* !!

!

#

"

$

%

'

&

!*

(

)

!#

!!

!

#

$

"

%

'

&

)

(

!!

!*

!"

#"

$"

!%

#%

$%

22/62 CR02

Page 23: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Dulmage-Mendelsohn decomposition: Finedecomposition

In the fine decomposition, the horizontal and vertical blocks haveblock diagonal structure where the individual blocks on the diagonalare horizontal and vertical, respectively.

Find the connected components of AH and AV ; these will be thediagonal blocks in those submatrices with the same shape as theencompassing blocks.

The fine decomposition of the square block AS is obtained byidentifying fully indecomposable blocks.

Include all rows and columns corresponding to the vertices in analternating tour in a single block.

23/62 CR02

Page 24: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Fine decomposition of the square block

Two columns are equivalent if they lie on an alternating tour.This is an equivalence relation. Let C1,C2, . . . ,CK be the equivalenceclasses, and let Rk be the set of rows matched to Ck .

!"#$%&'#$()*+,-#./#'0#*12"'$0#32+421&5&2'!"#$%&'#$()*+,-#./#'0#*12"'$0#32+421&5&2'

! "# $ % & '

!

"

#

$

%

&

'

! #

&

$%

$

"

!

"

#

$

%

!

"

#

$

%

'

&

'

&

!"#"

#$

#%

!$

!%

&'()*+,-

.*/')(*(0,1)'/2,34-5

6*)07(08,1)'/2,

94-5

Figure from J. R. Gilbert.

24/62 CR02

Page 25: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Fine decomposition of the square block

Let C1,C2, . . . ,CK be the equivalence classes, and let Rk be the set ofrows matched to Ck .

The row subsets Rk and column subsets Ck can be renumbered suchthat if Ci has a nonzero in the row set Rj , then j ≤ i (hence givingthe block upper triangular form).

The subgraph induced by Rk and Ck has strong Hall property.

If non-matching edges are directed from rows to columns and thematching ones are shrunk into single vertices the resulting directedgraph (the directed graph of the permuted matrix) has stronglyconnected components C1,C2, . . . ,CK .

A bipartite graph has the strong Hall propertyiff every pair of edges is on some alternating touriff the graph is connected and every edge is in some perfect matching.

25/62 CR02

Page 26: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Fine decomposition of symmetric matrices

Given a structurally rank deficient symmetric matrix A, let HR , SR , VR ,HC , SC , VC be the sets in the block triangular form of A.

The set of row indices in HR is equal to the set of col indices in VC ;

The set of row indices in SR is equal to the set of col indices in SC ;

The set of row indices in VR is equal to the set of col indices in HC .

26/62 CR02

Page 27: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Fine decomposition of symmetric matrices

Automorphic matching: he same set of rows and cols are matched.8 DUFF AND UCAR

Fig. 2.2. An automorphic maximum matching is shown with highlighted nonzeros.

a hypothetical example. An odd permutation cycle is of odd length, and an evenpermutation cycle is of even length. Note that the edges of an odd permutation cycle(with length greater than one) when put together with their symmetric counterpartsform a unique ordinary cycle in the bipartite graph of A. Note also that any pairof a row and a column in an odd permutation cycle is reachable from each othervia two alternating paths: one starting and ending with a matching edge, the otherstarting and ending with an unmatched edge. For an even permutation cycle of lengthk, adding the symmetric edges partitions the permutation cycle into two ordinarycycles each having k/2 matching edges and k/2 non-matching edges, where the rowvertices in one cycle are symmetric counterparts of the column vertices in the otherone; the two cycles may be connected in the bipartite graph due to existence ofother edges, but we are not interested in this possibility. Consider, for example, thelength 4 permutation cycle

�hri, cji,hrj , cki, hrk, cli, hrl, cii

�shown in Fig. 2.3. The

permutation cycle is split between two ordinary cycles in the bipartite graph of A:�hri, cji,(cj , rk),hrk, cli,(cl, ri)

�and

�hrj , cki,(ck, rl), hrl, cii,(ci, rj)

�. As seen, each of

these cycles contain 2 matching edges and 2 non-matching edges, and the row verticesin one cycle are symmetric counterparts of the column vertices in the other.

From an automorphic matching M, we construct another automorphic matchingM0 which is composed of odd length permutation cycles and length 2 permutationcycles. We proceed as follows. First, all edges of M that form an odd permuta-tion cycle are copied into M0, e.g., for a length 3 permutation cycle of the form�hri, cji, hrj , cki, hrk, cii

�, these three edges are copied into M0. Then, even length

permutation cycles of M are decomposed into length 2 permutation cycles, andthese length 2 permutation cycles are added to M0 such that if hri, cji 2 M0, thenhrj , cii 2M0. As noted above, the even length permutation cycles are split betweentwo ordinary cycles in the bipartite graph when the symmetric edges are considered.By alternating the status of the edges according to the matching in one of the cycles,we can obtain length 2 permutation cycles. The decomposition of an even permuta-tion cycle into length 2 permutation cycles is best seen in matrix terms. Consider thematching shown on the left below

14 DUFF AND UCAR

Fig. 3.3. The matrix permuted blockwise so that the resulting matrix is symmetric along theanti-diagonal.

is the transpose of Ai (see (3.1)), as A11 = AT11. Since Ai is irreducible, so is its

transpose shown in (3.3). Therefore, the rows whose indices are in the set J2 and thecolumns whose indices are in the set I1 cannot be in a di↵erent block from the onethat contains I.

We have established that either Ri = Ci or Ri \ Ci = ;. If Ri \ Ci = ;, allmatching nonzeros in this block should be in length 2 permutation cycles, as the oddpermutation cycles are irreducible. Therefore, we have another irreducible block jwith Rj = Ci and Cj = Ri and the proof is completed.

Having defined the fine structure of the square block AS , we refine Corollary 3.6by using that structure. As before, let Ri and Ci denote the set of row and columnindices of the ith irreducible block of AS . We will order the rows of A and then applythat order in the reverse direction to the columns. We first order the rows in thehorizontal block. Then, we order the rows in square block AS using the fine structureas follows. Let i be an irreducible block whose rows are yet to be ordered. If the setof column indices Ci is equal to the set of row indices Ri, order Ri. If Ci \ Ri = ;,order Ri and then the rows that are symmetric counterparts of the columns whoseindices are in the set Ci. After this blockwise ordering of all the rows in the squareblock AS , we order the rows in the vertical block. We do not specify the order ofthe rows in a subblock—it can be arbitrary. Now applying the order obtained forthe rows to the columns in the reverse direction results in a matrix that is symmetricalong the anti-diagonal. Figure 3.3 shows the matrix of the previous figures permutedto be symmetric around the anti-diagonal. We emphasize that the matching itselfis not symmetric around the anti-diagonal because of the odd permutation cycle onindices 5, 13, and 18. The matching entries can be placed to be symmetric aroundthe anti-diagonal, but then the symmetry in other parts of the matrix can be lost.

Notice that one can also permute the matrix so that the resulting matrix issymmetric along the main diagonal; this time by ordering the rows as describedabove and then by applying the same permutation to the columns. The resultingpermuted matrix is shown in left side of Fig. 3.4. One can further permute thematrix such that the square block of the Dulmage-Mendelsohn decomposition comes

Permute to have symmetry around the anti-diagonal

27/62 CR02

Page 28: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Fine decomposition of symmetric matrices

BLOCK TRIANGULAR FORM OF SYMMETRIC MATRICES 15

Fig. 3.4. The matrix permuted blockwise so that the resulting matrix is symmetric along themain diagonal. When the square block of the coarse decomposition is permuted before the otherblocks, a block tridiagonal form is obtain using the three blocks of the coarse Dulmage-Mendelsohndecomposition, with the last block on the diagonal being void of nonzeros

before the rectangular ones as shown in the right side of the same figure. With thisordering the coarse Dulmage-Mendelsohn decomposition can be seen as inducing ablock tridiagonal form with the last block on the diagonal being empty.

We note that Theorem 3.5, Corollary 3.6, and Theorem 3.7 hold for structurallyfull rank, symmetric matrices. In particular, the fine decomposition of such a matrixhas square irreducible blocks with a row index set Ri and a column index set Ci whereeither Ri = Ci or there exists another irreducible block j (with row index set Rj andcolumn index set Cj) with Rj = Ci and Cj = Ri.

4. Concluding remarks. We have presented observations on the block trian-gular form of structurally symmetric matrices. The two main results are that (i) if thematrix is structurally rank deficient, the horizontal and vertical blocks are transposesof each other, (ii) each block in the square submatrix has the same set of row andcolumn indices or those two sets are totally disjoint and there is another square blockbeing the transpose of the first one. These symmetrical structures help us recoverthe symmetry of the original matrix in the Dulmage-Mendelsohn decomposition (orin the block triangular form).

We note, for historical reasons, that Dulmage and Mendelsohn note (at the lastparagraph in their seminal paper [7]) that they think it may be worthwhile to studythe decomposition for symmetric bipartite graphs. We think that the observations inthis paper could address some of their concerns.

Acknowledgements. We thank two anonymous referees and Cleve Ashcraft,also a referee, for their constructive comments and suggestions. Cleve also providedus with some Matlab code for the figures. We also thank Alex Pothen for his remarkson an earlier version of the paper and bringing the Mendelsohn-Dulmage theorem,restated in Section 2.1, to our attention.

Permute to have symmetry around the main diagonal

28/62 CR02

Page 29: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The BTF, computation and propertiesBipartite matching

Konig’s theorem

In a bipartite graph, maximum cardinality of a matching is equal to thesize of the minimum vertex cover.

Recall: A vertex cover is a set S of vertices where for every edge at leastone of the end points is in S.

Proof: For each edge of a max card matching, we have one of thevertices in the cover. Hence |M| ≤ |S|. If we build a cover of size |M|,we are done.

Use DM decomposition.

29/62 CR02

Page 30: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Outline

1 The block triangular formThe BTF, computation and propertiesBipartite matching

2 Algorithms for max cardinality bipartite matching

30/62 CR02

Page 31: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Augmenting paths

An augmenting path with respect to a matching M is an alternatingpath that starts and ends at an unmatched vertex.

Theorem [Berge,’57] A matching M is of maximum cardinality iff there isno augmenting path with respect to M.

Proof: Assume M is maximum and P an M-augmenting path. ThenM′ =M\ E (P) ∪ E (P) \M is also a matching with |M′| = |M|+ 1⇒ contradiction.

31/62 CR02

Page 32: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Augmenting paths

An augmenting path with respect to a matching M is an alternatingpath that starts and ends at an unmatched vertex.

Theorem [Berge,’57] A matching M is of size maximum cardinality iffthere is no augmenting path with respect to M.

Proof (cont’): Assume no M-augmenting path exists, but there is amatching M′ such that |M′| > |M|. Consider D =M\M′ ∪M′ \M.Since both M′ and M are matchings, each vertex has at most two edgesof D incident on it. Consider components of D:Case 0: nothing to do.

Case 2 (cycles): equal number of M and M′ edges (skip).

Case 1 (paths): Since |M′| > |M|, there should be at least one pathwho has one more edge in |M′| than in M : an augmenting path wrtM⇒ contradiction. 2

32/62 CR02

Page 33: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Augmenting paths

Theorem [Berge,’57] A matching M is of size maximum cardinality iffthere is no augmenting path with respect to M.

a1

a2

a3

a4

1b

2b

3b

4b

a1

a2

a3

a4

1b

2b

3b

4b

a1

a2

a3

a4

1b

2b

3b

4b(M) (augmenting path) (new matching)

33/62 CR02

Page 34: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Bipartite matching algorithms

The essence of bipartite cardinality matching algorithms is to start withan empty matching and then to augment it until no furtheraugmentations are possible.

The existing algorithms mostly differ in the way the augmenting pathsare found and the way the augmentations are performed.

34/62 CR02

Page 35: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Bipartite matching algorithms: Start with a largematching

We will see

two common heuristics

GreedyKarp-Sipser

A randomized one

And we are going to extract an approximation algorithm from anexact one.

35/62 CR02

Page 36: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Bipartite matching algorithms: Simple Greedy

Design, Implementation, and Analysis of Maximum Transversal Algorithms 13:15

ALGORITHM 1: Simple Greedy Matching (SGM)Data: A bipartite graph G = (VR ∪ VC, E)Result: A matching MM ← ∅;for each unmatched u ∈ VC do

if u is adjacent to an unmatched vertex v ∈ VR thenM ← M ∪ {(u, v)};G ← G \ {u, v}!remove vertices u, v, and all edges incident on them

endendreturn M;

to augment it by searching paths only between a subset of the unmatched vertices, andthen use the algorithm of Bast et al. [2006] if these searches have not found a maximummatching. It has been shown that the overall algorithm runs in linear expected timefor sparse random graphs.

Another technique is to transform the input graph such that the algorithms wouldrun fast on it. This is exemplified in Feder and Motwani [1995], where the runtimecomplexity of HK becomes O(τ ∗√n)-time where τ ∗ = τ log (n2/τ )/ log n. Notice that theruntime is O(τ

√n) for practical purposes (when the graphs are sparse), and hence there

is no improvement over the standard HK.A remarkable property of algorithm HK is that it leads to an approximation algorithm

for the maximum matching problem. One can use the lemmas and proofs by Hopcroftand Karp [1973] to obtain an O(pτ )-time algorithm that finds a matching with cardi-nality at least p/(p + 1)δmax, where δmax is the cardinality of a maximum matching. Letδ be the size of the matching after the pth phase of HK. Since the shortest path lengthincreases by at least 2 in each phase, the shortest augmenting path length after thepth phase is at least 2p + 1. Then, each augmenting path should contain at least pmatching edges. Thus, there are at most δ/p vertex disjoint augmenting paths. Sinceeach augmenting path increases the cardinality of the current matching by one, δmaxcan be at most δ+δ/p. That is, (p + 1)/pδ ≥ δmax. One can rearrange the inequalities asδ ≥ (1 − (1/(p + 1)))δmax to see the approximation at the end of pth phase. This remarkis also made by Gabow and Tarjan [1988, p. 415].

4. SOME HEURISTICS FOR THE MAXIMUM MATCHING PROBLEMSeveral fast heuristics to jump-start maximum cardinality matching algorithms havebeen described in the literature [Karp and Sipser 1981; Langguth et al. 2010; Magun1998; Pothen and Fan 1990; Setubal 1996]. Here we discuss three of these heuristics.The first one, although it is the worst one, is probably the most frequently used heuristicin practice. The second one is probably the most theoretically studied heuristic for themaximum cardinality matching problem. Surprisingly, according to our experiments,the last one is the best. These heuristics are experimentally investigated by Magun[1998] and Langguth et al. [2010]. We also briefly investigate these heuristics to seetheir effects on the runtime of the algorithms. Modified and extended versions of theseheuristics and experimental analysis can be found in Magun [1998] and Langguth et al.[2010].

4.1. Simple Greedy Matching (SGM)The first heuristic, Algorithm 1, is used by Pothen and Fan [1990] and Duff and Wiberg[1988]. In this simple heuristic, each unmatched column is examined in turn andmatched with the first unmatched row in its adjacency list, if there is any.

ACM Transactions on Mathematical Software, Vol. 38, No. 2, Article 13, Publication date: December 2011.

Obtains a maximal matching.

Approximation guarantee?

Self study: What about maximal matchings in hypergraphs with a similaralgorithm? Assume d-uniform (each hyperedge has d vertices) andd-partite: there are d different sets of vertices, and each hyperedge hasone vertex from each set.

36/62 CR02

Page 37: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Bipartite matching algorithms: Simple Greedy

Design, Implementation, and Analysis of Maximum Transversal Algorithms 13:15

ALGORITHM 1: Simple Greedy Matching (SGM)Data: A bipartite graph G = (VR ∪ VC, E)Result: A matching MM ← ∅;for each unmatched u ∈ VC do

if u is adjacent to an unmatched vertex v ∈ VR thenM ← M ∪ {(u, v)};G ← G \ {u, v}!remove vertices u, v, and all edges incident on them

endendreturn M;

to augment it by searching paths only between a subset of the unmatched vertices, andthen use the algorithm of Bast et al. [2006] if these searches have not found a maximummatching. It has been shown that the overall algorithm runs in linear expected timefor sparse random graphs.

Another technique is to transform the input graph such that the algorithms wouldrun fast on it. This is exemplified in Feder and Motwani [1995], where the runtimecomplexity of HK becomes O(τ ∗√n)-time where τ ∗ = τ log (n2/τ )/ log n. Notice that theruntime is O(τ

√n) for practical purposes (when the graphs are sparse), and hence there

is no improvement over the standard HK.A remarkable property of algorithm HK is that it leads to an approximation algorithm

for the maximum matching problem. One can use the lemmas and proofs by Hopcroftand Karp [1973] to obtain an O(pτ )-time algorithm that finds a matching with cardi-nality at least p/(p + 1)δmax, where δmax is the cardinality of a maximum matching. Letδ be the size of the matching after the pth phase of HK. Since the shortest path lengthincreases by at least 2 in each phase, the shortest augmenting path length after thepth phase is at least 2p + 1. Then, each augmenting path should contain at least pmatching edges. Thus, there are at most δ/p vertex disjoint augmenting paths. Sinceeach augmenting path increases the cardinality of the current matching by one, δmaxcan be at most δ+δ/p. That is, (p + 1)/pδ ≥ δmax. One can rearrange the inequalities asδ ≥ (1 − (1/(p + 1)))δmax to see the approximation at the end of pth phase. This remarkis also made by Gabow and Tarjan [1988, p. 415].

4. SOME HEURISTICS FOR THE MAXIMUM MATCHING PROBLEMSeveral fast heuristics to jump-start maximum cardinality matching algorithms havebeen described in the literature [Karp and Sipser 1981; Langguth et al. 2010; Magun1998; Pothen and Fan 1990; Setubal 1996]. Here we discuss three of these heuristics.The first one, although it is the worst one, is probably the most frequently used heuristicin practice. The second one is probably the most theoretically studied heuristic for themaximum cardinality matching problem. Surprisingly, according to our experiments,the last one is the best. These heuristics are experimentally investigated by Magun[1998] and Langguth et al. [2010]. We also briefly investigate these heuristics to seetheir effects on the runtime of the algorithms. Modified and extended versions of theseheuristics and experimental analysis can be found in Magun [1998] and Langguth et al.[2010].

4.1. Simple Greedy Matching (SGM)The first heuristic, Algorithm 1, is used by Pothen and Fan [1990] and Duff and Wiberg[1988]. In this simple heuristic, each unmatched column is examined in turn andmatched with the first unmatched row in its adjacency list, if there is any.

ACM Transactions on Mathematical Software, Vol. 38, No. 2, Article 13, Publication date: December 2011.

variant: Ranking.. choose a neighbor with the smallest rank.Approximation guarantee?

37/62 CR02

Page 38: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Bipartite matching algorithms: Karp-Sipser heuristic

Degree-0 reduction

Degree-1 reduction: u has only one neighbor v . There is a max cardmatching in which u is matched to v

Degree-2 reduction: u has two neighbors v ,w . Merge v ,w , discardu.

If not, pick a random edge and match.

what happens with:

R1

R2

C1 C2

h

h

38/62 CR02

Page 39: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Algorithm I

1: for j = 1 to n do2: cmatch(j)← NIL3: for i = 1 to n do4: Randomly pick a column j in row i (uniformly random)5: cmatch(j)← i

Some columns are picked by many rows but only one of them getsto be matched.

Some columns are not matched at all, cmatch(·) value remains NIL.

39/62 CR02

Page 40: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Example

� �����

For each selected red vertex, we can have a mate.

Count the number of red vertices that are notselected to obtain a bound on the size of thematching.

40/62 CR02

Page 41: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Algorithm I – The expected size of a matching

Assumption: all rows and columns have d nonzeros (a row picks one of itscolumns with 1/d). Then the probability that the column j is not picked

(1− 1/d)d .

Bounded by the limit (increasing function),

limd→∞

(1− 1

d

)d

=1

e.

The expected number of unmatched columns is less than:

n

e.

Therefore, the above algorithm obtains a matching of size (inexpectation)

n

(1− 1

e

)≈ n 0.6321 .

41/62 CR02

Page 42: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Algorithm II – OneSided

The assumption that each row and column has d nonzeros is veryrestrictive.

Remedy: Any nonnegative matrix A with a total support can bescaled to a doubly stochastic matrix with two positive diagonalmatrices, yielding S = D1AD2.

We first do a scaling and then perform matching as before.

1: S ← doubly stochastic scaling of A2: for j = 1 to n do3: cmatch(j)← NIL4: for i = 1 to n do5: Randomly pick column j , according to probabilities sij6: cmatch(j)← i

42/62 CR02

Page 43: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Algorithm II – The expected size of a matching

Again, the above algorithm obtains a matching of size (proof uses thearithmetic-geometric mean inequality as an additional machinery)

n

(1− 1

e

)≈ n 0.6321

in expectation as n→∞ for an n × n matrix with total support.

43/62 CR02

Page 44: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

Components of a DFS-based maximum matching algorithm

Suppose that matching of size k has been found (i.e., there existpermutations to place entries on the first k diagonal positions).

augmenting paths: try to find a matching of size k + 1 using amatching of size k ,

use depth first search to locate augmenting paths starting from thecolumns.

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000

1

0

00

2

0

0

00

0

3

X00

0

4

0

00

0

50

X0

0X

06

0XX

XX

XX

X

XX

Page 45: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

X0000X

1

0

00

2

0

XX

X

0

00

0

3

X X00

0

4

0

00

0

50

X

X0

0

X

X

06

0X

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

45/62 CR02

Page 46: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X0

00

2

0

XX

XX

X

46/62 CR02

Page 47: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X0

00

2

0

XX

XX

X

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

2

0

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X

XX

XX

X

6

5

4

3

47/62 CR02

Page 48: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X0

00

2

0

XX

XX

X

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

2

0

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X

XX

XX

X

6

5

4

3

3

48/62 CR02

Page 49: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X0

00

2

0

XX

XX

X

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

2

0

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X

XX

XX

X

6

5

4

3 1

2

49/62 CR02

Page 50: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X0

00

2

0

XX

XX

X

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000

1

0

00

2

0

0

00

0

3

X00

0

4

0

00

0

50

X0

0X

06

0XX

XX

XX

X

XX

50/62 CR02

Page 51: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Illustration of the algorithm

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

0000X

1X

0

00

0

3

X00

0

4

0

00

0

50

X0

0

X

X

06

0X0

00

2

0

XX

XX

X

r1 c1

r2 c2

r3 c3

r4 c4

r5 c5

r6 c6

000

0

00

0

3

X00

0

4

0

00

0

50

X0 0

XX

X

X2

X

0

60XX0X0

1X00

0X

51/62 CR02

Page 52: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Algorithms for bipartite matching (cont’)

Alg. Description ComplexityDFSB Based on DFS. Forms the basis of many algo-

rithms.O(nτ)

BFSB Based on BFS. Quite common (the algorithm FFin [Melhorn and Naher,’99]).

O(nτ)

MC21A DFS+Lookahead [Duff,’81] and dmperm in Matlab[Davis,’06]—the most wide-spread?

O(nτ)

PF Phases of disjoint DFSs [Pothen and Fan,’90]. O(nτ)HK Shortest disjoint augmenting paths [Hopcroft and

Karp,’73].O(√nτ)

HKDW HK+Disjoint DFS [Duff and Wiberg,’88]. O(√nτ)

ABMP Combined DFS and BFS [Alt, Blum, Mehlhorn, and

Paul,’91].minO(

√nτ)

O(n1.5√τ/ log n)

PF+ A simple modification of PF [Duff, Kaya, and U.,’10]. O(nτ)

PR-FIFO Push-relabel [Cherkassky, Goldberg, Martin, Setubal,

Stolfi,’98]; Bounds on distances to free vertices.O(√nτ)

52/62 CR02

Page 53: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The basic algorithm (Pothen and Fan)

Computing the Block Triangular Form of a Sparse Matrix * 309

does not have a perfect matching, then MC13D puts the maximum number of

nonzeros on the diagonal, treats the remaining zeros on the diagonal as nonzeros,

and then computes a block upper triangular form corresponding to this diagonal.

However, in this case, the matrix has a finer btf that can be obtained from the

coarse and fine decompositions described here.

3. ALGORITHMS

We describe our algorithm to compute a Dulmage-Mendelsohn decomposition of

an m x n matrix A, where, without loss of generality, we have assumed m 2 n.

We represent the nonzero structure of the matrix A by both column-oriented

and row-oriented adjacency lists and pointer arrays used by SPARSPAK [15].

Thus the array adjcol(.) and the pointer array ~a@(.) are used to represent the

column indices of nonzeros in rows of A. Similarly, arrays adjrow (.) and xudjr(.)

are used to represent row indices of nonzeros in columns of A.

The algorithm to compute the btf has three phases:

Phase 1 Find a maximum matching M in the bipartite graph G(A).

Phase 2 With respect to M, partition R into the sets VR, SR, HR; similarly

partition C into the sets VC, SC, HC.

Phase 3 Find the diagonal blocks of the submatrix A, = (VR, VC), from the

connected components of G,; similarly for A, = (HR, HC).

Find the block upper triangular form of the submatrix A, = (SR, SC)

by finding strong components in the associated directed graph Gd.

3.1 The Maximum Matching

Duff [5] has described the implementation of an O(m) maximum matching

algorithm. More recently, Duff and Wiberg [9] have implemented an O(&,)

algorithm due to Hopcroft and Karp. Either of these algorithms could be used to

find the maximum matching in this phase. The latter algorithm has an asymp-

totically superior worst-case complexity. However, empirically, the running times

of the algorithms are greatly improved by the use of heuristic features, and the

relative performance of the two algorithms is problem dependent. Duffs imple-

mentation of the former algorithm is conceptually simpler and uses less storage.

A detailed description of Duff s implementation of an 0 (m) matching algorithm

may be found in the book by Duff et al. [6].

We implemented an algorithm similar to the one in [5], but found it to be slow

on the denser problems we considered. This motivated the design of the variant

of the O(m) maximum matching algorithm described below. We found that our

implementation of this algorithm was competitive with Duff s 0 (m-) algorithm

on sparser problems, while it was faster than the latter on denser problems. A

description of our O(m) matching algorithm follows.

Algorithm 1. Maximum Matching Step 0. [Initialize]

Set the matching M and the set of unmatched columns U to be empty. Step 1. [cheap matching]

for each column vertex c E C do match c to the first unmatched row vertex r E c&(c), if there is such a row; if c cannot be matched, add c to U;

end for

ACM Transactions on Mathematical Software, Vol. 16, No. 4, December 1990.

310 * A. Pothen and C.-J. Fan

Fig. 3. The fine decomposition of G, and the block upper triangular form of A,.

RI 1 Cl

----

2

5

-------

6

R3

7

Rows Columns

1234567

Step 2. [augment matching] u,., := 0 repeat

(perform one pass of the augmenting procedure) for each column vertex c E U do

search for an augmenting path from c, visiting only row vertices that have not been visited previously in this pass; mark all row vertices reached as visited, if an augmenting path is found, augment M; else include c in U,,,;

end for u:= u,,,; u,., := PI;

until no augmenting path is found in a pass.

Inasmuch as an augmenting path has an unmatched column vertex at one end

and an unmatched row vertex at the other, it is no loss of generality to search

for augmenting paths from unmatched columns only. Since we are searching by

alternating paths, the depth-first searches (dfs) have a simple structure. From

each column vertex, we search all rows adjacent to it, but from a row vertex, we search only the column matched to it.

Duff et al. [6] call Step 1 finding a cheap matching. If A is a square, unsymmetric

matrix of order n with a perfect matching, then, using the Hall property, it is

ACM Transactions on Mathematical Software, Vol. 16, No. 4, December 1990.

53/62 CR02

Page 54: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The basic algorithm: Analysis

Each pass costs O(τ)-time, where τ = nnz(A). There are a total of n passes(at most), hence the runtime is O(nτ).

Theorem: The cheap matching phase finds a matching of cardinality at least1/2 of the maximum cardinality.We saw one proof, another is based on the following theorem.

Konig-Frobenius theorem:

Let A be an m × n matrix, where m ≥ n, and let k ≤ n be a nonnegativeinteger. A necessary and sufficient condition that the size of a maximummatching of A is n − k is that it contains an s × t zero submatrix withs + t = m + k.

Suppose cheap matching obtained a cardinality of `; reorder rows and columnsof A such that

A =

(A11 A12

A21 O

),

then by the above theorem (m − `) + (n − `) ≤ m + k, and hence

` ≥ (n − k)/2.

54/62 CR02

Page 55: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

A faster algorithm (theoretically the fastest)

By Hopcroft and Karp,’73.

228 JOHN E. HOPCROFT AND RICHARD M. KARP

COROLLARY 3. P, P, + 11.COROLLARY 4. For all and j such that IP, IPjI, P, and P are vertex-disjoint.

Proof. Suppose, for contradiction, that IP, IPI, < j, and Pi and Pi are

not vertex-disjoint. Then there exist k and such that k < < j, Pk and Pl are

not vertex-disjoint, and for each m, k < m < l, P,, is vertex-disjoint from Pk and PI.Then PI is an augmenting path relative to Mk @ Pk, SO IPll >= IPI 4- IP f-I Pll. But

IPll IPl, so IP Pll O. Thus Pk and Pl have no edges in common. But if Pk andPl had a vertex v in common, they would have in common that edge incident with

v which is in Mk ( Pk. Hence Pk and P/are vertex-disjoint, and a contradiction is

obtained.THEOREM 3. Let s be the cardinality of a maximum matching. The number of

distinct integers in the sequence

IP01, IPll, ..., IPI,

is less than or equal to 2 [xJ + 2.

Proof. Let r /s x//-l. Then IMI r and, by Corollary 2,

IPI-<_ 2Ls /J/(s Us /J)/ <_ 2Lw/J + 1.

Thus, for each < r, IPil is one of the L/J / positive odd integers less than or

equal to 2L/3 / 1. Also I/1, "", IPI contribute at most s- r

distinct integers, and the total number of distinct integers is less than or equal to

Lx/J / + Fx/ __< 2Lv/J + 2, and the proof is complete.In view of Corollaries 3 and 4 and Theorem 3, the computation of the sequence

{M} breaks into at most 2Lx/-] + 2 phases, within each of which all the aug-menting paths found are vertex-disjoint and of the same length. Since these pathsare vertex-disjoint, they are all augmenting paths relative to the matching with

which the phase is begun. This gives us an alternative way of describing the com-

putation of a maximum matching.ALGORITHM A (Maximum matching algorithm).StepO. M.Step 1. Let l(M) be the length of a shortest augmenting path relative to M.

Find a maximal2 set of paths {Q, Q2,"", Q} with the propertiesthat(a) for each i, Qi is an augmenting path relative to M and 1(21 -/(M);(b) the Q are vertex-disjoint.Halt if no such paths exist.

Step 2. M - M @ Q @ Q2 @ @ Qt; go to 1.COROLLARY 5. If the cardinality ofa maximum matching is s, then Algorithm A

constructs a maximum matching within 2Lx/ + 2 executions of Step 1.

This way of describing the construction of a maximum matching suggeststhat we should not regard successive augmentation steps as independentcomputations, but should concentrate instead on the efficient implementation ofan entire phase (i.e., the execution of Step in Algorithm A). The next section

shows the advantage of this approach in the case where G is a bipartite graph.

A set is maximal with a given property if it has the property and is not properly contained in any

set that has the property. 55/62 CR02

Page 56: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

A faster algorithm: HK

Remark: Let M1 be a matching of size r and M2 be a matching of size s,where s > r . Then, there exists at least s − r many vertex disjointM1-augmenting paths.

Remark: Let M be a matching. Suppose |M| = r , and s > r is the maximumcardinality of a matching. Then, there is an M-augmenting path of length≤ 2br/(s − r)c+ 1 (all together r edges from M).

Remark: If P is a shortest M-augmenting path and P ′ is an(M⊕ P)-augmenting path, then |P ′| ≥ |P|+ 2 · |P ∩ P ′|.Remark: Let M0 = ∅ and consider the sequence M0,M1, . . . of matchingswhere Pi is a shortest augmenting path relative to Mi and Mi+1 =Mi ⊕ Pi .Then |Pi | ≤ |P i+1|. If |Pi | = |Pj |, then Pi and Pj are vertex disjoint.

Remark: Let s be the maximum cardinality of a matching. The number of

distinct integers in the sequence |P0|, |P1|, . . . , |P s | is less than or equal to

2b√sc+ 2.

56/62 CR02

Page 57: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The run time of HK

The HK algorithm finishes in 2b√sc+ 2 executions of Step 1.

228 JOHN E. HOPCROFT AND RICHARD M. KARP

COROLLARY 3. P, P, + 11.COROLLARY 4. For all and j such that IP, IPjI, P, and P are vertex-disjoint.

Proof. Suppose, for contradiction, that IP, IPI, < j, and Pi and Pi are

not vertex-disjoint. Then there exist k and such that k < < j, Pk and Pl are

not vertex-disjoint, and for each m, k < m < l, P,, is vertex-disjoint from Pk and PI.Then PI is an augmenting path relative to Mk @ Pk, SO IPll >= IPI 4- IP f-I Pll. But

IPll IPl, so IP Pll O. Thus Pk and Pl have no edges in common. But if Pk andPl had a vertex v in common, they would have in common that edge incident with

v which is in Mk ( Pk. Hence Pk and P/are vertex-disjoint, and a contradiction is

obtained.THEOREM 3. Let s be the cardinality of a maximum matching. The number of

distinct integers in the sequence

IP01, IPll, ..., IPI,

is less than or equal to 2 [xJ + 2.

Proof. Let r /s x//-l. Then IMI r and, by Corollary 2,

IPI-<_ 2Ls /J/(s Us /J)/ <_ 2Lw/J + 1.

Thus, for each < r, IPil is one of the L/J / positive odd integers less than or

equal to 2L/3 / 1. Also I/1, "", IPI contribute at most s- r

distinct integers, and the total number of distinct integers is less than or equal to

Lx/J / + Fx/ __< 2Lv/J + 2, and the proof is complete.In view of Corollaries 3 and 4 and Theorem 3, the computation of the sequence

{M} breaks into at most 2Lx/-] + 2 phases, within each of which all the aug-menting paths found are vertex-disjoint and of the same length. Since these pathsare vertex-disjoint, they are all augmenting paths relative to the matching with

which the phase is begun. This gives us an alternative way of describing the com-

putation of a maximum matching.ALGORITHM A (Maximum matching algorithm).StepO. M.Step 1. Let l(M) be the length of a shortest augmenting path relative to M.

Find a maximal2 set of paths {Q, Q2,"", Q} with the propertiesthat(a) for each i, Qi is an augmenting path relative to M and 1(21 -/(M);(b) the Q are vertex-disjoint.Halt if no such paths exist.

Step 2. M - M @ Q @ Q2 @ @ Qt; go to 1.COROLLARY 5. If the cardinality ofa maximum matching is s, then Algorithm A

constructs a maximum matching within 2Lx/ + 2 executions of Step 1.

This way of describing the construction of a maximum matching suggeststhat we should not regard successive augmentation steps as independentcomputations, but should concentrate instead on the efficient implementation ofan entire phase (i.e., the execution of Step in Algorithm A). The next section

shows the advantage of this approach in the case where G is a bipartite graph.

A set is maximal with a given property if it has the property and is not properly contained in any

set that has the property.

The cost of Step 1 is O(m + n + τ) for a bipartite graph on m + nvertices and τ edges.

57/62 CR02

Page 58: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The run time of HK

The cost of Step 1 is O(m + n + τ) for a bipartite graph on m + nvertices and τ edges.

Build an auxiliary graph:

MAXIMUM MATCHINGS IN BIPARTITE GRAPHS 229

3. The bipartite case. The graph G (V, E) is bipartite if the set of vertices Vcan be partitioned into two sets, X and Y, such that each edge of G joins a vertex inX with a vertex in Y. An element of X will be called a boy, and an element of Y, agirl.

Let M be a matching in a bipartite graph G. We discuss the implementationof Step of Algorithm A, in which a maximal vertex-disjoint set of shortest aug-menting paths relative to M is found. First we assign directions to the edges of Gin such a way that augmenting paths relative to M become directed paths. This isdone by directing each edge in E M so that it runs from a girl to a boy, and eachedge in M so that it runs from a boy to a girl. The resulting directed graph isG (V, E), where

E= {(y,x)l{x,y}E-M,xS,yeY} U {(x,y)l{x,y}eM,xS,yY}.Next we extract a subgraph ( of (, with the property that the directed paths of (running from a free girl to a free boy correspond one-to-one to the shortest aug-menting paths in G relative to M. This is done as follows.

Let Lo be the set of free boys, and let

E {(u, v)l(u, v) e , v e Li, uC! Lo U L, U U Li}, =0,1,2,...,

L+I {b/I for some v, (u, v)e E}, =0,1,2,....

Let i* min {ilL f"l {free girls} }.Then ( (P,/), where

Lo O L, U U Li._ U (gi, {free girls}),

E0 U E U U El,_ 2 U {(u, 1))Iv e Li,_ and u e {free girls}}.

An example of a graph ( is given in Fig. 3.The following properties of ( are immediate.

(i) The vertices at even levels (Lo, L2, are boys, and those at odd levelsare girls.

(ii) If (u, v) e/, then for some i, u e L + and v e Li.(iii) ( is acyclic.

(B)

Lo Eo L E L Ez L E L E L(G) (B) (G) (B) (G)

FIG. 3. The graph used by Algorithm B. Dotted arrows indicate edges in current matching.

Do a DFS-based search from unmatched vertices. Each discovered edgeeither becomes part of an augmenting path or there is no augmentingpath using that edge. No need to revisit that edge.

58/62 CR02

Page 59: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

The run time of HK

The cost of Step 1 is O(m + n + τ) for a bipartite graph on m + nvertices and τ edges.

There are at most O(√n) executions of Step 1, hence the run time is

O(√n τ).

59/62 CR02

Page 60: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Approximation out of HK

Theorem: Suppose we stop HK so that the length of the shortest augmentingpaths is no smaller than k. Then we have a 1− 2

k+1≥ 1− 2/k approximation.

Proof: consider the symmetric difference of a matching M whose shortestaugmenting paths are no shorter than k with that of M?.

Each component has at least (k + 1)/2 vertices from a max card matching.

In each component we have at least (k − 1)/2 edges from M.

In each component, M achieves an approximation of at least (k − 1)/(k + 1).

In all, this makes (k − 1)/(k + 1) approximation, hence the result.

〈〈 apply this result to a maximal matching 〉〉

60/62 CR02

Page 61: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Big question

The best known algorithm (worst case running time): O(√nτ)

The total length of the shortest augmenting paths (used in the HKalgorithm) is O(n log n).

Can we have such an algorithm? what is the tightest lower bound on theworst case running time of any algorithm for the max cardinalitymatching?

61/62 CR02

Page 62: Fanny Dufoss e & Bora U˘carperso.ens-lyon.fr/bora.ucar/CR02/lecture-matching.pdf · Matching and the block triangular form Fanny Dufoss e & Bora U˘car Inria, Grenoble Rhone-Alp^

The block triangular formAlgorithms for max cardinality bipartite matching

Homework questions:

HW4-Q1: Prove that a k regular bipartite graph G = (U,V ,E ) has aperfect matching.

HW4-Q2: A matrix A is called doubly stochastic if aij ≥ 0, and∑j aij = 1 for all i and

∑i aij = 1 for all j .

Show that A is square.

Show that there is a perfect matching in the bipartite graph of A.

Show that A is either fully indecomposable or can be permuted intoa block diagonal matrix, where the diagonal blocks are fullyindecomposable doubly stochastic matrices.

62/62 CR02