当前位置: 首页>>代码示例>>C++>>正文


C++ TPt::BegEI方法代码示例

本文整理汇总了C++中TPt::BegEI方法的典型用法代码示例。如果您正苦于以下问题:C++ TPt::BegEI方法的具体用法?C++ TPt::BegEI怎么用?C++ TPt::BegEI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TPt的用法示例。


在下文中一共展示了TPt::BegEI方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetTestTNodeEdgeNet

// Generate TNodeEdgeNet
TPt <TNodeEdgeNet<TInt, TInt> > GetTestTNodeEdgeNet() {
  TPt <TNodeEdgeNet<TInt, TInt> > Net;
  TPt <TNodeEdgeNet<TInt, TInt> > Net1;
  TPt <TNodeEdgeNet<TInt, TInt> > Net2;
  int n;

  Net = TNodeEdgeNet<TInt, TInt>::New();

  for (int i = 0; i < 20; i++) {
    Net->AddNode(i);
  }

  for (int i = 0; i < 20; i++) {
    Net->AddEdge(i,(i+1) % 20);
    Net->AddEdge(i,(i+2) % 20);
    Net->AddEdge(i,(i+3) % 20);
    Net->AddEdge(i,(i+1) % 20);
    Net->AddEdge(i,(i+2) % 20);
    Net->AddEdge(i,(i+3) % 20);
  }

  n = 0;
  for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    Net->SetEDat(EI.GetId(),n);
    n = (n+1) % 4;
  }

  return Net;
}
开发者ID:Accio,项目名称:snap,代码行数:30,代码来源:demo-subgraph.cpp

示例2: MakeSignEpinions

void MakeSignEpinions() {
  TSsParser Ss("/u/ana/data/EpinionRatings/user_rating.txt", ssfTabSep);
  //PSignNet Net = TSignNet::New();
  TPt<TNodeEDatNet<TInt, TInt> >  Net = TNodeEDatNet<TInt, TInt>::New();
  TStrHash<TInt> StrSet(Mega(1), true);
      
  while (Ss.Next()) {
    if ( ((TStr)Ss[0]).IsPrefix("#")  )
      continue;
    const int SrcNId = StrSet.AddKey(Ss[0]);
    const int DstNId = StrSet.AddKey(Ss[1]);
    if (! Net->IsNode(SrcNId)) { Net->AddNode(SrcNId); }
    if (! Net->IsNode(DstNId)) { Net->AddNode(DstNId); }
    const int Sign = ((TStr)Ss[2]).GetInt();
    Net->AddEdge(SrcNId, DstNId, Sign);
  }
    
  //    PrintGraphStatTable(Graph, OutFNm, Desc);
  TStr OutFNm = "soc-sign-epinions-user-ratings";
  TStr Desc = "Epinions signed social network";

  // copied from gio.h - line 111
  FILE *F = fopen(OutFNm.CStr(), "wt");
  fprintf(F, "# Directed graph: %s\n", OutFNm.CStr());
  if (! Desc.Empty()) 
    fprintf(F, "# %s\n", (Desc).CStr());
  fprintf(F, "# Nodes: %d Edges: %d\n", Net->GetNodes(), Net->GetEdges());
  fprintf(F, "# FromNodeId\tToNodeId\tSign\n"); 
  for (TNodeEDatNet<TInt,TInt>::TEdgeI ei = Net->BegEI(); ei < Net->EndEI(); ei++) {
      fprintf(F, "%d\t%d\t%d\n", ei.GetSrcNId(), ei.GetDstNId(), ei()());
  }
  fclose(F);
  
  PrintGraphStatTable(Net, OutFNm, Desc);
}
开发者ID:SherlockYang,项目名称:Archive,代码行数:35,代码来源:mkdatasets.cpp

示例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;
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:47,代码来源:Utilities.cpp

示例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);
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:9,代码来源:Utilities.cpp

示例5: edgeExists

