Example Maximum Cardinality Matching in Bipartite GraphsThe following program shows how the function Remark: The graph algorithms in LEDA are generic, that is, they accept graphs as well as parameterized graphs. In We use
#include <LEDA/graph/graph.h>
#include <LEDA/graph/mcb_matching.h>
using namespace leda;
int main()
{
graph G;
node a0=G.new_node(), a1=G.new_node(), a2=G.new_node();
list<node> A=G.all_nodes();
node b0=G.new_node(), b1=G.new_node();
list<node> B; B.append(b0); B.append(b1);
G.new_edge(a0,b0); G.new_edge(a0,b1);
G.new_edge(a1,b0); G.new_edge(a1,b1);
G.new_edge(a2,b0); G.new_edge(a2,b1);
node_array<bool> NC(G);
list<edge> M=MAX_CARD_BIPARTITE_MATCHING(G,A,B,NC);
bool result_correct=CHECK_MCB(G,M,NC);
if (result_correct) {
std::cout << "Matching: ";
edge e; forall(e,M) G.print_edge(e);
std::cout << std::endl << "Node Cover: ";
std::node v; forall_nodes(v,G) if (NC[v]) G.print_node(v);
std::cout << std::endl;
}
else std::cout << "M is not maximum cardinality matching!"
<< std::endl;
return 0;
}
Remark: There are variants of |
See also:Maximum Cardinality Matching in Bipartite Graphs Manual Entries: Manual Page Maximum Cardinality Matching in Bipartite Graphs |