template<typename GR>
class lemon::MaxMatching< GR >
This class implements Edmonds' alternating forest matching algorithm for finding a maximum cardinality matching in a general undirected graph. It can be started from an arbitrary initial matching (the default is the empty one).
The dual solution of the problem is a map of the nodes to Status, having values EVEN
(or D
), ODD
(or A
) and MATCHED
(or C
) defining the Gallai-Edmonds decomposition of the graph. The nodes in EVEN/D
induce a subgraph with factor-critical components, the nodes in ODD/A
form the canonical barrier, and the nodes in MATCHED/C
induce a graph having a perfect matching. The number of the factor-critical components minus the number of barrier nodes is a lower bound on the unmatched nodes, and the matching is optimal if and only if this bound is tight. This decomposition can be obtained using status() or statusMap() after running the algorithm.
- Template Parameters
-
GR | The undirected graph type the algorithm runs on. |
|
| MaxMatching (const Graph &graph) |
| Constructor. More...
|
|
|
The simplest way to execute the algorithm is to use the run() member function.
If you need better control on the execution, you have to call one of the functions init(), greedyInit() or matchingInit() first, then you can start the algorithm with startSparse() or startDense().
|
void | init () |
| Set the initial matching to the empty matching. More...
|
|
void | greedyInit () |
| Find an initial matching in a greedy way. More...
|
|
template<typename MatchingMap > |
bool | matchingInit (const MatchingMap &matching) |
| Initialize the matching from a map. More...
|
|
void | startSparse () |
| Start Edmonds' algorithm. More...
|
|
void | startDense () |
| Start Edmonds' algorithm with a heuristic improvement for dense graphs. More...
|
|
void | run () |
| Run Edmonds' algorithm. More...
|
|
|
Functions to get the primal solution, i.e. the maximum matching.
|
int | matchingSize () const |
| Return the size (cardinality) of the matching. More...
|
|
bool | matching (const Edge &edge) const |
| Return true if the given edge is in the matching. More...
|
|
Arc | matching (const Node &n) const |
| Return the matching arc (or edge) incident to the given node. More...
|
|
const MatchingMap & | matchingMap () const |
| Return a const reference to the matching map. More...
|
|
Node | mate (const Node &n) const |
| Return the mate of the given node. More...
|
|
|
Functions to get the dual solution, i.e. the Gallai-Edmonds decomposition.
|
Status | status (const Node &n) const |
| Return the status of the given node in the Edmonds-Gallai decomposition. More...
|
|
const StatusMap & | statusMap () const |
| Return a const reference to the status map, which stores the Edmonds-Gallai decomposition. More...
|
|
bool | barrier (const Node &n) const |
| Return true if the given node is in the barrier. More...
|
|