static inline int64_t verify(TupleGraph tg, GlobalAddress<G> g, int64_t root) { VerificatorBase<G>::verify(tg,g,root); // SSSP distances verification forall(tg.edges, tg.nedge, [=](TupleGraph::Edge& e){ auto i = e.v0, j = e.v1; /* Eliminate self loops from verification */ if ( i == j) return; /* SSSP specific checks */ auto ti = VerificatorBase<G>::get_parent(g,i), tj = VerificatorBase<G>::get_parent(g,j); auto di = get_dist(g,i), dj = get_dist(g,j); auto wij = get_edge_weight(g,i,j), wji = get_edge_weight(g,j,i); CHECK(!((di < dj) && ((di + wij) < dj))) << "Error, distance of the nearest neighbor is too great :" << "(" << i << "," << di << ")" << "--" << wij << "-->" << "(" << j << "," << dj << ")" ; CHECK(!((dj < di) && ((dj + wji) < di))) << "Error, distance of the nearest neighbor is too great : " << "(" << j << "," << dj << ")" << "--" << wji << "-->" << "(" << i << "," << di << ")" ; CHECK(!((i == tj) && ((di + wij) != dj))) << "Error, distance of the child vertex is not equil to " << "sum of its parent distance and edge weight :" << "(" << i << "," << di << ")" << "--" << wij << "-->" << "(" << j << "," << dj << ")" ; CHECK(!((j == ti) && ((dj + wji) != di))) << "Error, distance of the child vertex is not equil to " << "sum of its parent distance and edge weight :" << "(" << j << "," << dj << ")" << "--" << wji << "-->" << "(" << i << "," << di << ")" ; }); // everything checked out! VLOG(1) << "SSSP verified!\n"; return nedge_traversed; }
void NETWORK::load_network2(std::map<std::pair<std::string , std::string>,float> network, bool _weighted, int edges ) { // message file //std::string msg_file = _output + ".msg"; //FILE *pMsg = NULL; // reset network for(int i=0; i<Order; i++) delete Nodes[i]; Nodes.clear(); Order = 0; Size = 0; // read edges // FILE_HANDLER f( _input_file.c_str(), "r" ); //int edges = f.rows(); //char line[1024] = {""}; std::map<std::string, int> hash_table; int source, target; double weight; //char source_label[128] = {""}; //char target_label[128] = {""}; int source_id = 0; int target_id = 0; int columns; if (network.size() !=0) { std::map<std::pair<std::string , std::string>,float>::iterator it; for (std::map<std::pair<std::string , std::string>,float>::iterator it=network.begin(); it!=network.end(); ++it) { //f.get_text_line( line, sizeof(line) ); //// check if line is valid (two or threee columns) //weight = 1.0; //columns = sscanf( line, "%s %s %lf", source_label, target_label, &weight ); //if( (!_weighted && columns < 2) || (_weighted && columns != 3) ) //{ // pMsg = fopen( msg_file.c_str(), "w" ); // fprintf( pMsg, "Error\nMissing column in line %i.", n+1 ); // fclose( pMsg ); // exit( 0 ); //} std::pair< std::map<std::string, int>::iterator, bool> added; // source node added = hash_table.insert( std::pair<std::string, int>(std::string(it->first.first), (int)Nodes.size()) ); if( added.second ) { source_id = (int)Nodes.size(); add_node( it->first.first.c_str() ); } else source_id = added.first->second; // target node added = hash_table.insert( std::pair<std::string, float>(std::string(it->first.second), (int)Nodes.size()) ); if( added.second ) { target_id = (int)Nodes.size(); add_node( it->first.second.c_str()); } else target_id = added.first->second; // add edge if( is_there_edge(source_id, target_id) ) { weight += get_edge_weight( source_id, target_id ); remove_edge(source_id, target_id); add_edge( source_id, target_id, abs(it->second) ); } else add_edge( source_id, target_id, abs(it->second) ); } } // if size limitazion is on, check network size //if( _size_limit != 0 && Order > _size_limit ) //{ // pMsg = fopen( msg_file.c_str(), "w" ); // fprintf( pMsg, "Error\nNetwork is too large." ); // fclose( pMsg ); // exit(0); //} // normalize weights // uncomment this part for normal hierarchy computation // this commented out for no weight hierarchy computation /*int deg; double max_weight = Nodes[0]->outweight(0); for(int i=0; i<Order; i++) { deg = Nodes[i]->outdegree(); for(int j=0; j<deg; j++) { if( Nodes[i]->outweight(j) > max_weight ) max_weight = Nodes[i]->outweight(j); } } for(int i=0; i<Order; i++) { deg = Nodes[i]->outdegree(); for(int j=0; j<deg; j++) Nodes[i]->setOutWeight( j, Nodes[i]->outweight(j)/max_weight ); }*/ // print network properties //pMsg = fopen( msg_file.c_str(), "w" ); //fprintf( pMsg, "Success\n%i\n%i", Order, Size ); //fclose( pMsg ); }
void NETWORK::load_network( std::string &_input_file, bool _weighted, std::string &_output, int _size_limit ) { // message file std::string msg_file = _output + ".msg"; FILE *pMsg = NULL; // reset network for(int i=0; i<Order; i++) delete Nodes[i]; Nodes.clear(); Order = 0; Size = 0; // read edges FILE_HANDLER f( _input_file.c_str(), "r" ); int edges = f.rows(); char line[1024] = {""}; std::map<std::string, int> hash_table; int source, target; double weight; char source_label[128] = {""}; char target_label[128] = {""}; int source_id = 0; int target_id = 0; int columns; for(int n=0; n<edges; n++) { f.get_text_line( line, sizeof(line) ); // check if line is valid (two or threee columns) weight = 1.0; columns = sscanf( line, "%s %s %lf", source_label, target_label, &weight ); if( (!_weighted && columns < 2) || (_weighted && columns != 3) ) { pMsg = fopen( msg_file.c_str(), "w" ); fprintf( pMsg, "Error\nMissing column in line %i.", n+1 ); fclose( pMsg ); exit( 0 ); } std::pair< std::map<std::string, int>::iterator, bool> added; // source node added = hash_table.insert( std::pair<std::string, int>(std::string(source_label), (int)Nodes.size()) ); if( added.second ) { source_id = (int)Nodes.size(); add_node( source_label ); } else source_id = added.first->second; // target node added = hash_table.insert( std::pair<std::string, int>(std::string(target_label), (int)Nodes.size()) ); if( added.second ) { target_id = (int)Nodes.size(); add_node( target_label ); } else target_id = added.first->second; // add edge if( is_there_edge(source_id, target_id) ) { weight += get_edge_weight( source_id, target_id ); remove_edge(source_id, target_id); add_edge( source_id, target_id, weight ); } else add_edge( source_id, target_id, weight ); } // if size limitazion is on, check network size if( _size_limit != 0 && Order > _size_limit ) { pMsg = fopen( msg_file.c_str(), "w" ); fprintf( pMsg, "Error\nNetwork is too large." ); fclose( pMsg ); exit(0); } // normalize weights /*int deg; double max_weight = Nodes[0]->outweight(0); for(int i=0; i<Order; i++) { deg = Nodes[i]->outdegree(); for(int j=0; j<deg; j++) { if( Nodes[i]->outweight(j) > max_weight ) max_weight = Nodes[i]->outweight(j); } } for(int i=0; i<Order; i++) { deg = Nodes[i]->outdegree(); for(int j=0; j<deg; j++) Nodes[i]->setOutWeight( j, Nodes[i]->outweight(j)/max_weight ); }*/ // print network properties //pMsg = fopen( msg_file.c_str(), "w" ); //fprintf( pMsg, "Success\n%i\n%i", Order, Size ); //fclose( pMsg ); }