int TEgraphMF::readTopology(const char *file_name) { int ret = 0; Bitvector* lid; Bitvector* ilid; ifstream infile; string str; size_t found, first, second; FILE *instream; infile.open(file_name, ifstream::in); /*first the Global graph attributes - c igraph does not do it!!*/ while (infile.good()) { getline(infile, str); found = str.find("<data key=\"FID_LEN\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); sscanf(str.substr(first + 1, second - first - 1).c_str(), "%d", &fid_len); } found = str.find("<data key=\"TM\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); nodeID = str.substr(first + 1, second - first - 1); } found = str.find("<data key=\"RV\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); RVnodeID = str.substr(first + 1, second - first - 1); } found = str.find("<data key=\"TM_MODE\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); mode = str.substr(first + 1, second - first - 1); } } infile.close(); instream = fopen(file_name, "r"); if (instream == NULL) { return -1; } //EF_ALLOW_MALLOC_0=1; ret = igraph_read_graph_graphml(&graph, instream, 0); //EF_ALLOW_MALLOC_0=0; fclose(instream); if (ret < 0) { return ret; } //cout << "TM: " << igraph_vcount(&graph) << " nodes" << endl; //cout << "TM: " << igraph_ecount(&graph) << " edges" << endl; for (int i = 0; i < igraph_vcount(&graph); i++) { string nID = string(igraph_cattribute_VAS(&graph, "NODEID", i)); string iLID = string(igraph_cattribute_VAS(&graph, "iLID", i)); reverse_node_index.insert(pair<string, int>(nID, i)); ilid = new Bitvector(iLID); nodeID_iLID.insert(pair<string, Bitvector* >(nID, ilid)); vertex_iLID.insert(pair<int, Bitvector* >(i, ilid)); cout<<"node "<<i<<" has NODEID"<<nID<<endl; cout<<"node "<<i<<" has ILID"<<ilid->to_string()<<endl; } for (int i = 0; i < igraph_ecount(&graph); i++) { string LID = string(igraph_cattribute_EAS(&graph, "LID", i)); reverse_edge_index.insert(pair<string, int>(LID, i)); lid = new Bitvector(LID); edge_LID.insert(pair<int, Bitvector* >(i, lid)); igraph_integer_t head; igraph_integer_t tail; igraph_edge(&graph, i,&head,&tail); cout << "edge " << i <<" "<<head<<"->"<<tail<<" has LID " << lid->to_string() << endl; } std::vector<int> edgepairs; std::vector<double> capacities; igraph_eit_t ieit; igraph_eit_create(&graph,igraph_ess_all(IGRAPH_EDGEORDER_ID),&ieit); while(!IGRAPH_EIT_END(ieit)) { igraph_integer_t edgeid = IGRAPH_EIT_GET(ieit); igraph_integer_t head; igraph_integer_t tail; // WARNING all edge capacities are give the same value // this needs to come from deployment script capacities.push_back(defaultBW); igraph_edge(&graph, edgeid,&head,&tail); cout<<"edge"<<head<<"->"<<tail<<endl; edgepairs.push_back(head); edgepairs.push_back(tail); IGRAPH_EIT_NEXT(ieit); } igraph_eit_destroy(&ieit); // create an initial dmand matrix assuming equal traffic // between all node pairs - unlikely to be correct but // as booststrap we do not know any better // THIS WILL NEED TO BE DYNAMICALLY UPDATED LATER for (int i = 0; i < igraph_vcount(&graph); i++) { for (int j = 0; j < igraph_vcount(&graph); j++) { if( i == j) continue; mf_demand demand; demand.source = i; demand.sink = j; // WARNING HARDCODED VALUE, ok for initial boostrap // as it is all relative. It should be obtained from // the deployment script as an initial demand. demand.demand = 1.0; demandMapMeasured.insert(pair<intpair,mf_demand>(intpair(i,j), demand)); } } graphMF = Graph_mf((int)igraph_vcount(&graph),edgepairs,capacities); // now demands are set to half the maximum flow when // using shortest paths assuming equal flow between // all pairs - enough for boostrapping // initial demand matrix done! //update_paths(); preCalculateFids(); return ret; }
int TMIgraph::readTopology(char *file_name) { int ret; Bitvector *lid; Bitvector *ilid; ifstream infile; string str; size_t found, first, second; FILE *instream; infile.open(file_name, ifstream::in); /*first the Global graph attributes - c igraph does not do it!!*/ while (infile.good()) { getline(infile, str); found = str.find("<data key=\"FID_LEN\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); sscanf(str.substr(first + 1, second - first - 1).c_str(), "%d", &fid_len); } found = str.find("<data key=\"TM\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); nodeID = str.substr(first + 1, second - first - 1); } found = str.find("<data key=\"TM_MODE\">"); if (found != string::npos) { first = str.find(">"); second = str.find("<", first); mode = str.substr(first + 1, second - first - 1); } } infile.close(); instream = fopen(file_name, "r"); ret = igraph_read_graph_graphml(&graph, instream, 0); fclose(instream); if (ret < 0) { return ret; } cout << "TM: " << igraph_vcount(&graph) << " nodes" << endl; cout << "TM: " << igraph_ecount(&graph) << " edges" << endl; for (int i = 0; i < igraph_vcount(&graph); i++) { string nID = string(igraph_cattribute_VAS(&graph, "NODEID", i)); string iLID = string(igraph_cattribute_VAS(&graph, "iLID", i)); reverse_node_index.insert(pair<string, int>(nID, i)); ilid = new Bitvector(iLID); nodeID_iLID.insert(pair<string, Bitvector *>(nID, ilid)); vertex_iLID.insert(pair<int, Bitvector *>(i, ilid)); //cout << "node " << i << " has NODEID " << nID << endl; //cout << "node " << i << " has ILID " << ilid->to_string() << endl; } for (int i = 0; i < igraph_ecount(&graph); i++) { string LID = string(igraph_cattribute_EAS(&graph, "LID", i)); reverse_edge_index.insert(pair<string, int>(LID, i)); lid = new Bitvector(LID); edge_LID.insert(pair<int, Bitvector *>(i, lid)); //cout << "edge " << i << " has LID " << lid->to_string() << endl; } calculateNodeNumArea() ; return ret; }
int main(void) { // This needs to be done *first*. See igraph doc for why. igraph_i_set_attribute_table(&igraph_cattribute_table); printf("sizeof(int)=%d sizeof(long)=%d sizeof(igraph_integer_t)=%d\n", (int) sizeof(int), (int) sizeof(long), (int) sizeof(igraph_integer_t)); pause(); printf("Loading graph from file...\n"); FILE* f = fopen("donnees/arretes.test", "r"); //FILE* f = fopen("graph_a.ncol", "r"); igraph_t gr; igraph_read_graph_ncol(&gr, f, NULL, 1, 0, 0); fclose(f); f = NULL; long vcount = igraph_vcount(&gr); long ecount = igraph_ecount(&gr); printf("Main graph: |V| = %ld, |E| = %ld\n", vcount, ecount); pause(); // get connected components printf("Computing connected components...\n"); igraph_vector_t membership; igraph_vector_t csize; igraph_integer_t cnum = 0; igraph_vector_init(&membership, 1); igraph_vector_init(&csize, 1); igraph_clusters(&gr, &membership, &csize, &cnum, IGRAPH_STRONG); printf("There are %ld connected components.\n", (long) cnum); // work with connected components { printf("Writing connected components to file...\n"); // open file FILE* filout = fopen("groupes", "w"); long membership_size = igraph_vector_size(&membership); if (membership_size != vcount) { fprintf(stderr, "FATAL ERROR: membership_size != vcount\n"); exit(1); } for (long i = 0; i < membership_size; i++) { fprintf(filout, "%ld\t%s\n", // connected component id: (long) igraph_vector_e(&membership , i), // veretex name: igraph_cattribute_VAS(&gr, "name", i)); } fclose(filout); filout = NULL; printf("Connected components written.\n"); } pause(); // free connected components igraph_vector_destroy(&membership); igraph_vector_destroy(&csize); // free main graph igraph_destroy(&gr); printf("Program ends.\n"); pause(); return 0; }