SNAP Library 2.4, User Reference  2015-05-11 19:40:56
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  while (Ss.Next()) {
89  if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
90  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
91  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
92  Graph->AddEdge(SrcNId, DstNId);
93  }
94  Graph->Defrag();
95  return Graph;
96 }
97 
99 
103 template <class PGraph>
104 PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId, const char& Separator) {
105  TSsParser Ss(InFNm, Separator);
106  PGraph Graph = PGraph::TObj::New();
107  int SrcNId, DstNId;
108  while (Ss.Next()) {
109  if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
110  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
111  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
112  Graph->AddEdge(SrcNId, DstNId);
113  }
114  Graph->Defrag();
115  return Graph;
116 }
117 
119 
124 template <class PGraph>
125 PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId) {
126  TSsParser Ss(InFNm, ssfWhiteSep);
127  PGraph Graph = PGraph::TObj::New();
128  TStrHash<TInt> StrToNIdH(Mega(1), true); // hash-table mapping strings to integer node ids
129  while (Ss.Next()) {
130  const int SrcNId = StrToNIdH.AddKey(Ss[SrcColId]);
131  const int DstNId = StrToNIdH.AddKey(Ss[DstColId]);
132  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
133  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
134  Graph->AddEdge(SrcNId, DstNId);
135  }
136  Graph->Defrag();
137  return Graph;
138 }
139 
141 
147 template <class PGraph>
148 PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId, TStrHash<TInt>& StrToNIdH) {
149  TSsParser Ss(InFNm, ssfWhiteSep);
150  PGraph Graph = PGraph::TObj::New();
151  while (Ss.Next()) {
152  const int SrcNId = StrToNIdH.AddKey(Ss[SrcColId]);
153  const int DstNId = StrToNIdH.AddKey(Ss[DstColId]);
154  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
155  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
156  Graph->AddEdge(SrcNId, DstNId);
157  }
158  Graph->Defrag();
159  return Graph;
160 }
161 
163 
167 template <class PGraph>
168 PGraph LoadConnList(const TStr& InFNm) {
169  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
170  PGraph Graph = PGraph::TObj::New();
171  while (Ss.Next()) {
172  if (! Ss.IsInt(0)) { continue; }
173  const int SrcNId = Ss.GetInt(0);
174  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
175  for (int dst = 1; dst < Ss.Len(); dst++) {
176  const int DstNId = Ss.GetInt(dst);
177  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
178  Graph->AddEdge(SrcNId, DstNId);
179  }
180  }
181  Graph->Defrag();
182  return Graph;
183 }
184 
186 
191 template <class PGraph>
192 PGraph LoadConnListStr(const TStr& InFNm, TStrHash<TInt>& StrToNIdH) {
193  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
194  PGraph Graph = PGraph::TObj::New();
195  while (Ss.Next()) {
196  const int SrcNId = StrToNIdH.AddDatId(Ss[0]);
197  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
198  for (int dst = 1; dst < Ss.Len(); dst++) {
199  const int DstNId = StrToNIdH.AddDatId(Ss[dst]);
200  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
201  Graph->AddEdge(SrcNId, DstNId);
202  }
203  }
204  Graph->Defrag();
205  return Graph;
206 }
207 
208 template <class PGraph>
209 PGraph LoadPajek(const TStr& InFNm) {
210  PGraph Graph = PGraph::TObj::New();
211  TSsParser Ss(InFNm, ssfSpaceSep, true, true, true);
212  while ((Ss.Len()==0 || strstr(Ss[0], "*vertices") == NULL) && ! Ss.Eof()) {
213  Ss.Next(); Ss.ToLc(); }
214  // nodes
215  bool EdgeList = true;
216  EAssert(strstr(Ss[0], "*vertices") != NULL);
217  while (Ss.Next()) {
218  Ss.ToLc();
219  if (Ss.Len()>0 && Ss[0][0] == '%') { continue; } // comment
220  if (strstr(Ss[0], "*arcslist")!=NULL || strstr(Ss[0],"*edgeslist")!=NULL) { EdgeList=false; break; }
221  if (strstr(Ss[0], "*arcs")!=NULL || strstr(Ss[0],"*edges")!=NULL) { break; } // arcs are directed, edges are undirected
222  Graph->AddNode(Ss.GetInt(0));
223  }
224  // edges
225  while (Ss.Next()) {
226  if (Ss.Len()>0 && Ss[0][0] == '%') { continue; } // comment
227  if (Ss.Len()>0 && Ss[0][0] == '*') { break; }
228  if (EdgeList) {
229  // <source> <destination> <weight>
230  if (Ss.Len() >= 3 && Ss.IsInt(0) && Ss.IsInt(1)) {
231  Graph->AddEdge(Ss.GetInt(0), Ss.GetInt(1)); }
232  } else {
233  // <source> <destination1> <destination2> <destination3> ...
234  const int SrcNId = Ss.GetInt(0);
235  for (int i = 1; i < Ss.Len(); i++) {
236  Graph->AddEdge(SrcNId, Ss.GetInt(i)); }
237  }
238  }
239  return Graph;
240 }
241 
242 template <class PGraph>
243 void SaveEdgeList(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc) {
244  FILE *F = fopen(OutFNm.CStr(), "wt");
245  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) { fprintf(F, "# Directed graph: %s \n", OutFNm.CStr()); }
246  else { fprintf(F, "# Undirected graph (each unordered pair of nodes is saved once): %s\n", OutFNm.CStr()); }
247  if (! Desc.Empty()) { fprintf(F, "# %s\n", Desc.CStr()); }
248  fprintf(F, "# Nodes: %d Edges: %d\n", Graph->GetNodes(), Graph->GetEdges());
249  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) { fprintf(F, "# FromNodeId\tToNodeId\n"); }
250  else { fprintf(F, "# NodeId\tNodeId\n"); }
251  for (typename PGraph::TObj::TEdgeI ei = Graph->BegEI(); ei < Graph->EndEI(); ei++) {
252  fprintf(F, "%d\t%d\n", ei.GetSrcNId(), ei.GetDstNId());
253  }
254  fclose(F);
255 }
256 
257 template <class PGraph>
258 void SavePajek(const PGraph& Graph, const TStr& OutFNm) {
259  TIntH NIdToIdH(Graph->GetNodes(), true);
260  FILE *F = fopen(OutFNm.CStr(), "wt");
261  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
262  int i = 0;
263  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
264  fprintf(F, "%d \"%d\" ic Red fos 10\n", i+1, NI.GetId()); // ic: internal color, fos: font size
265  NIdToIdH.AddDat(NI.GetId(), i+1);
266  }
267  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
268  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
269  else {
270  fprintf(F, "*Edges %d\n", Graph->GetEdges());
271  }
272  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
273  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
274  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
275  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1); // width=1
276  }
277  fclose(F);
278 }
279 
282 template <class PGraph>
283 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH) {
284  TIntH NIdToIdH(Graph->GetNodes(), true);
285  FILE *F = fopen(OutFNm.CStr(), "wt");
286  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
287  int i = 0;
288  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
289  fprintf(F, "%d \"%d\" ic %s fos 10\n", i+1, NI.GetId(),
290  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
291  NIdToIdH.AddDat(NI.GetId(), i+1);
292  }
293  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
294  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
295  else {
296  fprintf(F, "*Edges %d\n", Graph->GetEdges());
297  }
298  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
299  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
300  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
301  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1);
302  }
303  fclose(F);
304 }
305 
309 template <class PGraph>
310 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH) {
311  TIntH NIdToIdH(Graph->GetNodes(), true);
312  FILE *F = fopen(OutFNm.CStr(), "wt");
313  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
314  int i = 0;
315  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
316  fprintf(F, "%d \"%s\" ic %s fos 10\n", i+1,
317  NIdLabelH.IsKey(NI.GetId()) ? NIdLabelH.GetDat(NI.GetId()).CStr() : TStr::Fmt("%d", NI.GetId()).CStr(),
318  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
319  NIdToIdH.AddDat(NI.GetId(), i+1);
320  }
321  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
322  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
323  else {
324  fprintf(F, "*Edges %d\n", Graph->GetEdges());
325  }
326  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
327  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
328  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
329  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1);
330  }
331  fclose(F);
332 }
333 
338 template <class PGraph>
339 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH, const TIntStrH& EIdColorH) {
340  CAssert(HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // network needs to have edge ids
341  TIntH NIdToIdH(Graph->GetNodes(), true);
342  FILE *F = fopen(OutFNm.CStr(), "wt");
343  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
344  int i = 0;
345  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
346  fprintf(F, "%d \"%s\" ic %s fos 10\n", i+1,
347  NIdLabelH.IsKey(NI.GetId()) ? NIdLabelH.GetDat(NI.GetId()).CStr() : TStr::Fmt("%d", NI.GetId()).CStr(),
348  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
349  NIdToIdH.AddDat(NI.GetId(), i+1);
350  }
351  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
352  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
353  else {
354  fprintf(F, "*Edges %d\n", Graph->GetEdges());
355  }
356  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
357  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
358  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
359  fprintf(F, "%d %d 1 c %s\n", SrcNId, DstNId,
360  EIdColorH.IsKey(EI.GetId()) ? EIdColorH.GetDat(EI.GetId()).CStr() : "Black");
361  }
362  fclose(F);
363 }
364 
366 template <class PGraph>
367 void SaveMatlabSparseMtx(const PGraph& Graph, const TStr& OutFNm) {
368  FILE *F = fopen(OutFNm.CStr(), "wt");
369  TIntSet NIdSet(Graph->GetNodes()); // so that
370  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
371  NIdSet.AddKey(NI.GetId());
372  }
373  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
374  const int Src = NIdSet.GetKeyId(EI.GetSrcNId())+1;
375  const int Dst = NIdSet.GetKeyId(EI.GetDstNId())+1;
376  fprintf(F, "%d\t%d\t1\n", Src, Dst);
377  if (! HasGraphFlag(typename PGraph::TObj, gfDirected) && Src!=Dst) {
378  fprintf(F, "%d\t%d\t1\n", Dst, Src);
379  }
380  }
381  fclose(F);
382 }
383 
384 template<class PGraph>
385 void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const bool& NodeLabels, const TIntStrH& NIdColorH) {
386  const bool IsDir = HasGraphFlag(typename PGraph::TObj, gfDirected);
387  FILE *F = fopen(OutFNm.CStr(), "wt");
388  if (! Desc.Empty()) fprintf(F, "/*****\n%s\n*****/\n\n", Desc.CStr());
389  if (IsDir) { fprintf(F, "digraph G {\n"); } else { fprintf(F, "graph G {\n"); }
390  fprintf(F, " graph [splines=false overlap=false]\n"); //size=\"12,10\" ratio=fill
391  // node [width=0.3, height=0.3, label=\"\", style=filled, color=black]
392  // node [shape=box, width=0.3, height=0.3, label=\"\", style=filled, fillcolor=red]
393  fprintf(F, " node [shape=ellipse, width=0.3, height=0.3%s]\n", NodeLabels?"":", label=\"\"");
394  // node colors
395  //for (int i = 0; i < NIdColorH.Len(); i++) {
396  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
397  if (NIdColorH.IsKey(NI.GetId())) {
398  fprintf(F, " %d [style=filled, fillcolor=\"%s\"];\n", NI.GetId(), NIdColorH.GetDat(NI.GetId()).CStr()); }
399  else {
400  fprintf(F, " %d ;\n", NI.GetId());
401  }
402  }
403  // edges
404  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
405  if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 && !NIdColorH.IsKey(NI.GetId())) {
406  fprintf(F, "%d;\n", NI.GetId()); }
407  else {
408  for (int e = 0; e < NI.GetOutDeg(); e++) {
409  if (! IsDir && NI.GetId() > NI.GetOutNId(e)) { continue; }
410  fprintf(F, " %d %s %d;\n", NI.GetId(), IsDir?"->":"--", NI.GetOutNId(e));
411  }
412  }
413  }
414  if (! Desc.Empty()) {
415  fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
416  fprintf(F, " fontsize=24;\n");
417  }
418  fprintf(F, "}\n");
419  fclose(F);
420 }
421 
422 template<class PGraph>
423 void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const TIntStrH& NIdLabelH) {
424  const bool IsDir = Graph->HasFlag(gfDirected);
425  FILE *F = fopen(OutFNm.CStr(), "wt");
426  if (! Desc.Empty()) fprintf(F, "/*****\n%s\n*****/\n\n", Desc.CStr());
427  if (IsDir) { fprintf(F, "digraph G {\n"); } else { fprintf(F, "graph G {\n"); }
428  fprintf(F, " graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
429  fprintf(F, " node [shape=ellipse, width=0.3, height=0.3]\n");
430  // node colors
431  //for (int i = 0; i < NodeLabelH.Len(); i++) {
432  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
433  fprintf(F, " %d [label=\"%s\"];\n", NI.GetId(), NIdLabelH.GetDat(NI.GetId()).CStr());
434 }
435  // edges
436  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
437  if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 && ! NIdLabelH.IsKey(NI.GetId())) {
438  fprintf(F, "%d;\n", NI.GetId()); }
439  else {
440  for (int e = 0; e < NI.GetOutDeg(); e++) {
441  if (! IsDir && NI.GetId() > NI.GetOutNId(e)) { continue; }
442  fprintf(F, " %d %s %d;\n", NI.GetId(), IsDir?"->":"--", NI.GetOutNId(e));
443  }
444  }
445  }
446  if (! Desc.Empty()) {
447  fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
448  fprintf(F, " fontsize=24;\n");
449  }
450  fprintf(F, "}\n");
451  fclose(F);
452 }
453 
454 } // 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:258
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:385
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:192
void ToLc()
Transforms the current line to lower case.
Definition: ss.cpp:436
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:772
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:443
THash< TInt, TStr > TIntStrH
Definition: hash.h:573
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
PGraph LoadPajek(const TStr &InFNm)
Loads a (directed, undirected or multi) graph from Pajek .PAJ format file.
Definition: gio.h:209
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:168
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:38
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:125
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:243
Space separated.
Definition: ss.h:10
int AddKey(const char *Key)
Definition: hash.h:870
Definition: hash.h:716
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:88
bool Next()
Loads next line from the input file.
Definition: ss.cpp:410
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:216
void SaveMatlabSparseMtx(const PGraph &Graph, const TStr &OutFNm)
Saves a graph in a MATLAB sparse matrix format.
Definition: gio.h:367
bool IsInt(const int &FldN) const
Checks whether fields FldN is an integer.
Definition: ss.h:142
const TStr SRC_ID_NAME
Definition: gio.h:9
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:420