Skip to main content

Module matching

Module matching 

Source
Expand description

Matchings in bipartite graphs, following scipy.sparse.csgraph: maximum-cardinality matching by Hopcroft and Karp (maximum_bipartite_matching), minimum-weight full matching by successive shortest augmenting paths (min_weight_full_bipartite_matching), and the structural rank of a sparsity pattern (structural_rank).

A bipartite graph is given by its biadjacency pattern: n_rows row vertices, n_cols column vertices and edges (row, col) (with weights for the weighted problem).

See the book entry Matchings, k shortest paths and Laplacians.

Structs§

BipartiteMatching
A matching: the column of each row and the row of each column, None where unmatched.

Functions§

maximum_bipartite_matching
A maximum-cardinality matching (SciPy’s maximum_bipartite_matching) by the Hopcroft-Karp algorithm, O(E √V): each phase finds, by a breadth-first search from all free rows, the length of the shortest augmenting paths, then augments along a maximal set of vertex-disjoint paths of that length by depth-first searches. Maximum matchings are not unique; SciPy may return a different one of the same size.
min_weight_full_bipartite_matching
A minimum-weight (or, with maximize, maximum-weight) matching that matches every vertex on the smaller side (SciPy’s min_weight_full_bipartite_matching). Returns (rows, cols) of the matched pairs, sorted by row. Successive shortest augmenting paths: each row in turn is matched by Dijkstra’s algorithm on the reduced costs w(r, c) − u(r) − v(c) ≥ 0, which the dual potentials u, v keep non-negative; O(V E log V). Errors if no full matching exists.
structural_rank
The structural rank of a sparsity pattern (SciPy’s structural_rank): the largest rank any matrix with this pattern can have, the size of a maximum matching between rows and columns.