TEST_F(VertexWeightedGraphTest, testGetNode) { Graph::Node *n; n = wmg->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); }
void ORD::buildGraph() { Graph::GraphCreatorFile creator(this->filename); Graph::GraphUtil util; Graph::GraphProperties properties; int wr; int size; MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &wr); G = creator.create_weighted_mutable_graph(); properties.make_canonical(G); char compname[512]; if (!properties.is_connected(G)) { Graph::GraphReaderWriterFactory factory; Graph::VertexWeightedGraph *H; // Since we are going to proceed with processing largest // component , set a mark as not original and write largest // component into a file. this->set_original(false); vector<list<int> *> members; int comp; comp = util.find_all_components(G, &members); DEBUG("found %d components\n", comp); int i = 0; int gsize = 0; int index = 0; for (int j = 0; j < comp; j++) { i = members[j]->size(); if (i > gsize) { gsize = i; index = j; sprintf(compname, "%s_%d_comp", filename.c_str(), gsize); DEBUG("new larger comp : %d\n", gsize); } } this->set_filename(compname); H = creator.create_component(G, members[index], true); delete G; G = H; // Change the label into 1-base DIMACS format int j = 0; int gs = G->get_num_nodes(); Graph::Node *n; for (int i = 0 ; i < gs; i++) { n = G->get_node(i); n->set_label(i+1); } } }
TEST_F(MutableGraphTest, testGetNode) { Graph::Node *n; n = mg->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); }
void remove_all_edges(int i){ list<int>::iterator it; Graph::Node *n = mg->get_node(i); list<int> nbrs = n->get_nbrs(); for(it = nbrs.begin(); it != nbrs.end(); ++it){ mg->remove_edge(i, *it); } }
TEST_F(VertexWeightedGraphTest, testIsEdge) { Graph::Node *n; n = wmg->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); EXPECT_TRUE(wmg->is_edge(108, 100)); }
TEST_F(MutableGraphTest, testIsEdge) { Graph::Node *n; n = mg->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); EXPECT_TRUE(mg->is_edge(108, 100)); }
bool BasicBlock::dominatedBy(BasicBlock *that) { Graph::Node *bn = &that->dom; Graph::Node *dn = &this->dom; while (dn && dn != bn) dn = dn->parent(); return dn != NULL; }
TEST_F(GraphPropertyTest, testClique) { Graph::Node *n; n = mg->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); EXPECT_FALSE(properties.is_clique(mg, &nbrs)); nbrs.push_back(108); properties.make_clique(mg, &nbrs); EXPECT_TRUE(properties.is_clique(mg, &nbrs)); }
TEST_F(MetisGraphReaderTest, testGetNode) { //dim_writer->write_graph(g); creator.set_file_name("data/1dc.128.met"); creator.set_graph_type("Metis"); g = creator.create_graph(); Graph::Node *n; n = g->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); }
TEST_F(DIMACSGraphWriterTest, testGetNode) { dim_writer->write_graph(g); creator.set_file_name("../data/1dc.128.out"); creator.set_graph_type("DIMACS"); g = creator.create_graph(); Graph::Node *n; n = g->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); }
TEST_F(GraphPropertyTest, testIsPath) { Graph::Node *n = mg->get_node(20); list<int> nbrs = n->get_nbrs(); EXPECT_GT(nbrs.size(), 0); EXPECT_TRUE(properties.is_path(mg, nbrs.front(), nbrs.back())); remove_all_edges(nbrs.front()); EXPECT_FALSE(properties.is_path(mg, nbrs.front(), nbrs.back())); EXPECT_GT(mg->get_num_edges(), 0); }
TEST_F(GraphReaderWriterFactoryTest, testDimacsGraphWriterGetNode) { gw = factory.create_writer("dimacs", "data/dimacsout.out"); gw->write_graph(g); creator.set_file_name("data/dimacsout.out"); creator.set_graph_type("dimacs"); g = creator.create_graph(); Graph::Node *n; n = g->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); }
TEST_F(GraphTest, testIsEdge) { Graph::Node *n; n = g->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); EXPECT_TRUE(g->is_edge(108, 100)); n = g->get_node(80); list<int> nbrs2 = n->get_nbrs(); EXPECT_EQ(22, nbrs2.size()); EXPECT_FALSE(g->is_edge(80, 12)); }
TEST_F(MetisGraphWriterTest, testIsEdge) { dim_writer->write_graph(g); creator.set_file_name("../data/1dc.128.met"); creator.set_graph_type("Metis"); g = creator.create_graph(); Graph::Node *n; n = g->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); EXPECT_TRUE(g->is_edge(108, 100)); }
void LazyConstraintCallback::separateConnectedComponents( Graph const & g , GraphVariables const & vars , Graph::Node const & root , NodeSetVector const & nonZeroNodesComponents , int & nCuts ) { IloExpr rhs( getEnv() ); for ( const NodeSet& S : nonZeroNodesComponents ) { // only consider the non-zero components that don't contain the root auto it = S.find( root ); if ( it == S.end() || it->componentIndex() != root.componentIndex() ) { // determine dS NodeSet dS; for ( Graph::Node i : S ) { for ( Graph::Edge e : g.incEdges( i ) ) { Graph::Node j = g.oppositeNode( i, e ); if ( S.find( j ) == S.end() ) { dS.insert( j ); } } } constructRHS( vars, dS, S, rhs ); for ( Graph::Node i : S ) { assert( isValid( g, i, dS, S ) ); add( vars.xVars[vars.nodeToIndex[i]] <= rhs, IloCplex::UseCutPurge ).end(); ++nCuts; } } } rhs.end(); }
void ORD::outputMetisFormat() { int n = G->get_num_nodes(); cout << n << " " << G->get_num_edges() << endl; for (int i = 0; i < n; i++) { Graph::Node *no = G->get_node(i); list<int> *l = no->get_nbrs_ptr(); list<int>::iterator it = l->begin(); for (; it != l->end(); ++it) { cout << (*it)+1 << " "; } cout << endl; } }
TEST_F(MutableGraphTest, testEliminateVertex) { EXPECT_TRUE(mg->is_edge(108, 100)); EXPECT_EQ(1471, mg->get_num_edges()); EXPECT_EQ(24, mg->get_degree(108)); EXPECT_EQ(24, mg->get_degree(100)); Graph::Node *na; na = mg->get_node(108); list<int> nbrs_a = na->get_nbrs(); vector<int> nbrsvec_a(nbrs_a.begin(), nbrs_a.end()); Graph::Node *nb; nb = mg->get_node(100); list<int> nbrs_b = nb->get_nbrs(); vector<int> nbrsvec_b(nbrs_b.begin(), nbrs_b.end()); int common_nbrs = 0; int final_degree = 0; int new_edges = 0; for (int ia = 0; ia < nbrsvec_a.size(); ia++) { for (int ib = 0; ib < nbrsvec_b.size(); ib++) { if (nbrsvec_a[ia] == nbrsvec_b[ib]) { common_nbrs++; } } } new_edges = mg->get_degree(108) - common_nbrs - 1; new_edges = new_edges + mg->get_degree(100) - 1; mg->eliminate_vertex(108, NULL, true); EXPECT_FALSE(mg->is_edge(108, 100)); EXPECT_FALSE(mg->is_edge(100, 108)); EXPECT_EQ(1597, mg->get_num_edges()); EXPECT_EQ(new_edges, mg->get_degree(100)); EXPECT_EQ(0, mg->get_degree(108)); }
/** * @brief Process the difference between 2 readers and return status. */ EImageStatus diffImageStatus(Graph::Node& read1, Graph::Node& read2, Graph::Node& stat, Graph& graph, const bfs::path& filename1, const bfs::path& filename2) { if (bfs::exists(filename1) == 0 || bfs::exists(filename2) == 0) return eImageStatusNoFile; if (bfs::file_size(filename1) == 0 || bfs::file_size(filename2) == 0) return eImageStatusFileSizeError; try { // Setup parameters read1.getParam("filename").setValue(filename1.string()); read2.getParam("filename").setValue(filename2.string()); if( !verbose ) std::cout.rdbuf(0); graph.compute(stat); std::cout.rdbuf(_stdCout); if( verbose ) { std::cout << "diff = "; for (unsigned int i = 0; i < 3; ++i) { std::cout << stat.getParam("quality").getDoubleValueAtIndex(i) << " "; } std::cout << std::endl; } for (unsigned int i = 0; i < 3; ++i) { if (stat.getParam("quality").getDoubleValueAtIndex(i) != 0.0 ) return eImageStatusDiffNotNull; } //std::cout << stat << std::endl; return eImageStatusDiffNull; } catch (...) { std::cerr << boost::current_exception() << std::endl; std::cerr << boost::current_exception_diagnostic_information() << std::endl; return eImageStatusImageError; } }
TEST_F(MutableGraphTest, testContractEdge) { EXPECT_TRUE(mg->is_edge(108, 100)); EXPECT_EQ(1471, mg->get_num_edges()); EXPECT_EQ(24, mg->get_degree(108)); EXPECT_EQ(24, mg->get_degree(100)); Graph::Node *na; na = mg->get_node(108); list<int> nbrs_a = na->get_nbrs(); vector<int> nbrsvec_a(nbrs_a.begin(), nbrs_a.end()); Graph::Node *nb; nb = mg->get_node(100); list<int> nbrs_b = nb->get_nbrs(); vector<int> nbrsvec_b(nbrs_b.begin(), nbrs_b.end()); int common_nbrs = 0; int final_degree = 0; int new_edges = 0; for (int ia = 0; ia < nbrsvec_a.size(); ia++) { for (int ib = 0; ib < nbrsvec_b.size(); ib++) { if (nbrsvec_a[ia] == nbrsvec_b[ib]) { common_nbrs++; } } } final_degree = mg->get_degree(108) + mg->get_degree(100) - common_nbrs - 2; new_edges = mg->get_num_edges() - common_nbrs - 1; int x = mg->contract_edge(108, 100); EXPECT_FALSE(mg->is_edge(108, 100)); EXPECT_FALSE(mg->is_edge(100, 108)); EXPECT_EQ(0, mg->get_degree(100)); EXPECT_EQ(new_edges, mg->get_num_edges()); EXPECT_EQ(final_degree, mg->get_degree(108)); }
TEST_F(DIMACSGraphWriterTest, testshuffle) { string out_file("../data/1dc.128.out.shuf"); dim_writer->set_out_file_name(out_file); dim_writer->shuffle(g, time(NULL)); dim_writer->write_graph(g); creator.set_file_name("../data/1dc.128.out.shuf"); creator.set_graph_type("DIMACS"); g = creator.create_graph(); Graph::Node *n; n = g->get_node(108); list<int> nbrs = n->get_nbrs(); //BDS - problem if randomization happens to put a vertex of //degree 24 in this location. Temporary fix. //EXPECT_NE(24, nbrs.size()); EXPECT_NE(0, nbrs.size()); }
void Graph::classifyDFS(Node *curr, int& seq) { Graph::Edge *edge; Graph::Node *node; curr->visit(++seq); curr->tag = 1; for (edge = curr->out; edge; edge = edge->next[0]) { node = edge->target; if (edge->type == Edge::DUMMY) continue; if (node->getSequence() == 0) { edge->type = Edge::TREE; classifyDFS(node, seq); } else if (node->getSequence() > curr->getSequence()) { edge->type = Edge::FORWARD; } else { edge->type = node->tag ? Edge::BACK : Edge::CROSS; } } for (edge = curr->in; edge; edge = edge->next[1]) { node = edge->origin; if (edge->type == Edge::DUMMY) continue; if (node->getSequence() == 0) { edge->type = Edge::TREE; classifyDFS(node, seq); } else if (node->getSequence() > curr->getSequence()) { edge->type = Edge::FORWARD; } else { edge->type = node->tag ? Edge::BACK : Edge::CROSS; } } curr->tag = 0; }
TEST_F(GraphPropertyTest, testIsIndependentSet) { Graph::Node *n = mg->get_node(20); list<int> nbrs = n->get_nbrs(); EXPECT_FALSE(properties.is_independent_set(mg, &nbrs)); list<int>::iterator it; list<int>::iterator jt; for(it = nbrs.begin(); it != nbrs.end(); ++it){ // Remove all edges between them for(jt = nbrs.begin(); jt != nbrs.end(); ++jt){ if(*it != *jt){ mg->remove_edge(*it, *jt); } } } EXPECT_TRUE(properties.is_independent_set(mg, &nbrs)); EXPECT_GT(mg->get_num_edges(), 0); }
TEST_F(GraphPropertyTest, testSimple) { Graph::Node *n; n = mg->get_node(108); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(24, nbrs.size()); EXPECT_TRUE(mg->is_edge(108, 100)); EXPECT_EQ(24, mg->get_degree(108)); mg->add_edge(108, 100); mg->add_edge(108, 108); EXPECT_EQ(1473, mg->get_num_edges()); EXPECT_EQ(26, mg->get_degree(108)); EXPECT_FALSE(properties.check_simple(mg)); properties.make_simple(mg); EXPECT_TRUE(properties.check_simple(mg)); EXPECT_EQ(24, mg->get_degree(108)); }
TEST_F(GraphUtilTest, testRecomputeDegree) { Graph::Node *n = mg->get_node(36); list<int> nbrs = n->get_nbrs(); EXPECT_EQ(29, nbrs.size()); EXPECT_FALSE(mg->is_edge(36, 3)); mg->add_edge(36, 3); EXPECT_EQ(30, mg->get_degree(36)); mg->remove_edge(36, 3); nbrs.push_back(3); n->set_nbr(nbrs); nbrs = n->get_nbrs(); EXPECT_EQ(30, nbrs.size()); EXPECT_EQ(29, mg->get_degree(36)); util.recompute_degrees(mg); EXPECT_EQ(30, mg->get_degree(36)); }
TEST_F(GraphTest, testFuseVertices) { EXPECT_FALSE(g->is_edge(80, 12)); EXPECT_EQ(1471, g->get_num_edges()); EXPECT_EQ(22, g->get_degree(80)); EXPECT_EQ(19, g->get_degree(12)); Graph::Node *na; na = g->get_node(80); list<int> nbrs_a = na->get_nbrs(); vector<int> nbrsvec_a(nbrs_a.begin(), nbrs_a.end()); Graph::Node *nb; nb = g->get_node(12); list<int> nbrs_b = nb->get_nbrs(); vector<int> nbrsvec_b(nbrs_b.begin(), nbrs_b.end()); int common_nbrs = 0; int final_degree = 0; int new_edges = 0; for(int ia = 0; ia < nbrsvec_a.size(); ia++){ for(int ib = 0; ib < nbrsvec_b.size(); ib++){ if(nbrsvec_a[ia] == nbrsvec_b[ib]){ common_nbrs++; } } } final_degree = g->get_degree(80) + g->get_degree(12) - common_nbrs; new_edges = g->get_num_edges() - common_nbrs; int x = g->fuse_vertices(80, 12, false); EXPECT_FALSE(g->is_edge(80, 12)); EXPECT_FALSE(g->is_edge(12, 80)); EXPECT_EQ(0, g->get_degree(12)); EXPECT_EQ(new_edges, g->get_num_edges()); EXPECT_EQ(final_degree, g->get_degree(80)); }
/** * @brief Process difference between a reader and a generator. */ EImageStatus diffImageStatus(Graph::Node& read1, Graph::Node& read2, Graph::Node& stat, Graph& graph, const bfs::path& filename, const std::vector<std::string>& generatorOptions ) { if ( ! bfs::exists(filename)) return eImageStatusNoFile; if ( bfs::file_size(filename) == 0 ) return eImageStatusFileSizeError; try { // Setup parameters read1.getParam("filename").setValue(filename.string()); for( size_t i=0; i<generatorOptions.size(); i++ ) { std::vector<std::string> opt; boost::split(opt, generatorOptions.at(i), boost::is_any_of("=")); int optvalue = atoi ( opt.at(1).c_str() ); if( optvalue == 0 ) { std::vector<std::string> optList; boost::split(optList, opt.at(1), boost::is_any_of(",")); switch( optList.size() ) { case 1 : { // not a number, set a string parameter read2.getParam(opt.at(0)).setValue( opt.at(1) ); break; } case 2 : { float opt0 = atof ( optList.at(0).c_str() ); float opt1 = atof ( optList.at(1).c_str() ); read2.getParam(opt.at(0)).setValue( opt0, opt1 ); break; } case 3 : { float opt0 = atof ( optList.at(0).c_str() ); float opt1 = atof ( optList.at(1).c_str() ); float opt2 = atof ( optList.at(2).c_str() ); read2.getParam(opt.at(0)).setValue( opt0, opt1, opt2 ); break; }/* case 4 : { double opt0 = atof ( optList.at(0).c_str() ); double opt1 = atof ( optList.at(1).c_str() ); double opt2 = atof ( optList.at(2).c_str() ); //double opt3 = atof ( optList.at(3).c_str() ); read2.getParam(opt.at(0)).setValue( opt0, opt1, opt2 ); }*/ default : { for(size_t i=0; i<opt.size(); i++) TUTTLE_COUT_VAR(opt.at(i)); TUTTLE_COUT("ERROR: unable to process " << optList.size() << " arguments"); break; } } } else { read2.getParam(opt.at(0)).setValue( optvalue ); } } if( !verbose ) std::cout.rdbuf(0); graph.compute(stat); std::cout.rdbuf(_stdCout); if( verbose ) { std::cout << "diff = "; for (unsigned int i = 0; i < 3; ++i) { std::cout << stat.getParam("quality").getDoubleValueAtIndex(i) << " "; } std::cout << std::endl; } for (unsigned int i = 0; i < 3; ++i) { if (stat.getParam("quality").getDoubleValueAtIndex(i) != 0.0 ) return eImageStatusDiffNotNull; } //std::cout << stat << std::endl; return eImageStatusDiffNull; } catch (...) { std::cerr << boost::current_exception() << std::endl; std::cerr << boost::current_exception_diagnostic_information() << std::endl; return eImageStatusImageError; } }
int ORD::find_elim_ordering() { int ws; int wr; char eoname[512]; char eoname_other[512]; // Get size and rank from the communicator MPI_Comm_size(comm, &ws); MPI_Comm_rank(comm, &wr); double xtime = MPI_Wtime(); sprintf(eoname, "%s.order.%d", this->filename.c_str(), ws); sprintf(eoname_other, "%s.order_other.%d", this->filename.c_str(), ws); DEBUG("size: %d, rank %d \n", ws, wr); int n = G->get_num_nodes(); int x = n/ws; int xm = n%ws; int i = 0; DEBUG("n: %d x: %d xm: %d \n", n, x, xm); vector<int> xadj; vector<int> adjncy; vector<int> vtxdist(ws + 1, 0); vector<int> sizes(2*ws,0); vector<int> ordering(x+1, 0); vector<int> recvcnt(ws, 0); vector<int> displ(ws, 0); int numflag = 0; int options[10]; options[0] = 0; vtxdist[0] = 0; for (i = 1; i <= ws; i++) { vtxdist[i] = vtxdist[i - 1] + x; if (i <= xm) vtxdist[i]++; } // prepareing displacement and receive counts to use with MPI_Gatherv for (i = 0; i < ws; i++) { recvcnt[i] = x; if (i < xm) recvcnt[i] ++; if (i > 0) displ[i] += displ[i - 1] + recvcnt[i - 1]; } DEBUG("range: %d, %d\n", vtxdist[wr], vtxdist[wr + 1]); int j = 0; xadj.push_back(0); for (i = vtxdist[wr]; i < vtxdist[wr + 1]; i++) { Graph::Node *no = G->get_node(i); list<int> *l = no->get_nbrs_ptr(); list<int>::iterator it = l->begin(); for (; it != l->end(); ++it) { adjncy.push_back(*it); j++; } xadj.push_back(j); } if (METIS_OK != ParMETIS_V3_NodeND(&vtxdist.front(), &xadj.front(), &adjncy.front(), &numflag, options, &ordering.front(), &sizes.front(), &comm)) { FERROR("error occured while processing parmetis, aborting\n"); MPI_Abort(MPI_COMM_WORLD, -1); } DEBUG("output from ParMETIS\n"); double parmet_time = MPI_Wtime() - xtime; vector<int> recvbuf; n = G->get_num_nodes(); if (wr == 0) { recvbuf = vector<int>(n, 0); } if (MPI_SUCCESS != MPI_Gatherv((void *)&ordering.front(), recvcnt[wr], MPI_INT, (void *)&recvbuf.front(), &recvcnt.front(), &displ.front(), MPI_INT, 0, comm)) { FERROR("MPI error occured at Gatherv, Abort!\n"); MPI_Abort(comm, -1); } vector<int> eo(n, 0); if (wr == 0) { for (int i = 0; i < n; i++) { eo[recvbuf[i]] = i; } FILE *f = fopen(eoname_other, "w"); for (int i = 0; i < n; i++) fprintf(f, "%d\n", eo[i] + 1); fclose(f); DEBUG("ParMetis NodeND elimination ordering is in : %s\n", eoname_other); } ordering.clear(); ordering.resize(recvcnt[wr], 0); if (MPI_SUCCESS != MPI_Scatterv ((void *)&eo.front(), &recvcnt.front(), &displ.front(), MPI_INT, (void *)&ordering.front(), recvcnt[wr], MPI_INT, 0, comm)) { FERROR("MPI error occured at Scatterv, Abort! \n"); MPI_Abort(comm, -1); } DEBUG("Scatterv completed\n"); Graph::GraphCreatorFile gf; Graph::VertexWeightedGraph *wg; Graph::GraphEOUtil eoutil; Graph::GraphProperties prop; list<int>members(ordering.begin(), ordering.end()); wg = gf.create_component(G, &members, false); prop.make_canonical(wg); vector<int> ord(recvcnt[wr], 0); vector<int> ordsend(recvcnt[wr, 0]); double xxtime = MPI_Wtime(); eoutil.find_elimination_ordering(wg, &ord, GD_AMD, false); DEBUG("eo time : %f\n", MPI_Wtime() - xxtime); int sz = recvcnt[wr]; for (int i = 0; i < sz; i++) ordsend[i] = wg->get_node(ord[i])->get_label(); recvbuf.assign(n, -1); if (MPI_SUCCESS != MPI_Gatherv((void *)&ordsend.front(), recvcnt[wr], MPI_INT, (void *)&recvbuf.front(), &recvcnt.front(), &displ.front(), MPI_INT, 0, comm)) { FERROR("MPI error occured at Gatherv, Abort!\n"); MPI_Abort(comm, -1); } double p_amd_time = MPI_Wtime() - xtime; if (wr == 0) { FILE *f = fopen(eoname, "w"); for (int i = 0; i < n && wr == 0; i++) fprintf(f, "%d\n", recvbuf[i]); fclose(f); } DEBUG("ordering is written into %s\n", eoname); DEBUG("%f,%f\n", parmet_time, p_amd_time); return 0; }