The maximum weighted matching problem is to find undirected edges in the graph with maximum overall weight and no two of them shares their endpoints. The problem can be formulated with the next linear program:
where is the set of edges incident to a node in , is the set of edges with both endpoints in and is the set of odd cardinality subsets of the nodes.
The algorithm calculates an optimal matching and a proof of the optimality. The solution of the dual problem can be used to check the result of the algorithm. The dual linear problem is the next:
The algorithm can be executed with run()
or the init()
and then the start()
member functions. After it the matching can be asked with matching()
or mate() functions. The dual solution can be get with nodeValue()
, blossomNum()
and blossomValue()
members and BlossomIt nested class which is able to iterate on the nodes of a blossom. If the value type is integral then the dual solution is multiplied by 4.
#include <lemon/max_matching.h>
Classes | |
class | BlossomIt |
Lemon iterator for get the items of the blossom. More... | |
Public Member Functions | |
MaxWeightedMatching (const UGraph &ugraph, const WeightMap &weight) | |
Execution control | |
void | init () |
Initialize the algorithm. | |
void | start () |
Starts the algorithm. | |
void | run () |
Runs MaxWeightedMatching algorithm. | |
Primal solution | |
Functions for get the primal solution, ie. the matching. | |
Value | matchingValue () const |
bool | matching (const UEdge &edge) const |
Edge | matching (const Node &node) const |
Returns the incident matching edge. | |
Node | mate (const Node &node) const |
Returns the mate of the node. | |
Dual solution | |
Functions for get the dual solution. | |
Value | dualValue () const |
Returns the value of the dual solution. | |
Value | nodeValue (const Node &n) const |
Returns the value of the node. | |
int | blossomNum () const |
Returns the number of the blossoms in the basis. | |
int | blossomSize (int k) const |
Value | blossomValue (int k) const |
Returns the value of the blossom. | |
Static Public Attributes | |
static const int | dualScale |
Scaling factor for dual solution. |
MaxWeightedMatching | ( | const UGraph & | ugraph, | |
const WeightMap & | weight | |||
) | [inline] |
Constructor.
void init | ( | ) | [inline] |
Initialize the algorithm
void start | ( | ) | [inline] |
Starts the algorithm
void run | ( | ) | [inline] |
This method runs the MaxWeightedMatching algorithm.
mwm.init(); mwm.start();
Value matchingValue | ( | ) | const [inline] |
Returns the matching value.
bool matching | ( | const UEdge & | edge | ) | const [inline] |
Returns true when the edge is in the matching.
Edge matching | ( | const Node & | node | ) | const [inline] |
Returns the incident matching edge from given node. If the node is not matched then it gives back INVALID
.
Node mate | ( | const Node & | node | ) | const [inline] |
Returns the adjancent node in a mathcing edge. If the node is not matched then it gives back INVALID
.
Value dualValue | ( | ) | const [inline] |
Returns the value of the dual solution. It should be equal to the primal value scaled by dual scale.
Value nodeValue | ( | const Node & | n | ) | const [inline] |
Returns the the value of the node.
int blossomNum | ( | ) | const [inline] |
Returns the number of the blossoms in the basis.
int blossomSize | ( | int | k | ) | const [inline] |
Returns the number of the nodes in the blossom.
Value blossomValue | ( | int | k | ) | const [inline] |
Returns the the value of the blossom.
const int dualScale [static] |
Initial value:
std::numeric_limits<Value>::is_integer ? 4 : 1