本文整理汇总了C++中PNEGraph::GetNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ PNEGraph::GetNodes方法的具体用法?C++ PNEGraph::GetNodes怎么用?C++ PNEGraph::GetNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PNEGraph
的用法示例。
在下文中一共展示了PNEGraph::GetNodes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TriadGetTestTUNGraph
// 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));
}
}
}
示例2: Add
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));
}
示例3: GetTestTNGraph
// 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());
}
示例4:
// 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));
}
示例5: TestConvertESubGraphs
// 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");
}
示例6: GetTestTNEGraph
// 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());
}
示例7: FOut
// 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);
}
//.........这里部分代码省略.........