ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BlossomMatching.h File Reference

The matchings of a general graph by the blossoms of Edmonds, beyond the book, whose matchings of a bipartite graph and branch and bound are in Matching.h [see Matching.h, which includes this header]: More...

#include "ADS/Contract.h"
#include "ADS/graph/Graph.h"
#include "ADS/graph/Matching.h"
#include "ADS/graph/Visit.h"
#include <algorithm>
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "ADS/graph/impl/BlossomMatching.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Functions

template<Graph G>
std::vector< int > ADS::maxCardinalityMatching (const G &g)
 the mate of each node in a matching of largest size of the unoriented graph \( g \), NIL for a node left unmatched and for a name that is not a node
template<class W>
requires std::is_arithmetic_v< W > && std::is_signed_v< W >
std::pair< W, std::vector< std::size_t > > ADS::maxWeightMatching (int n, const std::vector< std::tuple< int, int, W > > &E, bool maxCardinality=false)
 the largest total weight of a matching of the graph of \( n \) nodes and of the edges \( E = ( u , v , w ) \), or, if maxCardinality, the largest weight of a matching of largest size, and the places in \( E \) of its edges, in increasing order

Detailed description

The matchings of a general graph by the blossoms of Edmonds, beyond the book, whose matchings of a bipartite graph and branch and bound are in Matching.h [see Matching.h, which includes this header]:

  • maxCardinalityMatching(), a matching of largest size of a general graph, by the blossoms of Edmonds (beyond the book): a search grows an alternating tree from a free node, shrinks each odd cycle it closes (a blossom) into its base, and stops at the first free node it reaches, along whose path the matching grows by one. The blossoms are kept as the sets of a union-find whose representative knows the base, as in the labels of Gabow, so that a search costs \( O( m \alpha( m , n ) ) \) and the n searches at most \( O( n m \alpha( m , n ) ) \), within the \( O( n^3 ) \) of Gabow's implementation; a search that fails leaves its tree out of every later one, and a greedy matching starts them;
  • maxWeightMatching(), a matching of largest total weight of a general graph, or of largest weight among those of largest size, by the primal-dual algorithm of Edmonds on the blossoms (beyond the book) in the \( O( n^3 ) \) of Gabow and Lawler, as Galil surveys it: the duals of the nodes and of the odd sets keep every edge of nonnegative slack and the matched ones tight, and each stage grows alternating trees on the tight edges from every free node, shrinking the blossoms and changing the duals by the least slack until an augmenting path or the optimum appears; the least slack toward each blossom is kept per blossom, so that a change of the duals costs \( O( n ) \). With integer weights all the arithmetic is on integers, the duals being kept doubled. Among those of largest size it gives, e.g., a perfect matching of least cost with the costs negated.

With ADS_WITH_LEMON [see Interoperation with LEMON], maxCardinalityMatching() and maxWeightMatching() (without maxCardinality) are delegated to the MaxMatching and to the MaxWeightedMatching of LEMON, on a copy of the graph in a lemon::SmartGraph, in \( \Theta( n + m ) \) time and space more, with the same contracts and audits, the matching given being one of the same size or of the same weight, not necessarily the same edges; ADS_MATCHING_LEMON defined to 0 keeps the code of ADS, which is always there.

The contracts [see Contract.h]: an edge joins two distinct nodes of the graph, the graph of maxCardinalityMatching() is unoriented; at the level of the audits the matchings given have no two edges with an end in common, and the duals of maxWeightMatching() certify its optimum. The functions are defined in BlossomMatching.tpp.

See also
C. Berge, Two theorems in graph theory, Proceedings of the National Academy of Sciences 43(9), 842-844, 1957, doi:10.1073/pnas.43.9.842
J. Edmonds, Paths, trees, and flowers, Canadian Journal of Mathematics 17, 449-467, 1965, doi:10.4153/CJM-1965-045-4
H. N. Gabow, An efficient implementation of Edmonds' algorithm for maximum matching on graphs, Journal of the ACM 23(2), 221-234, 1976, doi:10.1145/321941.321942
R. E. Tarjan, J. van Leeuwen, Worst-case analysis of set union algorithms, Journal of the ACM 31(2), 245-281, 1984, doi:10.1145/62.2160
J. Edmonds, Maximum matching and a polyhedron with 0,1-vertices, Journal of Research of the National Bureau of Standards 69B, 125-130, 1965, doi:10.6028/jres.069B.013
H. N. Gabow, Implementation of algorithms for maximum matching on nonbipartite graphs, PhD thesis, Stanford University, 1973
E. L. Lawler, Combinatorial Optimization: Networks and Matroids, Holt, Rinehart and Winston, 1976, chapter 6
Z. Galil, Efficient algorithms for finding maximum matching in graphs, ACM Computing Surveys 18(1), 23-38, 1986, doi:10.1145/6462.6502
H. N. Gabow, Data structures for weighted matching and nearest common ancestors with linking, Proceedings of the 1st ACM-SIAM Symposium on Discrete Algorithms, 434-443, 1990
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa