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) |
|
|
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.
|
|
void | greedyInit () |
| Find an initial matching in a greedy way.
|
|
template<typename MatchingMap > |
bool | matchingInit (const MatchingMap &matching) |
| Initialize the matching from a map.
|
|
void | startSparse () |
| Start Edmonds' algorithm.
|
|
void | startDense () |
| Start Edmonds' algorithm with a heuristic improvement for dense graphs.
|
|
void | run () |
| Run Edmonds' algorithm.
|
|
|
Functions to get the primal solution, i.e. the maximum matching.
|
int | matchingSize () const |
| Return the size (cardinality) of the matching.
|
|
bool | matching (const Edge &edge) const |
| Return true if the given edge is in the matching.
|
|
Arc | matching (const Node &n) const |
| Return the matching arc (or edge) incident to the given node.
|
|
const MatchingMap & | matchingMap () const |
| Return a const reference to the matching map.
|
|
Node | mate (const Node &n) const |
| Return the mate of the given node.
|
|
|
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.
|
|
const StatusMap & | statusMap () const |
| Return a const reference to the status map, which stores the Edmonds-Gallai decomposition.
|
|
bool | barrier (const Node &n) const |
| Return true if the given node is in the barrier.
|
|