本文整理汇总了C++中PUNGraph::IsOk方法的典型用法代码示例。如果您正苦于以下问题:C++ PUNGraph::IsOk方法的具体用法?C++ PUNGraph::IsOk怎么用?C++ PUNGraph::IsOk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PUNGraph
的用法示例。
在下文中一共展示了PUNGraph::IsOk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Test the default constructor
TEST(TUNGraph, DefaultConstructor) {
PUNGraph Graph;
Graph = TUNGraph::New();
EXPECT_EQ(0,Graph->GetNodes());
EXPECT_EQ(0,Graph->GetEdges());
EXPECT_EQ(1,Graph->IsOk());
EXPECT_EQ(1,Graph->Empty());
EXPECT_EQ(0,Graph->HasFlag(gfDirected));
}
示例2: main
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 < 14; 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");
/*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;
}
示例3: FOut
// Test node, edge creation
TEST(TUNGraph, ManipulateNodesEdges) {
int NNodes = 10000;
int NEdges = 100000;
const char *FName = "test.graph";
PUNGraph Graph;
PUNGraph Graph1;
PUNGraph Graph2;
int i;
int n;
int NCount;
int x,y;
int Deg, InDeg, OutDeg;
Graph = TUNGraph::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);
// Graph->GetEdges() is not correct for the loops (x == y),
// skip the loops in this test
if (x != y && !Graph->IsEdge(x,y)) {
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 (TUNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
NCount++;
}
EXPECT_EQ(NNodes,NCount);
// edges per node iterator
NCount = 0;
for (TUNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
for (int e = 0; e < NI.GetOutDeg(); e++) {
NCount++;
}
}
EXPECT_EQ(NEdges*2,NCount);
// edges iterator
NCount = 0;
for (TUNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
NCount++;
}
EXPECT_EQ(NEdges,NCount);
// node degree
for (TUNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
Deg = NI.GetDeg();
InDeg = NI.GetInDeg();
OutDeg = NI.GetOutDeg();
EXPECT_EQ(Deg,InDeg);
EXPECT_EQ(Deg,OutDeg);
}
// assignment
Graph1 = TUNGraph::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();
}
//.........这里部分代码省略.........