// Test GetNodeClustCf (Specific Node) TEST(triad, TestGetNodeClustCfSpecific) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); for (int i = 0; i < GraphTUN->GetNodes(); i++) { double ClustCf = TSnap::GetNodeClustCf(GraphTUN, i); VerifyNodeClustCf(i, ClustCf); } // TNGraph should be treated as TUNGraph for calculations PNGraph GraphTN = TriadGetTestTNGraph(); for (int i = 0; i < GraphTN->GetNodes(); i++) { double ClustCf = TSnap::GetNodeClustCf(GraphTN, i); VerifyNodeClustCf(i, ClustCf); } // TNEGraph should be treated as TUNGraph for calculations PNEGraph GraphTNE = TriadGetTestTNEGraph(); for (int i = 0; i < GraphTNE->GetNodes(); i++) { double ClustCf = TSnap::GetNodeClustCf(GraphTNE, i); VerifyNodeClustCf(i, ClustCf); } }
// Test GetNodeClustCf (Vector) TEST(triad, TestGetNodeClustCfVector) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); TIntFltH NIdCCfH; TSnap::GetNodeClustCf(GraphTUN, NIdCCfH); for (int i = 0; i < GraphTUN->GetNodes(); i++) { double ClustCf = NIdCCfH.GetDat(i); VerifyNodeClustCf(i, ClustCf); } // TNGraph should be treated as TUNGraph for calculations PNGraph GraphTN = TriadGetTestTNGraph(); NIdCCfH.Clr(); TSnap::GetNodeClustCf(GraphTN, NIdCCfH); for (int i = 0; i < GraphTN->GetNodes(); i++) { double ClustCf = NIdCCfH.GetDat(i); VerifyNodeClustCf(i, ClustCf); } // TNEGraph should be treated as TUNGraph for calculations PNEGraph GraphTNE = TriadGetTestTNEGraph(); NIdCCfH.Clr(); TSnap::GetNodeClustCf(GraphTNE, NIdCCfH); for (int i = 0; i < GraphTNE->GetNodes(); i++) { double ClustCf = NIdCCfH.GetDat(i); VerifyNodeClustCf(i, ClustCf); } }
void TGStatVec::Add(const PNEGraph& Graph, const TSecTm& Time, const TStr& GraphNm) { if (Graph->GetNodes() < (int) TGStatVec::MinNodesEdges) { printf(" ** TGStatVec::Add: graph too small (%d nodes).SKIP\n", Graph->GetNodes()); return; } Add(TGStat::New(Graph, Time, StatFSet, GraphNm)); }
// Test GetNodeTriads (Open and Closed) TEST(triad, TestGetNodeCOTriads) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); for (int i = 0; i < GraphTUN->GetNodes(); i++) { int ClosedTr = -1, OpenTr = -1; TSnap::GetNodeTriads(GraphTUN, i, ClosedTr, OpenTr); VerifyClosedTriads(i, ClosedTr); VerifyOpenTriads(i, OpenTr); } // Test TNGraph which is treated same as undirected. PNGraph GraphTN = TriadGetTestTNGraph(); for (int i = 0; i < GraphTN->GetNodes(); i++) { int ClosedTr = -1, OpenTr = -1; TSnap::GetNodeTriads(GraphTN, i, ClosedTr, OpenTr); VerifyClosedTriads(i, ClosedTr); VerifyOpenTriads(i, OpenTr); } // Test TNEGraph which is treated same as undirected. PNEGraph GraphTNE = TriadGetTestTNEGraph(); for (int i = 0; i < GraphTNE->GetNodes(); i++) { int ClosedTr = -1, OpenTr = -1; TSnap::GetNodeTriads(GraphTNE, i, ClosedTr, OpenTr); VerifyClosedTriads(i, ClosedTr); VerifyOpenTriads(i, OpenTr); } }
// Test GetCmnNbrs: the number of neighbors in common TEST(triad, TestGetCmnNbrs) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); for (int i = 0; i < GraphTUN->GetNodes(); i++) { for (int j = i + 1; j < GraphTUN->GetNodes(); j++) { VerifyCmnNbrs(i, j, TSnap::GetCmnNbrs(GraphTUN, i, j)); } } // Test TNGraph which is same as undirected. PNGraph GraphTN = TriadGetTestTNGraph(); for (int i = 0; i < GraphTN->GetNodes(); i++) { for (int j = i + 1; j < GraphTN->GetNodes(); j++) { VerifyCmnNbrs(i, j, TSnap::GetCmnNbrs(GraphTN, i, j)); } } // Test TNEGraph which is same as undirected. PNEGraph GraphTNE = TriadGetTestTNEGraph(); for (int i = 0; i < GraphTNE->GetNodes(); i++) { for (int j = i + 1; j < GraphTNE->GetNodes(); j++) { VerifyCmnNbrs(i, j, TSnap::GetCmnNbrs(GraphTNE, i, j)); } } }
// Test GetLen2Paths: Number of path lengths 2 between pair of nodes TEST(triad, TestGetLen2Paths) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); for (int i = 0; i < GraphTUN->GetNodes(); i++) { for (int j = i + 1; j < GraphTUN->GetNodes(); j++) { VerifyLen2Paths(i, j, TSnap::GetLen2Paths(GraphTUN, i, j), 0); } } // Test TNGraph which is different from undirected due to out neighbors. PNGraph GraphTN = TriadGetTestTNGraph(); for (int i = 0; i < GraphTN->GetNodes(); i++) { for (int j = i + 1; j < GraphTN->GetNodes(); j++) { VerifyLen2Paths(i, j, TSnap::GetLen2Paths(GraphTN, i, j), 1); } } // Test TNEGraph which is different from undirected due to out neighbors. PNEGraph GraphTNE = TriadGetTestTNEGraph(); for (int i = 0; i < GraphTNE->GetNodes(); i++) { for (int j = i + 1; j < GraphTNE->GetNodes(); j++) { VerifyLen2Paths(i, j, TSnap::GetLen2Paths(GraphTNE, i, j), 2); } } }
// Test edge subgraph conversion TEST(subgraph, TestConvertESubGraphs) { PNEGraph NEGraph; PNGraph NGraph; TIntV NIdV; TIntV EIdV; int i; NGraph = GetTestTNGraph(); EXPECT_EQ(20,NGraph->GetNodes()); EXPECT_EQ(60,NGraph->GetEdges()); for (i = 0; i < 20; i += 2) { NIdV.Add(i); } // TODO: fix TSnap::ConvertSubGraph<PUNGraph>(NGraph, NIdV, true), it fails // UNGraph = TSnap::ConvertSubGraph<PUNGraph>(NGraph, NIdV, true); NEGraph = TSnap::ConvertGraph<PNEGraph>(NGraph); EXPECT_EQ(20,NEGraph->GetNodes()); EXPECT_EQ(60,NEGraph->GetEdges()); // select every second edge i = 0; for (TNEGraph::TEdgeI EI = NEGraph->BegEI(); EI < NEGraph->EndEI(); EI++) { if (i == 0) { EIdV.Add(EI.GetId()); } i = (i + 1) % 2; } NGraph = TSnap::ConvertESubGraph<PNGraph>(NEGraph, EIdV); EXPECT_EQ(20,NGraph->GetNodes()); EXPECT_EQ(30,NGraph->GetEdges()); }
// Generate TNEGraph PNEGraph GetTestTNEGraph() { PNEGraph Graph = TNEGraph::New(); for (int i = 0; i < 20; i++) { Graph->AddNode(i); } for (int i = 0; i < 20; i++) { Graph->AddEdge(i,(i+1) % 20); Graph->AddEdge(i,(i+2) % 20); Graph->AddEdge(i,(i+3) % 20); Graph->AddEdge(i,(i+1) % 20); Graph->AddEdge(i,(i+2) % 20); Graph->AddEdge(i,(i+3) % 20); } return Graph; }
// Generate TNEGraph PNEGraph TriadGetTestTNEGraph() { PNEGraph Graph = TNEGraph::New(); for (int i = 0; i < 6; i++) { Graph->AddNode(i); } for (int i = 1; i < 6; i++) { for (int j = 0; j < i; j++) { Graph->AddEdge(0, i); } } Graph->AddEdge(2, 3); Graph->AddEdge(1, 5); Graph->AddEdge(2, 5); return Graph; }
// Test GetNodeTriads TEST(triad, TestGetNodeTriads) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); for (int i = 0; i < GraphTUN->GetNodes(); i++) { VerifyClosedTriads(i, TSnap::GetNodeTriads(GraphTUN, i)); } // TNGraph is not treated the same! Each directed will be counted PNGraph GraphTN = TriadGetTestTNGraph(); for (int i = 0; i < GraphTN->GetNodes(); i++) { VerifyClosedTriads(i, TSnap::GetNodeTriads(GraphTN, i)); } // TNEGraph is not treated the same! Be careful with multigraphs PNEGraph GraphTNE = TriadGetTestTNEGraph(); for (int i = 0; i < GraphTNE->GetNodes(); i++) { VerifyClosedTriads(i, TSnap::GetNodeTriads(GraphTNE, i)); } }
// Test edge subgraph conversion void TestConvertESubGraphs() { PNEGraph NEGraph; PNGraph NGraph; int N1, N2, N3; int E1, E2, E3; TIntV NIdV; TIntV EIdV; int i; NGraph = GetTestTNGraph(); N1 = NGraph->GetNodes(); E1 = NGraph->GetEdges(); for (i = 0; i < 20; i += 2) { NIdV.Add(i); } // TODO: fix TSnap::ConvertSubGraph<PUNGraph>(NGraph, NIdV, true), it fails // UNGraph = TSnap::ConvertSubGraph<PUNGraph>(NGraph, NIdV, true); NEGraph = TSnap::ConvertGraph<PNEGraph>(NGraph); N2 = NEGraph->GetNodes(); E2 = NEGraph->GetEdges(); // select every second edge i = 0; for (TNEGraph::TEdgeI EI = NEGraph->BegEI(); EI < NEGraph->EndEI(); EI++) { if (i == 0) { EIdV.Add(EI.GetId()); } i = (i + 1) % 2; } NGraph = TSnap::ConvertESubGraph<PNGraph>(NEGraph, EIdV); N3 = NGraph->GetNodes(); E3 = NGraph->GetEdges(); printf("---- TestConvertESubGraphs -----\n"); printf("nodes: %d,%d,%d, edges: %d,%d,%d\n", N1, N2, N3, E1, E2, E3); printf("\n"); }
// Test GetNodeTriads (GroupSet, InGroupEdges, InOutGroupEdges, OutGroupEdges) TEST(triad, TestGetNodeTriadsGroupSetAndOut) { // Test TUNGraph PUNGraph GraphTUN = TriadGetTestTUNGraph(); for (int i = 0; i < GraphTUN->GetNodes(); i++) { TIntSet GroupSet; GetGroupSet(i, GroupSet); int InGroupEdges = -1, InOutGroupEdges = -1, OutGroupEdges = -1; TSnap::GetNodeTriads(GraphTUN, i, GroupSet, InGroupEdges, InOutGroupEdges, OutGroupEdges); VerifyInGroupEdges(i, InGroupEdges); VerifyInOutGroupEdges(i, InOutGroupEdges); VerifyOutGroupEdges(i, OutGroupEdges); } // Test TNGraph which is same as undirected. PNGraph GraphTN = TriadGetTestTNGraph(); for (int i = 0; i < GraphTN->GetNodes(); i++) { TIntSet GroupSet; GetGroupSet(i, GroupSet); int InGroupEdges = -1, InOutGroupEdges = -1, OutGroupEdges = -1; TSnap::GetNodeTriads(GraphTN, i, GroupSet, InGroupEdges, InOutGroupEdges, OutGroupEdges); VerifyInGroupEdges(i, InGroupEdges); VerifyInOutGroupEdges(i, InOutGroupEdges); VerifyOutGroupEdges(i, OutGroupEdges); } // Test TNEGraph which is same as undirected. PNEGraph GraphTNE = TriadGetTestTNEGraph(); for (int i = 0; i < GraphTNE->GetNodes(); i++) { TIntSet GroupSet; GetGroupSet(i, GroupSet); int InGroupEdges = -1, InOutGroupEdges = -1, OutGroupEdges = -1; TSnap::GetNodeTriads(GraphTNE, i, GroupSet, InGroupEdges, InOutGroupEdges, OutGroupEdges); VerifyInGroupEdges(i, InGroupEdges); VerifyInOutGroupEdges(i, InOutGroupEdges); VerifyOutGroupEdges(i, OutGroupEdges); } }
// Return a small graph on 5 nodes and 6 edges. PNEGraph TNEGraph::GetSmallGraph() { PNEGraph Graph = TNEGraph::New(); for (int i = 0; i < 5; i++) { Graph->AddNode(i); } Graph->AddEdge(0,1); Graph->AddEdge(0,2); Graph->AddEdge(0,3); Graph->AddEdge(0,4); Graph->AddEdge(1,2); Graph->AddEdge(1,2); return Graph; }
// Test subgraphs TEST(subgraph, TestSubTNEGraphs) { PNEGraph Graph; PNEGraph Graph1; PNEGraph Graph2; PNEGraph Graph3; int i; TIntV NIdV; TIntV NIdV1; TIntV EIdV; Graph = GetTestTNEGraph(); EXPECT_EQ(20,Graph->GetNodes()); EXPECT_EQ(120,Graph->GetEdges()); for (i = 10; i < 15; i++) { NIdV.Add(i); } Graph1 = TSnap::GetSubGraph(Graph, NIdV); EXPECT_EQ(5,Graph1->GetNodes()); EXPECT_EQ(18,Graph1->GetEdges()); for (i = 0; i < 20; i += 2) { NIdV1.Add(i); } Graph2 = TSnap::GetSubGraph(Graph, NIdV1); EXPECT_EQ(10,Graph2->GetNodes()); EXPECT_EQ(20,Graph2->GetEdges()); for (i = 0; i < 120; i += 2) { EIdV.Add(i); } Graph3 = TSnap::GetESubGraph(Graph, EIdV); EXPECT_EQ(20,Graph3->GetNodes()); EXPECT_EQ(60,Graph3->GetEdges()); }
// Test the default constructor TEST(TNEGraph, DefaultConstructor) { PNEGraph Graph; Graph = TNEGraph::New(); EXPECT_EQ(0,Graph->GetNodes()); EXPECT_EQ(0,Graph->GetEdges()); EXPECT_EQ(1,Graph->IsOk()); EXPECT_EQ(1,Graph->Empty()); EXPECT_EQ(1,Graph->HasFlag(gfDirected)); }
// Test small graph TEST(TNEGraph, GetSmallGraph) { PNEGraph Graph; return; // not implemented //Graph = TNEGraph::GetSmallGraph(); EXPECT_EQ(5,Graph->GetNodes()); EXPECT_EQ(6,Graph->GetEdges()); EXPECT_EQ(1,Graph->IsOk()); EXPECT_EQ(0,Graph->Empty()); EXPECT_EQ(1,Graph->HasFlag(gfDirected)); }
int main(int argc, char* argv[]) { //// what type of graph do you want to use? typedef PUNGraph PGraph; // undirected graph //typedef PNGraph PGraph; // directed graph //typedef PNEGraph PGraph; // directed multigraph //typedef TPt<TNodeNet<TInt> > PGraph; //typedef TPt<TNodeEdgeNet<TInt, TInt> > PGraph; // this code is independent of what particular graph implementation/type we use printf("Creating graph:\n"); PGraph G = PGraph::TObj::New(); for (int n = 0; n < 10; n++) { G->AddNode(); // if no parameter is given, node ids are 0,1,...,9 } G->AddEdge(0, 1); for (int e = 0; e < 10; e++) { const int NId1 = G->GetRndNId(); const int NId2 = G->GetRndNId(); if (G->AddEdge(NId1, NId2) != -2) { printf(" Edge %d -- %d added\n", NId1, NId2); } else { printf(" Edge %d -- %d already exists\n", NId1, NId2); } } IAssert(G->IsOk()); //G->Dump(); // delete PGraph::TObj::TNodeI NI = G->GetNI(0); printf("Delete edge %d -- %d\n", NI.GetId(), NI.GetOutNId(0)); G->DelEdge(NI.GetId(), NI.GetOutNId(0)); const int RndNId = G->GetRndNId(); printf("Delete node %d\n", RndNId); G->DelNode(RndNId); IAssert(G->IsOk()); // dump the graph printf("Graph (%d, %d)\n", G->GetNodes(), G->GetEdges()); for (PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) { printf(" %d: ", NI.GetId()); for (int e = 0; e < NI.GetDeg(); e++) { printf(" %d", NI.GetNbrNId(e)); } printf("\n"); } // dump subgraph TIntV NIdV; for (PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) { if (NIdV.Len() < G->GetNodes()/2) { NIdV.Add(NI.GetId()); } } PGraph SubG = TSnap::GetSubGraph(G, NIdV); //SubG->Dump(); // get UNGraph { PUNGraph UNG = TSnap::ConvertGraph<PUNGraph>(SubG); UNG->Dump(); IAssert(UNG->IsOk()); TSnap::ConvertSubGraph<PNGraph>(G, NIdV)->Dump(); } // get NGraph { PNGraph NG = TSnap::ConvertGraph<PNGraph>(SubG); NG->Dump(); IAssert(NG->IsOk()); TSnap::ConvertSubGraph<PNGraph>(G, NIdV)->Dump(); } // get NEGraph { PNEGraph NEG = TSnap::ConvertGraph<PNEGraph>(SubG); NEG->Dump(); IAssert(NEG->IsOk()); TSnap::ConvertSubGraph<PNGraph>(G, NIdV)->Dump(); } TSnap::TestAnf<PUNGraph>(); return 0; }
// Test node, edge creation TEST(TNEGraph, ManipulateNodesEdges) { int NNodes = 1000; int NEdges = 100000; const char *FName = "test.graph"; PNEGraph Graph; PNEGraph Graph1; PNEGraph Graph2; int i; int n; int NCount; int x,y; int Deg, InDeg, OutDeg; Graph = TNEGraph::New(); EXPECT_EQ(1,Graph->Empty()); // create the nodes for (i = 0; i < NNodes; i++) { Graph->AddNode(i); } EXPECT_EQ(0,Graph->Empty()); EXPECT_EQ(NNodes,Graph->GetNodes()); // create random edges NCount = NEdges; while (NCount > 0) { x = (long) (drand48() * NNodes); y = (long) (drand48() * NNodes); n = Graph->AddEdge(x, y); NCount--; } EXPECT_EQ(NEdges,Graph->GetEdges()); EXPECT_EQ(0,Graph->Empty()); EXPECT_EQ(1,Graph->IsOk()); for (i = 0; i < NNodes; i++) { EXPECT_EQ(1,Graph->IsNode(i)); } EXPECT_EQ(0,Graph->IsNode(NNodes)); EXPECT_EQ(0,Graph->IsNode(NNodes+1)); EXPECT_EQ(0,Graph->IsNode(2*NNodes)); // nodes iterator NCount = 0; for (TNEGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) { NCount++; } EXPECT_EQ(NNodes,NCount); // edges per node iterator NCount = 0; for (TNEGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) { for (int e = 0; e < NI.GetOutDeg(); e++) { NCount++; } } EXPECT_EQ(NEdges,NCount); // edges iterator NCount = 0; for (TNEGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) { NCount++; } EXPECT_EQ(NEdges,NCount); // node degree for (TNEGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) { Deg = NI.GetDeg(); InDeg = NI.GetInDeg(); OutDeg = NI.GetOutDeg(); EXPECT_EQ(Deg,InDeg+OutDeg); } // assignment Graph1 = TNEGraph::New(); *Graph1 = *Graph; EXPECT_EQ(NNodes,Graph1->GetNodes()); EXPECT_EQ(NEdges,Graph1->GetEdges()); EXPECT_EQ(0,Graph1->Empty()); EXPECT_EQ(1,Graph1->IsOk()); // saving and loading { TFOut FOut(FName); Graph->Save(FOut); FOut.Flush(); } { TFIn FIn(FName); Graph2 = TNEGraph::Load(FIn); } EXPECT_EQ(NNodes,Graph2->GetNodes()); EXPECT_EQ(NEdges,Graph2->GetEdges()); EXPECT_EQ(0,Graph2->Empty()); EXPECT_EQ(1,Graph2->IsOk()); // remove all the nodes and edges for (i = 0; i < NNodes; i++) { n = Graph->GetRndNId(); Graph->DelNode(n); } EXPECT_EQ(0,Graph->GetNodes()); EXPECT_EQ(0,Graph->GetEdges()); EXPECT_EQ(1,Graph->IsOk()); EXPECT_EQ(1,Graph->Empty()); Graph1->Clr(); EXPECT_EQ(0,Graph1->GetNodes()); EXPECT_EQ(0,Graph1->GetEdges()); EXPECT_EQ(1,Graph1->IsOk()); EXPECT_EQ(1,Graph1->Empty()); }
int main(int argc, char* argv[]) { //// what type of graph do you want to use? //typedef PUNGraph PGraph; // undirected graph typedef PNGraph PGraph; // directed graph //typedef PNEGraph PGraph; // directed multigraph //typedef TPt<TNodeNet<TInt> > PGraph; //typedef TPt<TNodeEdgeNet<TInt, TInt> > PGraph; // this code is independent of what particular graph implementation/type we use printf("Creating graph:\n"); PGraph G = PGraph::TObj::New(); for (int n = 0; n < 15; n++) { G->AddNode(); // if no parameter is given, node ids are 0,1,...,9 } G->AddEdge(1, 4); printf(" Edge 1 -- 4 added\n"); G->AddEdge(1, 3); printf(" Edge 1 -- 3 added\n"); G->AddEdge(2, 5); printf(" Edge 2 -- 5 added\n"); G->AddEdge(3, 2); printf(" Edge 3 -- 2 added\n"); G->AddEdge(3, 5); printf(" Edge 3 -- 5 added\n"); G->AddEdge(3, 10); printf(" Edge 3 -- 10 added\n"); G->AddEdge(4, 5); printf(" Edge 4 -- 5 added\n"); G->AddEdge(4, 7); printf(" Edge 4 -- 7 added\n"); G->AddEdge(4, 8); printf(" Edge 4 -- 8 added\n"); G->AddEdge(5, 6); printf(" Edge 5 -- 6 added\n"); G->AddEdge(6, 13); printf(" Edge 6 -- 13 added\n"); G->AddEdge(7, 4); printf(" Edge 7 -- 4 added\n"); G->AddEdge(8, 7); printf(" Edge 8 -- 7 added\n"); G->AddEdge(8, 9); printf(" Edge 8 -- 9 added\n"); G->AddEdge(9, 10); printf(" Edge 9 -- 10 added\n"); G->AddEdge(9, 12); printf(" Edge 9 -- 12 added\n"); G->AddEdge(10, 3); printf(" Edge 10 -- 3 added\n"); G->AddEdge(10, 6); printf(" Edge 10 -- 6 added\n"); G->AddEdge(11, 12); printf(" Edge 11 -- 12 added\n"); G->AddEdge(12, 9); printf(" Edge 12 -- 9 added\n"); G->AddEdge(12, 11); printf(" Edge 12 -- 11 added\n"); G->AddEdge(12, 14); printf(" Edge 12 -- 14 added\n"); G->AddEdge(13, 14); printf(" Edge 13 -- 14 added\n"); G->AddEdge(14, 13); printf(" Edge 14 -- 13 added\n"); /*for (int e = 0; e < 10; e++) { const int NId1 = G->GetRndNId(); const int NId2 = G->GetRndNId(); if (G->AddEdge(NId1, NId2) != -2) { printf(" Edge %d -- %d added\n", NId1, NId2); } else { printf(" Edge %d -- %d already exists\n", NId1, NId2); } }*/ IAssert(G->IsOk()); //G->Dump(); // delete //PGraph::TObj::TNodeI NI = G->GetNI(0); //printf("Delete edge %d -- %d\n", NI.GetId(), NI.GetOutNId(0)); //G->DelEdge(NI.GetId(), NI.GetOutNId(0)); const int RndNId = G->GetRndNId(); printf("Delete node %d\n", RndNId); G->DelNode(RndNId); IAssert(G->IsOk()); // dump the graph printf("Graph (%d, %d)\n", G->GetNodes(), G->GetEdges()); for (PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) { printf(" %d: ", NI.GetId()); for (int e = 0; e < NI.GetDeg(); e++) { printf(" %d", NI.GetNbrNId(e)); } printf("\n"); } // dump subgraph TIntV NIdV; for (PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) { if (NIdV.Len() < G->GetNodes()/2) { NIdV.Add(NI.GetId()); } } PGraph SubG = TSnap::GetSubGraph(G, NIdV); //SubG->Dump(); // get NGraph { PNGraph NG = TSnap::ConvertGraph<PNGraph>(SubG); NG->Dump(); IAssert(NG->IsOk()); TSnap::ConvertSubGraph<PNGraph>(G, NIdV)->Dump(); } // get NEGraph { PNEGraph NEG = TSnap::ConvertGraph<PNEGraph>(SubG); NEG->Dump(); IAssert(NEG->IsOk()); TSnap::ConvertSubGraph<PNGraph>(G, NIdV)->Dump(); } TSnap::TestAnf<PUNGraph>(); return 0; }