本文整理汇总了C++中TPt::BegNI方法的典型用法代码示例。如果您正苦于以下问题:C++ TPt::BegNI方法的具体用法?C++ TPt::BegNI怎么用?C++ TPt::BegNI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TPt
的用法示例。
在下文中一共展示了TPt::BegNI方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
// Test update node data
TEST(TNodeEdgeNet, UpdateNodeData) {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(1,Net->Empty());
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i,i+5);
}
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(NNodes,Net->GetNodes());
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
n = Net->AddEdge(x, y);
NCount--;
}
EXPECT_EQ(NEdges,Net->GetEdges());
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(1,Net->IsOk());
for (i = 0; i < NNodes; i++) {
EXPECT_EQ(1,Net->IsNode(i));
}
EXPECT_EQ(0,Net->IsNode(NNodes));
EXPECT_EQ(0,Net->IsNode(NNodes+1));
EXPECT_EQ(0,Net->IsNode(2*NNodes));
// test node data
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ(NI.GetId()+5, Net->GetNDat(NI.GetId()));
}
// update node data, node ID + 10
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Net->SetNDat(NI.GetId(), NI.GetId()+10);
}
// test node data
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ(NI.GetId()+10, Net->GetNDat(NI.GetId()));
}
}
示例2: SetNodeData
// Test set node data
void SetNodeData() {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEDatNet<TInt, TInt> > Net;
TPt <TNodeEDatNet<TInt, TInt> > Net1;
TPt <TNodeEDatNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
bool t;
int NodeId;
int NodeDat;
int Value;
bool ok;
Net = TNodeEDatNet<TInt, TInt>::New();
t = Net->Empty();
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i);
}
t = Net->Empty();
n = Net->GetNodes();
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
// Net->GetEdges() is not correct for the loops (x == y),
// skip the loops in this test
if (x != y && !Net->IsEdge(x,y)) {
n = Net->AddEdge(x, y);
NCount--;
}
}
PrintNStats("SetNodeData:Net", Net);
// set node data, square of node ID
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NodeId = NI.GetId();
NodeDat = NI.GetId()*NI.GetId();
Net->SetNDat(NodeId, NodeDat);
}
// read and test node data
ok = true;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NodeDat = Net->GetNDat(NI.GetId());
Value = NI.GetId()*NI.GetId();
if (NodeDat != Value) {
ok = false;
}
}
printf("network SetNodeData:Net, status %s\n", (ok == true) ? "ok" : "ERROR");
}
示例3: MIOA
TPt<TNodeEDatNet<TFlt, TFlt>> GenerateDAG1(const TPt<TNodeEDatNet<TFlt, TFlt>> &pGraph, const std::vector<int>& seedNodes, double threshold)
{
// Copy pGraph into pGraph_DAG1
auto pGraph_DAG1 = TNodeEDatNet<TFlt, TFlt>::New();
for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
pGraph_DAG1->AddNode(NI.GetId());
for (auto EI = pGraph->BegEI(); EI < pGraph->EndEI(); EI++)
{
pGraph_DAG1->AddEdge(EI.GetSrcNId(),EI.GetDstNId());
pGraph_DAG1->SetEDat(EI.GetSrcNId(),EI.GetDstNId(), pGraph->GetEDat(EI.GetSrcNId(),EI.GetDstNId()));
}
// Create a super root in order to update in one pass all the shortest paths from vSeedIDs nodes
int superRootID = pGraph_DAG1->GetMxNId()+1;
pGraph_DAG1->AddNode(superRootID);
for(int srcNode: seedNodes)
{
pGraph_DAG1->AddEdge(superRootID, srcNode);
pGraph_DAG1->SetEDat(superRootID, srcNode, 1.0);
}
pGraph_DAG1 = MIOA(pGraph_DAG1, superRootID, threshold);
// Remove the artificial super root node
pGraph_DAG1->DelNode(superRootID);
// Add back other edges with the condition r(u)<r(v)
for (auto EI = pGraph->BegEI(); EI < pGraph->EndEI(); EI++)
{
int u = EI.GetSrcNId(), v = EI.GetDstNId();
if(pGraph_DAG1->GetNDat(u)< pGraph_DAG1->GetNDat(v))
{
if (!pGraph_DAG1->IsEdge(u,v))
{
pGraph_DAG1->AddEdge(u,v);
pGraph_DAG1->SetEDat(u,v,EI.GetDat());
}
}
}
//Reset Node data from the original graph
for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
pGraph_DAG1->SetNDat(NI.GetId(),NI.GetDat().Val);
return pGraph_DAG1;
}
示例4: RandomGraphInitialization
// before generating DAG
void RandomGraphInitialization(TPt<TNodeEDatNet<TFlt, TFlt>> &pGraph)
{
srand(time(NULL));
for (auto EI = pGraph->BegEI(); EI < pGraph->EndEI(); EI++)
pGraph->SetEDat(EI.GetSrcNId(), EI.GetDstNId(), (double) rand() / RAND_MAX);
for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
pGraph->SetNDat(NI.GetId(), 0.0);
}
示例5: vertexExists
bool vertexExists(TPt<TNodeEDatNet<TInt, TFlt> > & G, int id)
{
for (SnapNode NI = G->BegNI(); NI < G->EndNI(); NI++)
{
if(NI.GetDat() == id)
{
return true;
}
}
return false;
}
示例6: GraphUnion
//???????
TPt<TNodeEDatNet<TFlt, TFlt>> GenerateDAG2(const TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, const std::vector<int> &vSeedIDs, double dThreshold)
{
// Vector of MIOA graphs per seed node
std::vector<TPt<TNodeEDatNet<TFlt, TFlt>>> vMIOAGraphs;
// Compute the union of MIOA for each node of vSeedIDs
for(auto it=vSeedIDs.begin(); it!=vSeedIDs.end(); ++it)
vMIOAGraphs.push_back(MIOA(pGraph, *it, dThreshold));
auto pOut = GraphUnion(vMIOAGraphs);
// Set node data
for (auto NI = pOut->BegNI(); NI < pOut->EndNI(); NI++)
pOut->SetNDat(NI.GetId(), FLT_MAX);
// Copy the edge weights from pGraph
for (auto EI = pOut->BegEI(); EI < pOut->EndEI(); EI++)
pOut->SetEDat(EI.GetSrcNId(), EI.GetDstNId(), pGraph->GetEDat(EI.GetSrcNId(), EI.GetDstNId()));
// Create a super root in order to update in one pass all the shortest paths from vSeedIDs nodes
int superRootID = pGraph->GetMxNId()+1;
pOut->AddNode(superRootID);
for(auto it=vSeedIDs.begin(); it!=vSeedIDs.end(); ++it)
{
pOut->AddEdge(superRootID, *it);
pOut->SetEDat(superRootID, *it, 1.0);
}
Dijkstra(pOut, superRootID, dThreshold, pOut);
// Remove the artificial super root node
pOut->DelNode(superRootID);
// Traverse the edges and prune the graph
for (auto EI = pOut->BegEI(); EI < pOut->EndEI(); EI++)
{
if(EI.GetDstNDat().Val < EI.GetSrcNDat().Val)
pOut->DelEdge(EI.GetSrcNId(), EI.GetDstNId());
}
//Reset Node data from the original graph
for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
pOut->SetNDat(NI.GetId(),NI.GetDat().Val);
return pOut;
}
示例7:
// Test edge data sorting
TEST(TNodeEdgeNet, SortEdgeData) {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
int i;
int n;
int x,y;
bool Sorted;
int Min;
int Value;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(1,Net->Empty());
// create the nodes with node data x*x % NNodes
for (i = 0; i < NNodes; i++) {
x = (i*13) % NNodes;
Net->AddNode(x, (x*x) % NNodes);
}
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(NNodes,Net->GetNodes());
// create random edges with edge data x*y % NEdges
for (i = 0; i < NEdges; i++) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
n = Net->AddEdge(x, y, (i*37) % NEdges, (x*y) % NEdges);
}
EXPECT_EQ(NEdges,Net->GetEdges());
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(1,Net->IsOk());
for (i = 0; i < NNodes; i++) {
EXPECT_EQ(1,Net->IsNode(i));
}
EXPECT_EQ(0,Net->IsNode(NNodes));
EXPECT_EQ(0,Net->IsNode(NNodes+1));
EXPECT_EQ(0,Net->IsNode(2*NNodes));
// test node data
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ((NI.GetId()*NI.GetId()) % NNodes, Net->GetNDat(NI.GetId()));
}
// test edge data
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
EXPECT_EQ((EI.GetSrcNId()*EI.GetDstNId()) % NEdges, Net->GetEDat(EI.GetId()));
}
// test sorting of edge IDs (unsorted)
Min = -1;
Sorted = true;
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
Value = EI.GetId();
if (Min > Value) {
Sorted = false;
}
Min = Value;
}
EXPECT_EQ(false,Sorted);
// sort the nodes by edge IDs (sorted)
Net->SortEIdById();
// test sorting of edge IDs
Min = -1;
Sorted = true;
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
Value = EI.GetId();
if (Min > Value) {
Sorted = false;
}
Min = Value;
}
EXPECT_EQ(true,Sorted);
// test sorting of edge data (unsorted)
Min = -1;
Sorted = true;
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
Value = Net->GetEDat(EI.GetId());
if (Min > Value) {
Sorted = false;
}
Min = Value;
}
EXPECT_EQ(false,Sorted);
// sort the nodes by edge data
Net->SortEIdByDat();
// test sorting of edge data (sorted)
Min = -1;
//.........这里部分代码省略.........
示例8: FOut
// Test node, edge creation
TEST(TNodeEdgeNet, ManipulateNodesEdges) {
int NNodes = 10000;
int NEdges = 100000;
const char *FName = "test.net";
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
int Deg, InDeg, OutDeg;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(1,Net->Empty());
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i);
}
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(NNodes,Net->GetNodes());
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
n = Net->AddEdge(x, y);
NCount--;
}
EXPECT_EQ(NEdges,Net->GetEdges());
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(1,Net->IsOk());
for (i = 0; i < NNodes; i++) {
EXPECT_EQ(1,Net->IsNode(i));
}
EXPECT_EQ(0,Net->IsNode(NNodes));
EXPECT_EQ(0,Net->IsNode(NNodes+1));
EXPECT_EQ(0,Net->IsNode(2*NNodes));
// nodes iterator
NCount = 0;
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NCount++;
}
EXPECT_EQ(NNodes,NCount);
// edges per node iterator
NCount = 0;
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
for (int e = 0; e < NI.GetOutDeg(); e++) {
NCount++;
}
}
EXPECT_EQ(NEdges,NCount);
// edges iterator
NCount = 0;
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
NCount++;
}
EXPECT_EQ(NEdges,NCount);
// node degree
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Deg = NI.GetDeg();
InDeg = NI.GetInDeg();
OutDeg = NI.GetOutDeg();
EXPECT_EQ(Deg,InDeg+OutDeg);
}
// assignment
Net1 = TNodeEdgeNet<TInt, TInt>::New();
*Net1 = *Net;
EXPECT_EQ(NNodes,Net1->GetNodes());
EXPECT_EQ(NEdges,Net1->GetEdges());
EXPECT_EQ(0,Net1->Empty());
EXPECT_EQ(1,Net1->IsOk());
// saving and loading
{
TFOut FOut(FName);
Net->Save(FOut);
FOut.Flush();
}
{
TFIn FIn(FName);
Net2 = TNodeEdgeNet<TInt, TInt>::Load(FIn);
}
//.........这里部分代码省略.........
示例9: SortNodeData
// Test node data sorting
void SortNodeData() {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEDatNet<TInt, TInt> > Net;
TPt <TNodeEDatNet<TInt, TInt> > Net1;
TPt <TNodeEDatNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
bool t;
int NodeId;
int NodeDat;
bool ok;
bool Sorted;
int Min;
int Value;
Net = TNodeEDatNet<TInt, TInt>::New();
t = Net->Empty();
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode((i*13) % NNodes);
}
t = Net->Empty();
n = Net->GetNodes();
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
// Net->GetEdges() is not correct for the loops (x == y),
// skip the loops in this test
if (x != y && !Net->IsEdge(x,y)) {
n = Net->AddEdge(x, y);
NCount--;
}
}
PrintNStats("SortNodeData:Net", Net);
// add data to nodes, square of node ID % NNodes
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NodeId = NI.GetId();
NodeDat = (NI.GetId()*NI.GetId()) % NNodes;
Net->SetNDat(NodeId, NodeDat);
}
// test node data
ok = true;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NodeDat = Net->GetNDat(NI.GetId());
Value = (NI.GetId()*NI.GetId()) % NNodes;
if (NodeDat != Value) {
ok = false;
}
}
printf("network SortNodeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");
// test sorting of node IDs (unsorted)
Min = -1;
Sorted = true;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Value = NI.GetId();
if (Min > Value) {
Sorted = false;
}
Min = Value;
}
printf("network SortNodeData:Net, status2 %s\n", (Sorted == false) ? "ok" : "ERROR");
// sort the nodes by node IDs (sorted)
Net->SortNIdById();
// test sorting of node IDs
Min = -1;
Sorted = true;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Value = NI.GetId();
if (Min > Value) {
Sorted = false;
}
Min = Value;
}
printf("network SortNodeData:Net, status3 %s\n", (Sorted == true) ? "ok" : "ERROR");
// test sorting of node data (unsorted)
Min = -1;
Sorted = true;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Value = Net->GetNDat(NI.GetId());
if (Min > Value) {
Sorted = false;
}
Min = Value;
}
printf("network SortNodeData:Net, status4 %s\n", (Sorted == false) ? "ok" : "ERROR");
//.........这里部分代码省略.........
示例10: ManipulateNodesEdges
// Test node, edge creation
void ManipulateNodesEdges() {
int NNodes = 10000;
int NEdges = 100000;
const char *FName = "demo.net.dat";
TPt <TNodeEDatNet<TInt, TInt> > Net;
TPt <TNodeEDatNet<TInt, TInt> > Net1;
TPt <TNodeEDatNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int ECount1;
int ECount2;
int x,y;
bool t;
Net = TNodeEDatNet<TInt, TInt>::New();
t = Net->Empty();
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i);
}
t = Net->Empty();
n = Net->GetNodes();
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
// Net->GetEdges() is not correct for the loops (x == y),
// skip the loops in this test
if (x != y && !Net->IsEdge(x,y)) {
n = Net->AddEdge(x, y);
NCount--;
}
}
PrintNStats("ManipulateNodesEdges:Net", Net);
// get all the nodes
NCount = 0;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NCount++;
}
// get all the edges for all the nodes
ECount1 = 0;
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
for (int e = 0; e < NI.GetOutDeg(); e++) {
ECount1++;
}
}
// get all the edges directly
ECount2 = 0;
for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
ECount2++;
}
printf("network ManipulateNodesEdges:Net, nodes %d, edges1 %d, edges2 %d\n",
NCount, ECount1, ECount2);
// assignment
Net1 = TNodeEDatNet<TInt, TInt>::New();
*Net1 = *Net;
PrintNStats("ManipulateNodesEdges:Net1",Net1);
// save the network
{
TFOut FOut(FName);
Net->Save(FOut);
FOut.Flush();
}
// load the network
{
TFIn FIn(FName);
Net2 = TNodeEDatNet<TInt, TInt>::Load(FIn);
}
PrintNStats("ManipulateNodesEdges:Net2",Net2);
// remove all the nodes and edges
for (i = 0; i < NNodes; i++) {
n = Net->GetRndNId();
Net->DelNode(n);
}
PrintNStats("ManipulateNodesEdges:Net",Net);
Net1->Clr();
PrintNStats("ManipulateNodesEdges:Net1",Net1);
}
示例11: InitializationBeforePropagation
// before belief propagation
void InitializationBeforePropagation(TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph)
{
for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
pGraph->SetNDat(NI.GetId(), 0.0);
}