void createGraphDataStructures(){ //create graph nodes map<string, string>::iterator auth; for(auth = author_id_name.begin(); auth != author_id_name.end(); auth++) { string idd = auth->first; string authorname = auth->second; int idpos = nodes.size(); GraphNode * anewnode = new GraphNode (idpos, idd, authorname); gnode_by_id[idd] = anewnode; nodes.push_back(anewnode); } //now create edges map<string, Article*>::iterator art; for(art = article_id_art.begin(); art != article_id_art.end(); art++) { string articleid = art->first; Article* thearticle = art->second; vector<string> auths = thearticle->authorsList(); //for each author in an article, create an edge connecting that to the rest for (int s= 0; s<auths.size(); s++) { string auth1 = auths.at(s); for (int rest=s+1; rest<auths.size(); rest++) { string auth2 = auths.at(rest); if (auth1 == auth2) { printf("ERROR: author duplicate %s \n", auth1.c_str()); } //create an edge between aut1 and aut2 //but... //need to prevent duplicates string edgekey1 = auth1+auth2; string edgekey2 = auth2+auth1; //whichever encountered before, we don't know if (edges_by_ids.count(edgekey1) > 0 || edges_by_ids.count(edgekey2) > 0 ) { //this edge exists } else{ int posid = edges.size(); GraphEdge * anewedge = new GraphEdge(posid, auth1, auth2); edges.push_back(anewedge); edges_by_ids[edgekey1] = anewedge; edges_by_ids[edgekey2] = anewedge; } } } } //now print all edges //printf("all number of edges created % d \n ", (int)edges.size()); //edges sanity check /* for (int e=0; e<edges.size(); e++) { GraphEdge * edg = edges.at(e); string efrom = edg->from; string eto = edg->to; for (int c=0; c<edges.size(); c++) { GraphEdge * compare = edges.at(c); if (compare->from == efrom && compare->to == eto) { if (e != c) { printf("duplicate at: %d, %d \n", e, c); } } } //printf("edge id: %d, from: %s, to: %s \n", edg->getEdgeid(), edg->from.c_str(), edg->to.c_str()); } */ }