SNAP Library 2.3, User Reference  2014-06-16 11:58:46
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 
6 template <class PGraph> PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId=0, const int& DstColId=1);
8 template <class PGraph> PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId, const char& Separator);
10 template <class PGraph> PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId=0, const int& DstColId=1);
12 template <class PGraph> PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId, TStrHash<TInt>& StrToNIdH);
14 template <class PGraph> PGraph LoadConnList(const TStr& InFNm);
16 template <class PGraph> PGraph LoadConnListStr(const TStr& InFNm, TStrHash<TInt>& StrToNIdH);
17 
19 
21 template <class PGraph> PGraph LoadPajek(const TStr& InFNm);
23 PNGraph LoadDyNet(const TStr& FNm);
26 
27 //TODO: Sparse/Dense adjacency matrix which values we threshold at Thresh to obtain an adjacency matrix.
28 //template <class PGraph> PGraph LoadAdjMtx(const TStr& FNm, const int Thresh);
29 //TODO: Load from a GML file format (http://en.wikipedia.org/wiki/Graph_Modelling_Language)
30 //template <class PGraph> PGraph LoadGml(const TStr& FNm, const int Thresh);
31 
32 
34 template <class PGraph> void SaveEdgeList(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc=TStr());
36 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm);
38 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH);
40 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH);
42 template <class PGraph> void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH, const TIntStrH& EIdColorH);
44 template <class PGraph> void SaveMatlabSparseMtx(const PGraph& Graph, const TStr& OutFNm);
46 
49 template<class PGraph> void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc=TStr(), const bool& NodeLabels=false, const TIntStrH& NIdColorH=TIntStrH());
51 
54 template<class PGraph> void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const TIntStrH& NIdLabelH);
55 
56 //TODO: Save to a GML file format (http://en.wikipedia.org/wiki/Graph_Modelling_Language)
57 //template <class PGraph> SaveGml(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc);
58 
60 // Implementation
61 
63 
67 template <class PGraph>
68 PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId) {
69  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
70  PGraph Graph = PGraph::TObj::New();
71  int SrcNId, DstNId;
72  while (Ss.Next()) {
73  if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
74  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
75  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
76  Graph->AddEdge(SrcNId, DstNId);
77  }
78  Graph->Defrag();
79  return Graph;
80 }
81 
83 
87 template <class PGraph>
88 PGraph LoadEdgeList(const TStr& InFNm, const int& SrcColId, const int& DstColId, const char& Separator) {
89  TSsParser Ss(InFNm, Separator);
90  PGraph Graph = PGraph::TObj::New();
91  int SrcNId, DstNId;
92  while (Ss.Next()) {
93  if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
94  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
95  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
96  Graph->AddEdge(SrcNId, DstNId);
97  }
98  Graph->Defrag();
99  return Graph;
100 }
101 
103 
108 template <class PGraph>
109 PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId) {
110  TSsParser Ss(InFNm, ssfWhiteSep);
111  PGraph Graph = PGraph::TObj::New();
112  TStrHash<TInt> StrToNIdH(Mega(1), true); // hash-table mapping strings to integer node ids
113  while (Ss.Next()) {
114  const int SrcNId = StrToNIdH.AddKey(Ss[SrcColId]);
115  const int DstNId = StrToNIdH.AddKey(Ss[DstColId]);
116  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
117  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
118  Graph->AddEdge(SrcNId, DstNId);
119  }
120  Graph->Defrag();
121  return Graph;
122 }
123 
125 
131 template <class PGraph>
132 PGraph LoadEdgeListStr(const TStr& InFNm, const int& SrcColId, const int& DstColId, TStrHash<TInt>& StrToNIdH) {
133  TSsParser Ss(InFNm, ssfWhiteSep);
134  PGraph Graph = PGraph::TObj::New();
135  while (Ss.Next()) {
136  const int SrcNId = StrToNIdH.AddKey(Ss[SrcColId]);
137  const int DstNId = StrToNIdH.AddKey(Ss[DstColId]);
138  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
139  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
140  Graph->AddEdge(SrcNId, DstNId);
141  }
142  Graph->Defrag();
143  return Graph;
144 }
145 
147 
151 template <class PGraph>
152 PGraph LoadConnList(const TStr& InFNm) {
153  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
154  PGraph Graph = PGraph::TObj::New();
155  while (Ss.Next()) {
156  if (! Ss.IsInt(0)) { continue; }
157  const int SrcNId = Ss.GetInt(0);
158  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
159  for (int dst = 1; dst < Ss.Len(); dst++) {
160  const int DstNId = Ss.GetInt(dst);
161  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
162  Graph->AddEdge(SrcNId, DstNId);
163  }
164  }
165  Graph->Defrag();
166  return Graph;
167 }
168 
170 
175 template <class PGraph>
176 PGraph LoadConnListStr(const TStr& InFNm, TStrHash<TInt>& StrToNIdH) {
177  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
178  PGraph Graph = PGraph::TObj::New();
179  while (Ss.Next()) {
180  const int SrcNId = StrToNIdH.AddDatId(Ss[0]);
181  if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
182  for (int dst = 1; dst < Ss.Len(); dst++) {
183  const int DstNId = StrToNIdH.AddDatId(Ss[dst]);
184  if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
185  Graph->AddEdge(SrcNId, DstNId);
186  }
187  }
188  Graph->Defrag();
189  return Graph;
190 }
191 
192 template <class PGraph>
193 PGraph LoadPajek(const TStr& InFNm) {
194  PGraph Graph = PGraph::TObj::New();
195  TSsParser Ss(InFNm, ssfSpaceSep, true, true, true);
196  while ((Ss.Len()==0 || strstr(Ss[0], "*vertices") == NULL) && ! Ss.Eof()) {
197  Ss.Next(); Ss.ToLc(); }
198  // nodes
199  bool EdgeList = true;
200  EAssert(strstr(Ss[0], "*vertices") != NULL);
201  while (Ss.Next()) {
202  Ss.ToLc();
203  if (Ss.Len()>0 && Ss[0][0] == '%') { continue; } // comment
204  if (strstr(Ss[0], "*arcslist")!=NULL || strstr(Ss[0],"*edgeslist")!=NULL) { EdgeList=false; break; }
205  if (strstr(Ss[0], "*arcs")!=NULL || strstr(Ss[0],"*edges")!=NULL) { break; } // arcs are directed, edges are undirected
206  Graph->AddNode(Ss.GetInt(0));
207  }
208  // edges
209  while (Ss.Next()) {
210  if (Ss.Len()>0 && Ss[0][0] == '%') { continue; } // comment
211  if (Ss.Len()>0 && Ss[0][0] == '*') { break; }
212  if (EdgeList) {
213  // <source> <destination> <weight>
214  if (Ss.Len() >= 3 && Ss.IsInt(0) && Ss.IsInt(1)) {
215  Graph->AddEdge(Ss.GetInt(0), Ss.GetInt(1)); }
216  } else {
217  // <source> <destination1> <destination2> <destination3> ...
218  const int SrcNId = Ss.GetInt(0);
219  for (int i = 1; i < Ss.Len(); i++) {
220  Graph->AddEdge(SrcNId, Ss.GetInt(i)); }
221  }
222  }
223  return Graph;
224 }
225 
226 template <class PGraph>
227 void SaveEdgeList(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc) {
228  FILE *F = fopen(OutFNm.CStr(), "wt");
229  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) { fprintf(F, "# Directed graph: %s \n", OutFNm.CStr()); }
230  else { fprintf(F, "# Undirected graph (each unordered pair of nodes is saved once): %s\n", OutFNm.CStr()); }
231  if (! Desc.Empty()) { fprintf(F, "# %s\n", Desc.CStr()); }
232  fprintf(F, "# Nodes: %d Edges: %d\n", Graph->GetNodes(), Graph->GetEdges());
233  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) { fprintf(F, "# FromNodeId\tToNodeId\n"); }
234  else { fprintf(F, "# NodeId\tNodeId\n"); }
235  for (typename PGraph::TObj::TEdgeI ei = Graph->BegEI(); ei < Graph->EndEI(); ei++) {
236  fprintf(F, "%d\t%d\n", ei.GetSrcNId(), ei.GetDstNId());
237  }
238  fclose(F);
239 }
240 
241 template <class PGraph>
242 void SavePajek(const PGraph& Graph, const TStr& OutFNm) {
243  TIntH NIdToIdH(Graph->GetNodes(), true);
244  FILE *F = fopen(OutFNm.CStr(), "wt");
245  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
246  int i = 0;
247  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
248  fprintf(F, "%d \"%d\" ic Red fos 10\n", i+1, NI.GetId()); // ic: internal color, fos: font size
249  NIdToIdH.AddDat(NI.GetId(), i+1);
250  }
251  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
252  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
253  else {
254  fprintf(F, "*Edges %d\n", Graph->GetEdges());
255  }
256  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
257  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
258  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
259  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1); // width=1
260  }
261  fclose(F);
262 }
263 
266 template <class PGraph>
267 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH) {
268  TIntH NIdToIdH(Graph->GetNodes(), true);
269  FILE *F = fopen(OutFNm.CStr(), "wt");
270  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
271  int i = 0;
272  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
273  fprintf(F, "%d \"%d\" ic %s fos 10\n", i+1, NI.GetId(),
274  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
275  NIdToIdH.AddDat(NI.GetId(), i+1);
276  }
277  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
278  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
279  else {
280  fprintf(F, "*Edges %d\n", Graph->GetEdges());
281  }
282  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
283  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
284  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
285  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1);
286  }
287  fclose(F);
288 }
289 
293 template <class PGraph>
294 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH) {
295  TIntH NIdToIdH(Graph->GetNodes(), true);
296  FILE *F = fopen(OutFNm.CStr(), "wt");
297  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
298  int i = 0;
299  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
300  fprintf(F, "%d \"%s\" ic %s fos 10\n", i+1,
301  NIdLabelH.IsKey(NI.GetId()) ? NIdLabelH.GetDat(NI.GetId()).CStr() : TStr::Fmt("%d", NI.GetId()).CStr(),
302  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
303  NIdToIdH.AddDat(NI.GetId(), i+1);
304  }
305  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
306  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
307  else {
308  fprintf(F, "*Edges %d\n", Graph->GetEdges());
309  }
310  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
311  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
312  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
313  fprintf(F, "%d %d %d c Black\n", SrcNId, DstNId, 1);
314  }
315  fclose(F);
316 }
317 
322 template <class PGraph>
323 void SavePajek(const PGraph& Graph, const TStr& OutFNm, const TIntStrH& NIdColorH, const TIntStrH& NIdLabelH, const TIntStrH& EIdColorH) {
324  CAssert(HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // network needs to have edge ids
325  TIntH NIdToIdH(Graph->GetNodes(), true);
326  FILE *F = fopen(OutFNm.CStr(), "wt");
327  fprintf(F, "*Vertices %d\n", Graph->GetNodes());
328  int i = 0;
329  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, i++) {
330  fprintf(F, "%d \"%s\" ic %s fos 10\n", i+1,
331  NIdLabelH.IsKey(NI.GetId()) ? NIdLabelH.GetDat(NI.GetId()).CStr() : TStr::Fmt("%d", NI.GetId()).CStr(),
332  NIdColorH.IsKey(NI.GetId()) ? NIdColorH.GetDat(NI.GetId()).CStr() : "Red");
333  NIdToIdH.AddDat(NI.GetId(), i+1);
334  }
335  if (HasGraphFlag(typename PGraph::TObj, gfDirected)) {
336  fprintf(F, "*Arcs %d\n", Graph->GetEdges()); } // arcs are directed, edges are undirected
337  else {
338  fprintf(F, "*Edges %d\n", Graph->GetEdges());
339  }
340  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
341  const int SrcNId = NIdToIdH.GetDat(EI.GetSrcNId());
342  const int DstNId = NIdToIdH.GetDat(EI.GetDstNId());
343  fprintf(F, "%d %d 1 c %s\n", SrcNId, DstNId,
344  EIdColorH.IsKey(EI.GetId()) ? EIdColorH.GetDat(EI.GetId()).CStr() : "Black");
345  }
346  fclose(F);
347 }
348 
350 template <class PGraph>
351 void SaveMatlabSparseMtx(const PGraph& Graph, const TStr& OutFNm) {
352  FILE *F = fopen(OutFNm.CStr(), "wt");
353  TIntSet NIdSet(Graph->GetNodes()); // so that
354  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
355  NIdSet.AddKey(NI.GetId());
356  }
357  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
358  const int Src = NIdSet.GetKeyId(EI.GetSrcNId())+1;
359  const int Dst = NIdSet.GetKeyId(EI.GetDstNId())+1;
360  fprintf(F, "%d\t%d\t1\n", Src, Dst);
361  if (! HasGraphFlag(typename PGraph::TObj, gfDirected) && Src!=Dst) {
362  fprintf(F, "%d\t%d\t1\n", Dst, Src);
363  }
364  }
365  fclose(F);
366 }
367 
368 template<class PGraph>
369 void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const bool& NodeLabels, const TIntStrH& NIdColorH) {
370  const bool IsDir = HasGraphFlag(typename PGraph::TObj, gfDirected);
371  FILE *F = fopen(OutFNm.CStr(), "wt");
372  if (! Desc.Empty()) fprintf(F, "/*****\n%s\n*****/\n\n", Desc.CStr());
373  if (IsDir) { fprintf(F, "digraph G {\n"); } else { fprintf(F, "graph G {\n"); }
374  fprintf(F, " graph [splines=false overlap=false]\n"); //size=\"12,10\" ratio=fill
375  // node [width=0.3, height=0.3, label=\"\", style=filled, color=black]
376  // node [shape=box, width=0.3, height=0.3, label=\"\", style=filled, fillcolor=red]
377  fprintf(F, " node [shape=ellipse, width=0.3, height=0.3%s]\n", NodeLabels?"":", label=\"\"");
378  // node colors
379  //for (int i = 0; i < NIdColorH.Len(); i++) {
380  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
381  if (NIdColorH.IsKey(NI.GetId())) {
382  fprintf(F, " %d [style=filled, fillcolor=\"%s\"];\n", NI.GetId(), NIdColorH.GetDat(NI.GetId()).CStr()); }
383  else {
384  fprintf(F, " %d ;\n", NI.GetId());
385  }
386  }
387  // edges
388  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
389  if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 && !NIdColorH.IsKey(NI.GetId())) {
390  fprintf(F, "%d;\n", NI.GetId()); }
391  else {
392  for (int e = 0; e < NI.GetOutDeg(); e++) {
393  if (! IsDir && NI.GetId() > NI.GetOutNId(e)) { continue; }
394  fprintf(F, " %d %s %d;\n", NI.GetId(), IsDir?"->":"--", NI.GetOutNId(e));
395  }
396  }
397  }
398  if (! Desc.Empty()) {
399  fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
400  fprintf(F, " fontsize=24;\n");
401  }
402  fprintf(F, "}\n");
403  fclose(F);
404 }
405 
406 template<class PGraph>
407 void SaveGViz(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc, const TIntStrH& NIdLabelH) {
408  const bool IsDir = Graph->HasFlag(gfDirected);
409  FILE *F = fopen(OutFNm.CStr(), "wt");
410  if (! Desc.Empty()) fprintf(F, "/*****\n%s\n*****/\n\n", Desc.CStr());
411  if (IsDir) { fprintf(F, "digraph G {\n"); } else { fprintf(F, "graph G {\n"); }
412  fprintf(F, " graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
413  fprintf(F, " node [shape=ellipse, width=0.3, height=0.3]\n");
414  // node colors
415  //for (int i = 0; i < NodeLabelH.Len(); i++) {
416  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
417  fprintf(F, " %d [label=\"%s\"];\n", NI.GetId(), NIdLabelH.GetDat(NI.GetId()).CStr());
418 }
419  // edges
420  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
421  if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 && ! NIdLabelH.IsKey(NI.GetId())) {
422  fprintf(F, "%d;\n", NI.GetId()); }
423  else {
424  for (int e = 0; e < NI.GetOutDeg(); e++) {
425  if (! IsDir && NI.GetId() > NI.GetOutNId(e)) { continue; }
426  fprintf(F, " %d %s %d;\n", NI.GetId(), IsDir?"->":"--", NI.GetOutNId(e));
427  }
428  }
429  }
430  if (! Desc.Empty()) {
431  fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
432  fprintf(F, " fontsize=24;\n");
433  }
434  fprintf(F, "}\n");
435  fclose(F);
436 }
437 
438 } // namespace TSnap
void SavePajek(const PGraph &Graph, const TStr &OutFNm)
Saves a graph in a Pajek .NET format.
Definition: gio.h:242
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:369
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:176
void ToLc()
Transforms the current line to lower case.
Definition: ss.cpp:436
Definition: ss.h:72
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:68
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:193
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:152
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:30
have explicit edges (multigraph): TNEGraph, TNodeEdgeNet
Definition: gbase.h:14
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
Whitespace (space or tab) separated.
Definition: ss.h:11
#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:109
int AddKey(const TKey &Key)
Definition: shash.h:1248
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:227
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
bool Next()
Loads next line from the input file.
Definition: ss.cpp:410
Definition: bd.h:196
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:4
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:351
bool IsInt(const int &FldN) const
Checks whether fields FldN is an integer.
Definition: ss.h:142
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