bool edgeExists(TPt<TNodeEDatNet<TInt, TFlt> >  & G, int id1, int id2, TFlt weight)
{
    for (SnapEdge EI = G->BegEI(); EI < G->EndEI(); EI++)
    {
        if(EI.GetDstNDat() == id2 && EI.GetSrcNDat() == id1 && EI.GetDat() == weight)
            return true;
    }
    return false;
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:9,代码来源:testgraph.cpp

示例6: MakeSlashdotSignNet

void MakeSlashdotSignNet(const TStr InFNm, TStr OutFNm, TStr Desc, THashSet<TChA> NIdSet) {
  //THashSet<TChA> NIdSet;
  TChA LnStr;
  TVec<char *> WrdV;
  int Sign;
  //PSignNet Net = TSignNet::New();
  TPt<TNodeEDatNet<TInt, TInt> >  Net = TNodeEDatNet<TInt, TInt>::New();
  int i = 0;
  for (TFIn FIn(InFNm); FIn.GetNextLn(LnStr); ) {
    if (LnStr.Empty() || LnStr[0]=='#') { continue; }
    LnStr.ToLc();
    TStrUtil::SplitOnCh(LnStr, WrdV, '\t', false);
    //NIdSet.AddKey(WrdV[0]);
    if (strcmp(WrdV[1], "friends")==0) { Sign = 1; }
    else if (strcmp(WrdV[1], "fans")==0) { continue; } // skip (fans are in-friends)
    else if (strcmp(WrdV[1], "foes")==0) { Sign = -1; } else { Fail; }
    const int SrcNId = NIdSet.AddKey(WrdV[0]);
    if (! Net->IsNode(SrcNId)) {
      Net->AddNode(SrcNId); }   
    for (int e = 2; e < WrdV.Len(); e++) {
      const int DstNId = NIdSet.AddKey(WrdV[e]);
      i ++ ;
      if ((SrcNId != DstNId) && ! Net->IsEdge(SrcNId, DstNId)) {
        if (! Net->IsNode(DstNId))
          Net->AddNode(DstNId);
        Net->AddEdge(SrcNId, DstNId, Sign);
      }
    }  
  }  
  TSnap::PrintInfo(Net, "Slashdot (" + TInt::GetStr(i) + ")");  

  // copied from gio.h - line 111
  FILE *F = fopen(OutFNm.CStr(), "wt");
  fprintf(F, "# Directed graph: %s\n", OutFNm.CStr());
  if (! Desc.Empty()) 
    fprintf(F, "# %s\n", (Desc).CStr());
    fprintf(F, "# Nodes: %d Edges: %d\n", Net->GetNodes(), Net->GetEdges());
    fprintf(F, "# UserId\tGroupId\tSign\n"); 
  for (TNodeEDatNet<TInt,TInt>::TEdgeI ei = Net->BegEI(); ei < Net->EndEI(); ei++) {
      fprintf(F, "%d\t%d\t%d\n", ei.GetSrcNId(), ei.GetDstNId(), ei()());
  }
  fclose(F);
  
  PrintGraphStatTable(Net, OutFNm, Desc);
}
开发者ID:SherlockYang,项目名称:Archive,代码行数:45,代码来源:mkdatasets.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:Aleyasen,项目名称:Alaki,代码行数:101,代码来源:test-TNodeEdgeNet.cpp

示例8: while

// Test update edge data
TEST(TNodeEdgeNet, UpdateEdgeData) {
  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);
  }
  EXPECT_EQ(0,Net->Empty());
  EXPECT_EQ(NNodes,Net->GetNodes());

  // create random edges and edge data x+y+10
  NCount = NEdges;
  while (NCount > 0) {
    x = (long) (drand48() * NNodes);
    y = (long) (drand48() * NNodes);
    n = Net->AddEdge(x, y, -1, x+y+10);
    // printf("0a %d %d %d\n",x,y,n);
    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));

  // add data to nodes, square of node ID
  for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    Net->SetNDat(NI.GetId(), NI.GetId()*NI.GetId());
  }

  // test node data
  for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    EXPECT_EQ(NI.GetId()*NI.GetId(), Net->GetNDat(NI.GetId()));
  }

  // verify edge data, x+y+10
  for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    EXPECT_EQ(EI.GetSrcNId()+EI.GetDstNId()+10, Net->GetEDat(EI.GetId()));
  }

  // update edge data, x+y+5
  for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    Net->SetEDat(EI.GetId(),EI.GetSrcNId()+EI.GetDstNId()+5);
  }

  // verify edge data, x+y+5
  for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    EXPECT_EQ(EI.GetSrcNId()+EI.GetDstNId()+5, Net->GetEDat(EI.GetId()));
  }

  // test node data again
  for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    EXPECT_EQ(NI.GetId()*NI.GetId(), Net->GetNDat(NI.GetId()));
  }
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:76,代码来源:test-TNodeEdgeNet.cpp

示例9: 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);
  }

//.........这里部分代码省略.........
开发者ID:Aleyasen,项目名称:Alaki,代码行数:101,代码来源:test-TNodeEdgeNet.cpp

示例10: UpdateEdgeData

// Test update edge data
void UpdateEdgeData() {
  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 SrcNId;
  int DstNId;
  int EdgeDat;
  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 and edge data x+y+10
  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, x+y+10);
      NCount--;
    }
  }
  PrintNStats("UpdateEdgeData:Net", Net);

  // verify edge data, x+y+10
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    SrcNId = EI.GetSrcNId();
    DstNId = EI.GetDstNId();
    EdgeDat = Net->GetEDat(SrcNId, DstNId);
    Value = SrcNId+DstNId+10;
    if (EdgeDat != Value) {
      ok = false;
    }
  }
  printf("network UpdateEdgeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");

  // update edge data, x+y+5
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    Net->SetEDat(EI.GetSrcNId(),EI.GetDstNId(),EI.GetSrcNId()+EI.GetDstNId()+5);
  }

  // verify edge data, x+y+5
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    SrcNId = EI.GetSrcNId();
    DstNId = EI.GetDstNId();
    EdgeDat = Net->GetEDat(SrcNId, DstNId);
    Value = SrcNId+DstNId+5;
    if (EdgeDat != Value) {
      ok = false;
    }
  }
  printf("network UpdateEdgeData:Net, status2 %s\n", (ok == true) ? "ok" : "ERROR");
}
开发者ID:Accio,项目名称:snap,代码行数:74,代码来源:demo-TNodeEDatNet.cpp

示例11: 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);
}
开发者ID:Accio,项目名称:snap,代码行数:92,代码来源:demo-TNodeEDatNet.cpp


注:本文中的TPt::BegEI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。