void grafoGDF(PUNGraph G) { std::ofstream myfile; std::vector<int> nodos = obtenerVerticesOrdenados(G); TIntV conexiones; myfile.open("facebook.gdf"); myfile << "nodedef>name VARCHAR" << "\n"; myfile << "edgedef>node1 VARCHAR,node2 VARCHAR" << "\n"; for (int i = 0; i < nodos.size(); i++) { GetNodesAtHop(G, nodos[i], 1, conexiones, false); for (int j = 0; j < conexiones.EndI() - conexiones.BegI(); j++) { if (conexiones[j] > i) { myfile << i << "," << conexiones[j] << "\n"; } } conexiones.Clr(); } myfile.close(); }//cierre de grafoGDF
void QuoteGraph::CreateNodes() { TIntV QuoteIds; QB->GetAllQuoteIds(QuoteIds); TIntV::TIter QuoteIdsEnd = QuoteIds.EndI(); for (TIntV::TIter QuoteId = QuoteIds.BegI(); QuoteId < QuoteIdsEnd; QuoteId++) { QGraph->AddNode(*QuoteId); } }
void grafoJSON(PUNGraph G) { std::ofstream myfile; std::vector<int> nodos = obtenerVerticesOrdenados(G); TIntV conexiones; myfile.open("facebook.json"); myfile << "{ \"graph\": {" << "\n"; myfile << "\"nodes\": [" << "\n"; for (int i = 0; i < nodos.size(); i++) { myfile << "{ \"id\": \"" << nodos[i] << "\" }"; if (i == nodos.size()-1) { myfile << " ]," << "\n"; } else { myfile << "," << "\n"; } } myfile << "\"edges\": [\n"; for (int i = 0; i < nodos.size(); i++) { GetNodesAtHop(G, nodos[i], 1, conexiones, false); for (int j = 0; j < conexiones.EndI() - conexiones.BegI(); j++) { if (conexiones[j] > i) { myfile << "{ \"source\": \"" << i << "\", \"target\": \"" << conexiones[j] << "\" }"; if (i == nodos.size()-1) { myfile << " ]" << "\n"; } else { myfile << "," << "\n"; } } } conexiones.Clr(); } myfile << "} }"; myfile.close(); }
// Computes GINI coefficient of egonet as a subset of the parent graph (edges into and out of the egonet ARE considered) double TSnap::GetGiniCoefficient(const TIntFltH DegH, const TIntV NIdV) { typename TIntV::TIter VI; typename TFltV::TIter DI; TFltV DegV; const int n = NIdV.Len(); // DegV.Gen(n); // NOTE: don't use Gen() and Sort() on the same object (!) for (VI = NIdV.BegI(); VI < NIdV.EndI(); VI++) { DegV.Add(DegH.GetDat(VI->Val)); // might need to change this (in / out / undirected) } DegV.Sort(); int i = 0; double numerator = 0.0, denominator = 0.0; for (DI = DegV.BegI(); DI < DegV.EndI(); DI++, i++) { numerator += (i + 1)*DegV[i]; denominator += DegV[i]; } return(double(2*numerator) / double(n*denominator) - double(n + 1) / double(n)); }
void grafoGEXF(PUNGraph G) { std::ofstream myfile; std::vector<int> nodos = obtenerVerticesOrdenados(G); long int aristas = 0; TIntV conexiones; myfile.open("facebook.gexf"); myfile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << "\n"; myfile << "<gexf xmlns=\"http://www.gexf.net/1.2draft\" version=\"1.2\">" << "\n"; myfile << "\t<graph mode=\"static\" defaultedgetype=\"undirected\">" << "\n"; myfile << "\t\t<edges>" << std::endl; for (int i = 0; i < nodos.size(); i++) { GetNodesAtHop(G, nodos[i], 1, conexiones, false); for (int j = 0; j < conexiones.EndI() - conexiones.BegI(); j++) { if (conexiones[j] > i) { myfile << "\t\t\t<edge id=\"" << aristas << "\" source=\"" << i << "\" target=\"" << conexiones[j] << "\"/>" << "\n"; aristas++; } } conexiones.Clr(); } myfile << "\t\t</edges>" << "\n"; myfile << "\t</graph>" << "\n"; myfile << "</gexf>" << "\n"; myfile.close(); }//cierre de grafoGDF
void grafoML(PUNGraph G) { std::ofstream myfile; std::vector<int> nodos = obtenerVerticesOrdenados(G); long int aristas = 1; TIntV conexiones; myfile.open("facebook.graphml"); myfile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << "\n"; myfile << "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"" << "\n"; myfile << "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << "\n"; myfile << "\txsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">" << "\n"; myfile << " <graph id=\"G\" edgedefault=\"undirected\">" << "\n"; for (int i = 0; i < nodos.size(); i++) { GetNodesAtHop(G, nodos[i], 1, conexiones, false); for (int j = 0; j < conexiones.EndI() - conexiones.BegI(); j++) { if (conexiones[j] > i) { myfile << " \t<edge id=\"e" << aristas << "\" source=\"" << i << "\" target=\"" << conexiones[j] << "\"/>" << "\n"; aristas++; } } conexiones.Clr(); } myfile << " </graph>" << "\n"; myfile << "</graphml>" << "\n"; myfile.close(); }//cierre de grafoGDF