SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
testSnap.cpp
Go to the documentation of this file.
00001 // Small example testing basic functionality of SNAP
00002 
00003 #include "Snap.h"
00004 
00005 int main(int argc, char* argv[]) {
00006   // create a graph and save it
00007   { PNGraph Graph = TNGraph::New();
00008   for (int i = 0; i < 10; i++) {
00009     Graph->AddNode(i); }
00010   for (int i = 0; i < 10; i++) {
00011     Graph->AddEdge(i, TInt::Rnd.GetUniDevInt(10)); }
00012   TSnap::SaveEdgeList(Graph, "graph.txt", "Edge list format"); }
00013   // load a graph
00014   PNGraph Graph;
00015   Graph = TSnap::LoadEdgeList<PNGraph>("graph.txt", 0, 1);
00016   // traverse nodes
00017   for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
00018     printf("NodeId: %d, InDegree: %d, OutDegree: %d\n", NI.GetId(), NI.GetInDeg(), NI.GetOutDeg());
00019     printf("OutNodes: ");
00020     for (int e = 0; e < NI.GetOutDeg(); e++) { printf("  %d", NI.GetOutNId(e)); }
00021     printf("\nInNodes: ");
00022     for (int e = 0; e < NI.GetInDeg(); e++) { printf("  %d", NI.GetInNId(e)); }
00023     printf("\n\n");
00024   }
00025   // graph statistic
00026   TSnap::PrintInfo(Graph, "Graph info");
00027   PNGraph MxWcc = TSnap::GetMxWcc(Graph);
00028   TSnap::PrintInfo(MxWcc, "Largest Weakly connected component");
00029   // random graph
00030   PNGraph RndGraph = TSnap::GenRndGnm<PNGraph>(100, 1000);
00031   TGStat GraphStat(RndGraph, TSecTm(1), TGStat::AllStat(), "Gnm graph");
00032   GraphStat.PlotAll("RndGraph", "Random graph on 1000 nodes");
00033   // Forest Fire graph
00034   { TFfGGen ForestFire(false, 1, 0.35, 0.30, 1.0, 0.0, 0.0);
00035   ForestFire.GenGraph(100);
00036   PNGraph FfGraph = ForestFire.GetGraph(); }
00037   // network
00038   TPt<TNodeEDatNet<TStr, TStr> > Net = TNodeEDatNet<TStr, TStr>::New();
00039   Net->AddNode(0, "zero");
00040   Net->AddNode(1, "one");
00041   Net->AddEdge(0, 1, "zero to one");
00042   return 0;
00043 }