SNAP Library 2.3, Developer 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.cpp
Go to the documentation of this file.
1 namespace TSnap {
2 
4 PNGraph LoadDyNet(const TStr& FNm) {
6  THashSet<TStr> NIdStr;
7  while (XmlLx.GetSym()!=xsyEof) {
8  if (XmlLx.Sym==xsySTag && XmlLx.TagNm=="network") {
9  PNGraph G = TNGraph::New();
10  XmlLx.GetSym();
11  while (XmlLx.TagNm=="link") {
12  TStr Str1, Val1, Str2, Val2;
13  XmlLx.GetArg(0, Str1, Val1); XmlLx.GetArg(1, Str2, Val2);
14  IAssert(Str1=="source" && Str2=="target");
15  NIdStr.AddKey(Val1); NIdStr.AddKey(Val2);
16  const int src=NIdStr.GetKeyId(Val1);
17  const int dst=NIdStr.GetKeyId(Val2);
18  if (! G->IsNode(src)) { G->AddNode(src); }
19  if (! G->IsNode(dst)) { G->AddNode(dst); }
20  G->AddEdge(src, dst);
21  XmlLx.GetSym();
22  }
23  return G;
24  }
25  }
26  return PNGraph();
27 }
28 
32  TVec<PNGraph> GraphV;
33  THashSet<TStr> NIdStr;
34  while (XmlLx.GetSym()!=xsyEof) {
35  if (XmlLx.Sym==xsySTag && XmlLx.TagNm=="network") {
36  PNGraph G = TNGraph::New();
37  GraphV.Add(G);
38  XmlLx.GetSym();
39  while (XmlLx.TagNm=="link") {
40  TStr Str1, Val1, Str2, Val2;
41  XmlLx.GetArg(0, Str1, Val1); XmlLx.GetArg(1, Str2, Val2);
42  IAssert(Str1=="source" && Str2=="target");
43  NIdStr.AddKey(Val1); NIdStr.AddKey(Val2);
44  const int src=NIdStr.GetKeyId(Val1);
45  const int dst=NIdStr.GetKeyId(Val2);
46  if (! G->IsNode(src)) { G->AddNode(src); }
47  if (! G->IsNode(dst)) { G->AddNode(dst); }
48  G->AddEdge(src, dst);
49  XmlLx.GetSym();
50  }
51  }
52  }
53  return GraphV;
54 }
55 
56 }; // namespace TSnap
#define IAssert(Cond)
Definition: bd.h:262
TXmlLxSym GetSym()
Definition: xml.cpp:757
TStr TagNm
Definition: xml.h:141
void GetArg(const int &ArgN, TStr &ArgNm, TStr &ArgVal) const
Definition: xml.h:166
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:405
Definition: xml.h:94
int GetKeyId(const TKey &Key) const
Definition: shash.h:1322
static bool IsZipFNm(const TStr &FNm)
Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
Definition: zipfl.h:56
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:208
static PSIn New(const TStr &FNm)
Definition: zipfl.cpp:124
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
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the graph.
Definition: graph.cpp:286
Definition: xml.h:98
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: graph.h:455
TPt< TNGraph > PNGraph
Pointer to a directed graph (TNGraph)
Definition: graph.h:16
int AddKey(const TKey &Key)
Definition: shash.h:1248
Definition: xml.h:93
Definition: dt.h:412
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
TXmlLxSym Sym
Definition: xml.h:139
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:420