jacint@536: ///Generates a random graph, and tests max_matching.h on it. jacint@536: #include jacint@536: #include jacint@536: #include jacint@536: jacint@536: #include jacint@536: #include jacint@536: #include jacint@536: #include jacint@536: #include jacint@536: #include jacint@536: alpar@921: using namespace lemon; jacint@536: jacint@536: int main(int, char **) { jacint@536: jacint@536: typedef UndirGraph UGW; jacint@536: typedef UGW::Edge Edge; jacint@536: typedef UGW::EdgeIt EdgeIt; jacint@536: typedef UGW::OutEdgeIt OutEdgeIt; jacint@536: typedef UGW::NodeIt NodeIt; jacint@536: typedef UGW::Node Node; jacint@536: jacint@536: UGW G; jacint@536: jacint@536: // random_init(); //If you want to use a random graph with a random jacint@536: // number of edges and nodes. jacint@536: jacint@536: int i; jacint@536: int j; jacint@536: std::cout<<"Number of nodes: "; jacint@536: std::cin >> i; jacint@536: std::cout<<"Number of edges: "; jacint@536: std::cin >> j; jacint@536: jacint@536: // readDimacs(std::cin, G); jacint@536: randomGraph(G, i, j ); jacint@536: jacint@536: Timer ts; jacint@536: bool noerror=true; jacint@536: jacint@536: std::cout << jacint@536: "\n Testing max_matching.h on a random graph with " << jacint@536: G.nodeNum() << " nodes and " << G.edgeNum() << " edges...\n" jacint@536: << std::endl; jacint@536: MaxMatching max_matching(G); jacint@536: jacint@536: jacint@536: std::cout << jacint@536: "Running the plain edmonds algorithm runEdmonds(0) using no heuristic... " jacint@536: < mate(G,INVALID); jacint@536: max_matching.writeNMapNode(mate); jacint@536: NodeIt v; jacint@536: for(G.first(v); G.valid(v); G.next(v) ) { jacint@536: if ( G.valid(mate[v]) ) { jacint@536: ++s; jacint@536: } jacint@536: } jacint@536: int size=(int)s/2; //size will be used as the size of a maxmatching jacint@536: std::cout << size << " is the size of the matching found by runEdmonds(0),"<::pos_enum> pos0(G); jacint@536: max_matching.writePos(pos0); jacint@536: std::cout << "OK" << std::endl; jacint@536: jacint@536: jacint@536: std::cout << "Resetting the matching and the position by calling"<< std::endl; jacint@536: std::cout<<"resetPos() and resetMatching()..."; jacint@536: max_matching.resetPos(); jacint@536: max_matching.resetMatching(); jacint@536: std::cout <<"OK" << std::endl; jacint@536: jacint@536: jacint@536: std::cout << "\nRunning runEdmonds(1) using the 'postpone shrink' heuristic ... " <::pos_enum> pos1(G); jacint@536: max_matching.writePos(pos1); jacint@536: jacint@536: jacint@536: std::cout << "\nStarting run() from the matching given by runEdmonds(1)... " <::pos_enum> pos2(G); jacint@536: max_matching.writePos(pos2); jacint@536: jacint@536: jacint@536: std::cout << "\nCalling resetPos() and resetMatching()..."; jacint@536: max_matching.resetPos(); jacint@536: max_matching.resetMatching(); jacint@536: std::cout<<"OK"<::pos_enum> pos(G); jacint@536: max_matching.writePos(pos); jacint@536: jacint@536: jacint@536: std::cout<<"\nChecking if the output is a matching..."; jacint@536: bool ismatching=true; jacint@536: for(G.first(v); G.valid(v); G.next(v) ) jacint@536: if ( G.valid(mate[v]) ) { jacint@536: Node u=mate[v]; jacint@536: if (mate[u]!=v) ismatching=false; jacint@536: } jacint@536: if ( ismatching ) std::cout<<"OK"< todo(G,true); jacint@536: int num_comp=0; jacint@536: for(G.first(v); G.valid(v); G.next(v) ) { jacint@536: if ( pos[v]==max_matching.D && todo[v] ) { jacint@536: int comp_size=1; jacint@536: ++num_comp; jacint@536: std::queue Q; jacint@536: Q.push(v); jacint@536: todo.set(v,false); jacint@536: while (!Q.empty()) { jacint@536: Node w=Q.front(); jacint@536: Q.pop(); jacint@536: OutEdgeIt e; jacint@536: for(G.first(e,w); G.valid(e); G.next(e)) { jacint@536: Node u=G.bNode(e); jacint@536: if ( pos[u]==max_matching.D && todo[u] ) { jacint@536: ++comp_size; jacint@536: Q.push(u); jacint@536: todo.set(u,false); jacint@536: } jacint@536: } jacint@536: } jacint@536: if ( !(comp_size % 2) ) oddcomp=false; jacint@536: } jacint@536: } jacint@536: std::cout << "\n found " << num_comp << " component(s) of G[D],"; jacint@536: if ( oddcomp ) std::cout<<" each is odd."<