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
testSnap.cpp
Go to the documentation of this file.
1 // Small example testing basic functionality of SNAP
2 
3 #include "Snap.h"
4 
5 int main(int argc, char* argv[]) {
6  // create a graph and save it
7  { PNGraph Graph = TNGraph::New();
8  for (int i = 0; i < 10; i++) {
9  Graph->AddNode(i); }
10  for (int i = 0; i < 10; i++) {
11  Graph->AddEdge(i, TInt::Rnd.GetUniDevInt(10)); }
12  TSnap::SaveEdgeList(Graph, "graph.txt", "Edge list format"); }
13  // load a graph
14  PNGraph Graph;
15  Graph = TSnap::LoadEdgeList<PNGraph>("graph.txt", 0, 1);
16  // traverse nodes
17  for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
18  printf("NodeId: %d, InDegree: %d, OutDegree: %d\n", NI.GetId(), NI.GetInDeg(), NI.GetOutDeg());
19  printf("OutNodes: ");
20  for (int e = 0; e < NI.GetOutDeg(); e++) { printf(" %d", NI.GetOutNId(e)); }
21  printf("\nInNodes: ");
22  for (int e = 0; e < NI.GetInDeg(); e++) { printf(" %d", NI.GetInNId(e)); }
23  printf("\n\n");
24  }
25  // graph statistic
26  TSnap::PrintInfo(Graph, "Graph info");
27  PNGraph MxWcc = TSnap::GetMxWcc(Graph);
28  TSnap::PrintInfo(MxWcc, "Largest Weakly connected component");
29  // random graph
30  PNGraph RndGraph = TSnap::GenRndGnm<PNGraph>(100, 1000);
31  TGStat GraphStat(RndGraph, TSecTm(1), TGStat::AllStat(), "Gnm graph");
32  GraphStat.PlotAll("RndGraph", "Random graph on 1000 nodes");
33  // Forest Fire graph
34  { TFfGGen ForestFire(false, 1, 0.35, 0.30, 1.0, 0.0, 0.0);
35  ForestFire.GenGraph(100);
36  PNGraph FfGraph = ForestFire.GetGraph(); }
37  // network
39  Net->AddNode(0, "zero");
40  Net->AddNode(1, "one");
41  Net->AddEdge(0, 1, "zero to one");
42  return 0;
43 }
TStopReason GenGraph(const int &GraphNodes, const bool &FloodStop=true)
Definition: ff.cpp:327
PGraph GetMxWcc(const PGraph &Graph)
Returns a graph representing the largest weakly connected component on an input Graph.
Definition: cncom.h:452
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:405
static TFSet AllStat()
Definition: gstat.cpp:401
static TRnd Rnd
Definition: dt.h:1050
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEDatNet::New().
Definition: network.h:593
Statistics of a Graph Snapshot.
Definition: gstat.h:36
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
Definition: tm.h:81
int main(int argc, char *argv[])
Definition: testSnap.cpp:5
PNGraph GetGraph() const
Definition: ff.h:64
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:324
Definition: bd.h:196
Definition: ff.h:49
void PrintInfo(const PGraph &Graph, const TStr &Desc="", const TStr &OutFNm="", const bool &Fast=true)
Prints basic graph statistics.
Definition: gbase.h:84