SNAP Library 4.0, User Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gio.h
Go to the documentation of this file.
1 // Loading and saving graphs from/to various file formats.
3 namespace TSnap {
4 
5 //const TStr EDGES_START("#EDGES");
6 const TStr EDGES_START = ("#EDGES");
7 const TStr NODES_START = ("#NODES");
8 const TStr END_SENTINEL = ("#END");
9 const TStr SRC_ID_NAME = ("SrcNId");
10 const TStr DST_ID_NAME = ("DstNId");
11 const TStr NID_NAME = ("NId");
12 const TStr INT_TYPE_PREFIX = ("Int");
13 const TStr FLT_TYPE_PREFIX = ("Flt");
14 const TStr STR_TYPE_PREFIX = ("Str");
15 const TStr NULL_VAL = ("__null__");
16 
18 template <class PGraph> PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId=0, const int& DstColId=1);
20 template <class PGraph> PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId, const char& Separator);
22 PNEANet LoadEdgeListNet(const TStr& InFNm, const char& Separator);
24 template <class PGraph> PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId=0, const int& DstColId=1);
26 template <class PGraph> PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId, TStrHash<TInt>& StrToNIdH);
28 template <class PGraph> PGraph LoadConnList(const TStr& InFNm);
30 template <class PGraph> PGraph LoadConnListStr(const TStr& InFNm, TStrHash<TInt>& StrToNIdH);
31 
33 
35 template <class PGraph> PGraph LoadPajek(const TStr& InFNm);
37 PNGraph LoadDyNet(const TStr& FNm);
40 
41 //TODO: Sparse/Dense adjacency matrix which values we threshold at Thresh to obtain an adjacency matrix.
42 //template <class PGraph> PGraph LoadAdjMtx(const TStr& FNm, const int Thresh);
43 //TODO: Load from a GML file format (http://en.wikipedia.org/wiki/Graph_Modelling_Language)
44 //template <class PGraph> PGraph LoadGml(const TStr& FNm, const int Thresh);
45 
46 
48 template <class PGraph> void SaveEdgeList(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc=TStr());
50 void SaveEdgeListNet(const PNEANet& Graph, const TStr& OutFNm, const TStr& Desc);
52 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm);
54 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH);
56 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH);
58 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH, const TIntStrH& EIdColorH);
60 template <class PGraph> void SaveMatlabSparseMtx(const PGraph& Graph, const TStr& OutFNm);
62 
65 template<class PGraph> void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc=TStr(), const bool& NodeLabels=false, const TIntStrH& NIdColorH=TIntStrH());
67 
70 template<class PGraph> void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const TIntStrH& NIdLabelH);
71 
72 //TODO: Save to a GML file format (http://en.wikipedia.org/wiki/Graph_Modelling_Language)
73 //template <class PGraph> SaveGml(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc);
74 
76 // Implementation
77 
79 
83 template <class PGraph>
84 PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId) {
85  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
86  PGraph Graph = PGraph::TObj::New();
87  int SrcNId, DstNId;
88 
89  while (Ss.Next()) {
90  if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
91  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
92  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
93  Graph->AddEdge(SrcNId, DstNId);
94  }
95  Graph->Defrag();
96  return Graph;
97 }
98 
100 
104 template <class PGraph>
105 PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId, const char& Separator) {
106  TSsParser Ss(InFNm, Separator);
107  PGraph Graph = PGraph::TObj::New();
108  int SrcNId, DstNId;
109  while (Ss.Next()) {
110  if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
111  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
112  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
113  Graph->AddEdge(SrcNId, DstNId);
114  }
115  Graph->Defrag();
116  return Graph;
117 }
118 
120 
125 template <class PGraph>
126 PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId) {
127  TSsParser Ss(InFNm, ssfWhiteSep);
128  PGraph Graph = PGraph::TObj::New();
129  TStrHash<TInt> StrToNIdH(Mega(1), true); // hash-table mapping strings to integer node ids
130  while (Ss.Next()) {
131  const int SrcNId = StrToNIdH.AddKey(Ss[SrcColId]);
132  const int DstNId = StrToNIdH.AddKey(Ss[DstColId]);
133  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
134  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
135  Graph->AddEdge(SrcNId, DstNId);
136  }
137  Graph->Defrag();
138  return Graph;
139 }
140 
142 
148 template <class PGraph>
149 PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId, TStrHash<TInt>& StrToNIdH) {
150  TSsParser Ss(InFNm, ssfWhiteSep);
151  PGraph Graph = PGraph::TObj::New();
152  while (Ss.Next()) {
153  const int SrcNId = StrToNIdH.AddKey(Ss[SrcColId]);
154  const int DstNId = StrToNIdH.AddKey(Ss[DstColId]);
155  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
156  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
157  Graph->AddEdge(SrcNId, DstNId);
158  }
159  Graph->Defrag();
160  return Graph;
161 }
162 
164 
168 template <class PGraph>
169 PGraph LoadConnList(const TStr& InFNm) {
170  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
171  PGraph Graph = PGraph::TObj::New();
172  while (Ss.Next()) {
173  if (! Ss.IsInt(0)) { continue; }
174  const int SrcNId = Ss.GetInt(0);
175  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
176  for (int dst = 1; dst < Ss.Len(); dst++) {
177  const int DstNId = Ss.GetInt(dst);
178  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
179  Graph->AddEdge(SrcNId, DstNId);
180  }
181  }
182  Graph->Defrag();
183  return Graph;
184 }
185 
187 
192 template <class PGraph>
193 PGraph LoadConnListStr(const TStr& InFNm, TStrHash<TInt>& StrToNIdH) {
194  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
195  PGraph Graph = PGraph::TObj::New();
196  while (Ss.Next()) {
197  const int SrcNId = StrToNIdH.AddDatId(Ss[0]);
198  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
199  for (int dst = 1; dst < Ss.Len(); dst++) {
200  const int DstNId = StrToNIdH.AddDatId(Ss[dst]);
201  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
202  Graph->AddEdge(SrcNId, DstNId);
203  }
204  }
205  Graph->Defrag();
206  return Graph;
207 }
208 
209 template <class PGraph>
210 PGraph LoadPajek(const TStr& InFNm) {
211  PGraph Graph = PGraph::TObj::New();
212  TSsParser Ss(InFNm, ssfSpaceSep, true, true, true);
213  while ((Ss.Len()==0 || strstr(Ss[0], "*vertices") == NULL) && ! Ss.Eof()) {
214  Ss.Next(); Ss.ToLc(); }
215  // nodes
216  bool EdgeList = true;
217  EAssert(strstr(Ss[0], "*vertices") != NULL);
218  while (Ss.Next()) {
219  Ss.ToLc();
220  if (Ss.Len()>0 && Ss[0][0] == '%') { continue; } // comment
221  if (strstr(Ss[0], "*arcslist")!=NULL || strstr(Ss[0],"*edgeslist")!=NULL) { EdgeList=false; break; }
222  if (strstr(Ss[0], "*arcs")!=NULL || strstr(Ss[0],"*edges")!=NULL) { break; } // arcs are directed, edges are undirected
223  Graph->AddNode(Ss.GetInt(0));
224  }
225  // edges
226  while (Ss.Next()) {
227  if (Ss.Len()>0 && Ss[0][0] == '%') { continue; } // comment
228  if (Ss.Len()>0 && Ss[0][0] == '*') { break; }
229  if (EdgeList) {
230  // <source> <destination> <weight>
231  if (Ss.Len() >= 3 && Ss.IsInt(0) && Ss.IsInt(1)) {
232  Graph->AddEdge(Ss.GetInt(0), Ss.GetInt(1)); }
233  } else {
234  // <source> <destination1> <destination2> <destination3> ...
235  const int SrcNId = Ss.GetInt(0);
236  for (int i = 1; i < Ss.Len(); i++) {
237  Graph->AddEdge(SrcNId, Ss.GetInt(i)); }
238  }
239  }
240  return Graph;
241 }
242 
243 template <class PGraph>
244 void SaveEdgeList(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc) {
245  FILE *F = fopen(OutFNm.CStr(), "wt");
246  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) { fprintf(F, "# Directed graph: %s \n", OutFNm.CStr()); }
247  else { fprintf(F, "# Undirected graph (each unordered pair of nodes is saved once): %s\n", OutFNm.CStr()); }
248  if (! Desc.Empty()) { fprintf(F, "# %s\n", Desc.CStr()); }
249  fprintf(F, "# Nodes: %d Edges: %d\n", Graph->GetNodes(), Graph->GetEdges());
250  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) { fprintf(F, "# FromNodeId\tToNodeId\n"); }
251  else { fprintf(F, "# NodeId\tNodeId\n"); }
252  for (typename PGraph::TObj::TEdgeI ei = Graph->BegEI(); ei < Graph->EndEI(); ei++) {
253  fprintf(F, "%d\t%d\n", ei.GetSrcNId(), ei.GetDstNId());
254  }
255  fclose(F);
256 }
257 
258 template <class PGraph>
259 void SavePajek(const PGraph& Graph, const TStr& OutFNm) {
260  TIntH NIdToIdH(Graph->GetNodes(), true);
261  FILE *F = fopen(OutFNm.CStr(), "wt");
262  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
263  int i = 0;
264  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
265  fprintf(F, "%d \"%d\" ic Red fos 10\n", i+1, NI.GetId()); // ic: internal color, fos: font size
266  NIdToIdH.AddDat(NI.GetId(), i+1);
267  }
268  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
269  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
270  else {
271  fprintf(F, "*Edges %d\n", Graph->GetEdges());
272  }
273  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
274  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
275  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
276  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1); // width=1
277  }
278  fclose(F);
279 }
280 
283 template <class PGraph>
284 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH) {
285  TIntH NIdToIdH(Graph->GetNodes(), true);
286  FILE *F = fopen(OutFNm.CStr(), "wt");
287  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
288  int i = 0;
289  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
290  fprintf(F, "%d \"%d\" ic %s fos 10\n", i+1, NI.GetId(),
291  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
292  NIdToIdH.AddDat(NI.GetId(), i+1);
293  }
294  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
295  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
296  else {
297  fprintf(F, "*Edges %d\n", Graph->GetEdges());
298  }
299  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
300  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
301  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
302  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1);
303  }
304  fclose(F);
305 }
306 
310 template <class PGraph>
311 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH) {
312  TIntH NIdToIdH(Graph->GetNodes(), true);
313  FILE *F = fopen(OutFNm.CStr(), "wt");
314  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
315  int i = 0;
316  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
317  fprintf(F, "%d \"%s\" ic %s fos 10\n", i+1,
318  NIdLabelH.IsKey(NI.GetId()) ? NIdLabelH.GetDat(NI.GetId()).CStr() : TStr::Fmt("%d", NI.GetId()).CStr(),
319  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
320  NIdToIdH.AddDat(NI.GetId(), i+1);
321  }
322  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
323  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
324  else {
325  fprintf(F, "*Edges %d\n", Graph->GetEdges());
326  }
327  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
328  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
329  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
330  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1);
331  }
332  fclose(F);
333 }
334 
339 template <class PGraph>
340 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH, const TIntStrH& EIdColorH) {
341  CAssert(HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // network needs to have edge ids
342  TIntH NIdToIdH(Graph->GetNodes(), true);
343  FILE *F = fopen(OutFNm.CStr(), "wt");
344  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
345  int i = 0;
346  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
347  fprintf(F, "%d \"%s\" ic %s fos 10\n", i+1,
348  NIdLabelH.IsKey(NI.GetId()) ? NIdLabelH.GetDat(NI.GetId()).CStr() : TStr::Fmt("%d", NI.GetId()).CStr(),
349  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
350  NIdToIdH.AddDat(NI.GetId(), i+1);
351  }
352  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
353  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
354  else {
355  fprintf(F, "*Edges %d\n", Graph->GetEdges());
356  }
357  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
358  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
359  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
360  fprintf(F, "%d %d 1 c %s\n", SrcNId, DstNId,
361  EIdColorH.IsKey(EI.GetId()) ? EIdColorH.GetDat(EI.GetId()).CStr() : "Black");
362  }
363  fclose(F);
364 }
365 
367 template <class PGraph>
368 void SaveMatlabSparseMtx(const PGraph& Graph, const TStr& OutFNm) {
369  FILE *F = fopen(OutFNm.CStr(), "wt");
370  TIntSet NIdSet(Graph->GetNodes()); // so that
371  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
372  NIdSet.AddKey(NI.GetId());
373  }
374  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
375  const int Src = NIdSet.GetKeyId(EI.GetSrcNId())+1;
376  const int Dst = NIdSet.GetKeyId(EI.GetDstNId())+1;
377  fprintf(F, "%d\t%d\t1\n", Src, Dst);
378  if (! HasGraphFlag(typename PGraph::TObj, gfDirected) && Src!=Dst) {
379  fprintf(F, "%d\t%d\t1\n", Dst, Src);
380  }
381  }
382  fclose(F);
383 }
384 
385 template<class PGraph>
386 void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const bool& NodeLabels, const TIntStrH& NIdColorH) {
387  const bool IsDir = HasGraphFlag(typename PGraph::TObj, gfDirected);
388  FILE *F = fopen(OutFNm.CStr(), "wt");
389  if (! Desc.Empty()) fprintf(F, "/*****\n%s\n*****/\n\n", Desc.CStr());
390  if (IsDir) { fprintf(F, "digraph G {\n"); } else { fprintf(F, "graph G {\n"); }
391  fprintf(F, " graph [splines=false overlap=false]\n"); //size=\"12,10\" ratio=fill
392  // node [width=0.3, height=0.3, label=\"\", style=filled, color=black]
393  // node [shape=box, width=0.3, height=0.3, label=\"\", style=filled, fillcolor=red]
394  fprintf(F, " node [shape=ellipse, width=0.3, height=0.3%s]\n", NodeLabels?"":", label=\"\"");
395  // node colors
396  //for (int i = 0; i < NIdColorH.Len(); i++) {
397  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
398  if (NIdColorH.IsKey(NI.GetId())) {
399  fprintf(F, " %d [style=filled, fillcolor=\"%s\"];\n", NI.GetId(), NIdColorH.GetDat(NI.GetId()).CStr()); }
400  else {
401  fprintf(F, " %d ;\n", NI.GetId());
402  }
403  }
404  // edges
405  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
406  if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 && !NIdColorH.IsKey(NI.GetId())) {
407  fprintf(F, "%d;\n", NI.GetId()); }
408  else {
409  for (int e = 0; e < NI.GetOutDeg(); e++) {
410  if (! IsDir && NI.GetId() > NI.GetOutNId(e)) { continue; }
411  fprintf(F, " %d %s %d;\n", NI.GetId(), IsDir?"->":"--", NI.GetOutNId(e));
412  }
413  }
414  }
415  if (! Desc.Empty()) {
416  fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
417  fprintf(F, " fontsize=24;\n");
418  }
419  fprintf(F, "}\n");
420  fclose(F);
421 }
422 
423 template<class PGraph>
424 void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const TIntStrH& NIdLabelH) {
425  const bool IsDir = Graph->HasFlag(gfDirected);
426  FILE *F = fopen(OutFNm.CStr(), "wt");
427  if (! Desc.Empty()) fprintf(F, "/*****\n%s\n*****/\n\n", Desc.CStr());
428  if (IsDir) { fprintf(F, "digraph G {\n"); } else { fprintf(F, "graph G {\n"); }
429  fprintf(F, " graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
430  fprintf(F, " node [shape=ellipse, width=0.3, height=0.3]\n");
431  // node colors
432  //for (int i = 0; i < NodeLabelH.Len(); i++) {
433  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
434  fprintf(F, " %d [label=\"%s\"];\n", NI.GetId(), NIdLabelH.GetDat(NI.GetId()).CStr());
435 }
436  // edges
437  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
438  if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 && ! NIdLabelH.IsKey(NI.GetId())) {
439  fprintf(F, "%d;\n", NI.GetId()); }
440  else {
441  for (int e = 0; e < NI.GetOutDeg(); e++) {
442  if (! IsDir && NI.GetId() > NI.GetOutNId(e)) { continue; }
443  fprintf(F, " %d %s %d;\n", NI.GetId(), IsDir?"->":"--", NI.GetOutNId(e));
444  }
445  }
446  }
447  if (! Desc.Empty()) {
448  fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
449  fprintf(F, " fontsize=24;\n");
450  }
451  fprintf(F, "}\n");
452  fclose(F);
453 }
454 
455 } // namespace TSnap
const TStr EDGES_START
Definition: gio.h:6
void SavePajek(const PGraph &Graph, const TStr &OutFNm)
Saves a graph in a Pajek .NET format.
Definition: gio.h:259
void SaveEdgeListNet(const PNEANet &Graph, const TStr &OutFNm, const TStr &Desc)
Saves a network into a text file. Each line encodes either an edge or a node, along with its attribut...
Definition: gio.cpp:269
void SaveGViz(const PGraph &Graph, const TStr &OutFNm, const TStr &Desc=TStr(), const bool &NodeLabels=false, const TIntStrH &NIdColorH=TIntStrH())
Save a graph in GraphVizp .DOT format.
Definition: gio.h:386
const TStr STR_TYPE_PREFIX
Definition: gio.h:14
PGraph LoadConnListStr(const TStr &InFNm, TStrHash< TInt > &StrToNIdH)
Loads a (directed, undirected or multi) graph from a text file InFNm with 1 node and all its edges in...
Definition: gio.h:193
void ToLc()
Transforms the current line to lower case.
Definition: ss.cpp:440
Definition: ss.h:72
const TStr NID_NAME
Definition: gio.h:11
PGraph LoadEdgeList(const TStr &InFNm, const int &SrcColId=0, const int &DstColId=1)
Loads a (directed, undirected or multi) graph from a text file InFNm with 1 edge per line (whitespace...
Definition: gio.h:84
TDat & AddDatId(const char *Key)
Definition: hash.h:858
bool GetInt(const int &FldN, int &Val) const
If the field FldN is an integer its value is returned in Val and the function returns true...
Definition: ss.cpp:447
THash< TInt, TStr > TIntStrH
Definition: hash.h:619
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
PGraph LoadPajek(const TStr &InFNm)
Loads a (directed, undirected or multi) graph from Pajek .PAJ format file.
Definition: gio.h:210
PGraph LoadConnList(const TStr &InFNm)
Loads a (directed, undirected or multi) graph from a text file InFNm with 1 node and all its edges in...
Definition: gio.h:169
const TStr DST_ID_NAME
Definition: gio.h:10
TVec< PNGraph > LoadDyNetGraphV(const TStr &FNm)
For more info see ORA Network Analysis Data (http://www.casos.cs.cmu.edu/computational_tools/data2.php)
Definition: gio.cpp:322
have explicit edges (multigraph): TNEGraph, TNodeEdgeNet
Definition: gbase.h:14
const TStr FLT_TYPE_PREFIX
Definition: gio.h:13
bool Eof() const
Checks for end of file.
Definition: ss.h:122
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
PNEANet LoadEdgeListNet(const TStr &InFNm, const char &Separator)
Loads a network from the text file InFNm with 1 node/edge per line ('Separator' separated columns...
Definition: gio.cpp:138
const TStr NODES_START
Definition: gio.h:7
Whitespace (space or tab) separated.
Definition: ss.h:11
const TStr END_SENTINEL
Definition: gio.h:8
#define Mega(n)
Definition: gbase.h:4
PGraph LoadEdgeListStr(const TStr &InFNm, const int &SrcColId=0, const int &DstColId=1)
Loads a (directed, undirected or multi) graph from a text file InFNm with 1 edge per line (whitespace...
Definition: gio.h:126
int AddKey(const TKey &Key)
Definition: shash.h:1254
int Len() const
Returns the number of fields in the current line.
Definition: ss.h:114
void SaveEdgeList(const PGraph &Graph, const TStr &OutFNm, const TStr &Desc=TStr())
Saves a graph into a text file. Each line contains two columns and encodes a single edge:
Definition: gio.h:244
Space separated.
Definition: ss.h:10
int AddKey(const char *Key)
Definition: hash.h:968
Definition: hash.h:781
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph
Definition: gbase.h:13
#define EAssert(Cond)
Definition: bd.h:280
#define CAssert(Cond)
Definition: bd.h:302
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
Definition: hash.h:97
bool Next()
Loads next line from the input file.
Definition: ss.cpp:412
Definition: bd.h:196
const TStr NULL_VAL
Definition: gio.h:15
PNGraph LoadDyNet(const TStr &FNm)
For more info see ORA Network Analysis Data (http://www.casos.cs.cmu.edu/computational_tools/data2.php)
Definition: gio.cpp:296
const TStr INT_TYPE_PREFIX
Definition: gio.h:12
char * CStr()
Definition: dt.h:476
bool IsKey(const TKey &Key) const
Definition: hash.h:258
void SaveMatlabSparseMtx(const PGraph &Graph, const TStr &OutFNm)
Saves a graph in a MATLAB sparse matrix format.
Definition: gio.h:368
bool IsInt(const int &FldN) const
Checks whether fields FldN is an integer.
Definition: ss.h:143
const TStr SRC_ID_NAME
Definition: gio.h:9
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430