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; }
intpair operator+(const intpair& a, const intpair& b) { return intpair(a.first + b.first, a.second + b.second); }