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


C++ PNEANet::AddEdge方法代码示例

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


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

示例1: StrAttr

// Test node, edge attribute functionality
TEST(TNEANet, AddEdgeNodeAfterAttrAdded) {
  PNEANet Graph;
  Graph = TNEANet::New();

  TStr StrAttr("name");
  TStr EIntAttr("weight");
  TStr NIntAttr("test");

  Graph->AddStrAttrN(StrAttr);
  Graph->AddIntAttrN(NIntAttr);
  Graph->AddIntAttrE(EIntAttr);

  Graph->AddNode(0);
  Graph->AddNode(1);
  Graph->AddNode(2);

  Graph->AddStrAttrDatN(0, "zero", StrAttr);
  Graph->AddStrAttrDatN(1, "one", StrAttr);
  Graph->AddStrAttrDatN(2, "two", StrAttr);

  Graph->AddEdge(0, 1);
  Graph->AddEdge(1, 2);
  Graph->AddEdge(2, 0);

  for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    Graph->AddIntAttrDatE(EI.GetId(), EI.GetId()*3+1, EIntAttr);
  }

  for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    TInt AttrVal = Graph->GetIntAttrDatE(EI.GetId(), EIntAttr);
    ASSERT_EQ(EI.GetId()*3+1, AttrVal);
  }
}
开发者ID:IsmaelAli,项目名称:snap,代码行数:34,代码来源:test-TNEANet.cpp

示例2: GetSmallGraph

// Return a small graph on 5 nodes and 6 edges.
PNEANet TNEANet::GetSmallGraph() {
  PNEANet Net = TNEANet::New();
  for (int i = 0; i < 5; i++) { Net->AddNode(i); }
  Net->AddEdge(0,1);  Net->AddEdge(0,2);
  Net->AddEdge(0,3);  Net->AddEdge(0,4);
  Net->AddEdge(1,2);  Net->AddEdge(1,2);
  return Net;
}
开发者ID:Daron-Wan,项目名称:snap,代码行数:9,代码来源:network.cpp

示例3: Val

TEST(TNEANet, AddSAttrDatE_flt) {
  PNEANet Graph;
  Graph = TNEANet::New();
  Graph->AddNode(0);
  Graph->AddNode(1);
  Graph->AddEdge(0, 1, 0);
  TFlt Val(5.0);
  TInt Id(0);
  int status = Graph->AddSAttrDatE(Id, 1, Val);
  EXPECT_EQ(-1, status);
  TInt AttrId;
  TStr AttrName("TestFlt");
  Graph->AddSAttrE(AttrName, atFlt, AttrId);
  TInt ErrorVal(1);
  status = Graph->AddSAttrDatE(Id, AttrId, ErrorVal);
  EXPECT_EQ(-2, status);
  status = Graph->AddSAttrDatE(Id, AttrId, Val);
  EXPECT_EQ(0, status);
  status = Graph->AddSAttrDatE(Id, AttrName, Val);
  EXPECT_EQ(0, status);
  TStr NewName("TestFlt2");
  status = Graph->AddSAttrDatE(Id, NewName, Val);
  EXPECT_EQ(0, status);
  TInt ErrorId(1);
  status = Graph->AddSAttrDatE(ErrorId, AttrId, Val);
  EXPECT_EQ(-1, status);
}
开发者ID:IsmaelAli,项目名称:snap,代码行数:27,代码来源:test-TNEANet.cpp

示例4: AttrId

TEST(TNEANet, GetSAttrDatE_str) {
  PNEANet Graph;
  Graph = TNEANet::New();
  Graph->AddNode(0);
  Graph->AddNode(1);
  Graph->AddEdge(0, 1, 0);
  TStr Val;
  TInt AttrId(0);
  TStr AttrName("TestInt");
  TInt EId(0);
  int status = Graph->GetSAttrDatE(EId, AttrName, Val);
  EXPECT_EQ(-1, status);
  status = Graph->GetSAttrDatE(EId, AttrId, Val);
  EXPECT_EQ(-1, status);
  Graph->AddSAttrE(AttrName, atStr, AttrId);
  TStr TestVal("5");
  Graph->AddSAttrDatE(EId, AttrId, TestVal);
  status = Graph->GetSAttrDatE(EId, AttrId, Val);
  EXPECT_EQ(0, status);
  EXPECT_STREQ(TestVal.CStr(), Val.CStr());
  status = Graph->GetSAttrDatE(EId, AttrName, Val);
  EXPECT_EQ(0, status);
  EXPECT_STREQ(TestVal.CStr(), Val.CStr());
  TInt ErrorId(1);
  status = Graph->GetSAttrDatE(ErrorId, AttrId, Val);
  EXPECT_EQ(-1, status);
}
开发者ID:IsmaelAli,项目名称:snap,代码行数:27,代码来源:test-TNEANet.cpp

示例5: IntAttr

TEST(TNEANet, DelSAttrDatE) {
  PNEANet Graph;
  Graph = TNEANet::New();
  Graph->AddNode(0);
  Graph->AddNode(1);
  Graph->AddEdge(0, 1, 0);
  TStr IntAttr("TestInt");
  TInt IntId;
  Graph->AddSAttrE(IntAttr, atInt, IntId);
  TStr FltAttr("TestFlt");
  TInt FltId;
  Graph->AddSAttrE(FltAttr, atFlt, FltId);
  TStr StrAttr("TestStr");
  TInt StrId;
  Graph->AddSAttrE(StrAttr, atStr, StrId);
  TInt Id(0);
  int status = Graph->DelSAttrDatE(Id, IntAttr);
  EXPECT_EQ(-1, status);
  status = Graph->DelSAttrDatE(Id, IntId);
  EXPECT_EQ(-1, status);

  TInt IntVal(5);
  Graph->AddSAttrDatE(Id, IntId, IntVal);
  status = Graph->DelSAttrDatE(Id, IntAttr);
  EXPECT_EQ(0, status);
  Graph->AddSAttrDatE(Id, IntId, IntVal);
  status = Graph->DelSAttrDatE(Id, IntId);
  EXPECT_EQ(0, status);
  status = Graph->DelSAttrDatE(Id, IntId);
  EXPECT_EQ(-1, status);
  TInt ErrorId(1);
  status = Graph->DelSAttrDatE(ErrorId, IntId);
  EXPECT_EQ(-1, status);

  TFlt FltVal(5.0);
  Graph->AddSAttrDatE(Id, FltId, FltVal);
  status = Graph->DelSAttrDatE(Id, FltAttr);
  EXPECT_EQ(0, status);
  Graph->AddSAttrDatE(Id, FltId, FltVal);
  status = Graph->DelSAttrDatE(Id, FltId);
  EXPECT_EQ(0, status);
  status = Graph->DelSAttrDatE(Id, FltId);
  EXPECT_EQ(-1, status);
  status = Graph->DelSAttrDatE(ErrorId, FltId);
  EXPECT_EQ(-1, status);

  TStr StrVal("5");
  Graph->AddSAttrDatE(Id, StrId, StrVal);
  status = Graph->DelSAttrDatE(Id, StrAttr);
  EXPECT_EQ(0, status);
  Graph->AddSAttrDatE(Id, StrId, StrVal);
  status = Graph->DelSAttrDatE(Id, StrId);
  EXPECT_EQ(0, status);
  status = Graph->DelSAttrDatE(Id, StrId);
  EXPECT_EQ(-1, status);
  status = Graph->DelSAttrDatE(ErrorId, StrId);
  EXPECT_EQ(-1, status);
}
开发者ID:IsmaelAli,项目名称:snap,代码行数:58,代码来源:test-TNEANet.cpp

示例6: TestAttr

TEST(TNEANet, IntVAttr) {
  PNEANet Graph;
  Graph = TNEANet::New();
  int i;
  TIntV test;
  int numNodes = 10;
  Graph->AddNode(0);
  for (i = 1; i < numNodes; i++) {
    Graph->AddNode(i);
    Graph->AddEdge(i-1, i);
  }
  TStr TestAttr("Test1");
  Graph->AddIntVAttrN(TestAttr);
  for (i = 0; i < numNodes; i++) {
    test = Graph->GetIntVAttrDatN(i, TestAttr);
    EXPECT_EQ(0, test.Len());
  }

  TIntV testVB;
  for (i = 0; i < numNodes; i++) {
    testVB.Add(i);
  }
  const TIntV testV = testVB;
  Graph->AddIntVAttrDatN(0, testV, TestAttr);
  test = Graph->GetIntVAttrDatN(0, TestAttr);
  EXPECT_EQ(numNodes, test.Len());

  for (i = 0; i < numNodes; i++) {
    EXPECT_EQ(test[i], i);
  }

  Graph->AppendIntVAttrDatN(0, numNodes, TestAttr);
  test = Graph->GetIntVAttrDatN(0, TestAttr);
  EXPECT_EQ(numNodes+1, test.Len());
  for (i = 0; i < numNodes+1; i++) {
    EXPECT_EQ(test[i], i);
  }

  Graph->DelAttrDatN(0, TestAttr);
  for (i = 0; i < numNodes; i++) {
    test = Graph->GetIntVAttrDatN(i, TestAttr);
    EXPECT_EQ(0, test.Len());
  }

}
开发者ID:JohnMatta,项目名称:snap,代码行数:45,代码来源:test-TNEANet.cpp

示例7: BuildCapacityNetwork

int BuildCapacityNetwork(const TStr& InFNm, PNEANet &Net, const int& SrcColId = 0, const int& DstColId = 1, const int& CapColId = 2) {
  TSsParser Ss(InFNm, ssfWhiteSep, true, true, true);
  TRnd Random;
  Net.Clr();
  Net = TNEANet::New();
  int SrcNId, DstNId, CapVal, EId;
  int MaxCap = 0;
  while (Ss.Next()) {
    if (! Ss.GetInt(SrcColId, SrcNId) || ! Ss.GetInt(DstColId, DstNId)) { continue; }
    Ss.GetInt(CapColId, CapVal);
    //CapVal = Random.GetUniDevInt(1, 10000);
    MaxCap = max(CapVal, MaxCap);
    if (! Net->IsNode(SrcNId)) {
      Net->AddNode(SrcNId);
    }
    if (! Net->IsNode(DstNId)) {
      Net->AddNode(DstNId);
    }
    EId = Net->AddEdge(SrcNId, DstNId);
    Net->AddIntAttrDatE(EId, CapVal, TSnap::CapAttrName);
  }
  Net->Defrag();
  return MaxCap;
}
开发者ID:hdravna,项目名称:CommDet,代码行数:24,代码来源:flows.cpp

示例8: KNNJaccardParallel

PNEANet KNNJaccardParallel(PNGraph Graph,int K) {
  PNEANet KNN = TNEANet::New();
  TIntV NIdV;
  Graph->GetNIdV (NIdV);
  int size = NIdV.Len();
  for (int ind = 0; ind < size; ind++) {
    KNN->AddNode(NIdV[ind]);
  }
  KNN->AddFltAttrE("sim");
  TVec<TVec<TPair<TFlt, TInt>, int >, int > TopKList;
  TVec<TVec<TPair<TFlt, TInt>, int >, int > ThTopK; // for each thread
  TIntV NodeList;
  TIntV ThNodeList;// for each thread
  int NumThreads = omp_get_max_threads();
  omp_set_num_threads(NumThreads);
  #pragma omp parallel private(ThNodeList, ThTopK)
  {
    TIntV* Neighbors_old = new TIntV();
    TIntV* Neighbors = new TIntV();
    TIntV* temp;

    #pragma omp for schedule(dynamic,1000)
    for (int ind = 0; ind < size; ind++) {
      TNGraph::TNodeI NI = Graph->GetNI(NIdV[ind]);
      if (NI.GetInDeg() > 0) {
        continue;
      }
      if (NI.GetOutDeg() == 0) {
        continue;
      }

      TVec<TPair<TFlt, TInt>, int > TopK;
      for (int i = 0; i < K; i++) {
          TopK.Add(TPair<TFlt,TInt>(0.0, -1));
      }

      Neighbors->Clr(false);
      Neighbors_old->Clr(false);

      for (int i = 0; i < NI.GetOutDeg(); i++) {
        TNGraph::TNodeI Inst_NI = Graph->GetNI(NI.GetOutNId(i));
        MergeNbrs(Neighbors, Neighbors_old, Inst_NI);

        temp = Neighbors_old;
        temp->Clr(false);
        Neighbors_old = Neighbors;
        Neighbors = temp;
      }

      // Swap neighbors and Neighbors_old

      temp = Neighbors_old;
      Neighbors_old = Neighbors;
      Neighbors = temp;
      for(int j = 0; j< Neighbors->Len(); j++) {

        TNGraph::TNodeI Auth_NI = Graph->GetNI((*Neighbors)[j]);

        float similarity = JaccardSim(NI, Auth_NI);
        if (TopK[K-1].GetVal1() < similarity) {
          int index = 0;
          for (int i = K-2; i >= 0; i--)
            if (TopK[i].GetVal1() < similarity) {
              TopK.SetVal(i+1, TopK[i]);
            } else {
              index = i+1;
              break;
            }
          TopK.SetVal(index, TPair<TFlt, TInt>(similarity, (*Neighbors)[j]));
        }
      }

      ThTopK.Add(TopK);
      ThNodeList.Add(NIdV[ind]);

//    if (ct%10000 == 0)
//    	cout<<ct<<" avg neighbor degree = "<<sum_neighbors*1.0/ct<<" "<<currentDateTime()<<endl;

    }
    #pragma omp critical
    {
      for (int j = 0; j < ThTopK.Len(); j++) {
        TopKList.Add(ThTopK[j]);
        NodeList.Add(ThNodeList[j]);
      }
    }
	}

  int size2 = NodeList.Len();
  for (int i= 0; i < size2 ; i++) {

    for (int j = 0; j < K; j++) {
      if (TopKList[i][j].GetVal2() <= -1) {
        break;
      }
      int EId = KNN->AddEdge(NodeList[i], TopKList[i][j].GetVal2());
      KNN->AddFltAttrDatE(EId, TopKList[i][j].GetVal1(), "sim");
    }
  }
  return KNN;
//.........这里部分代码省略.........
开发者ID:vid-koci,项目名称:snap,代码行数:101,代码来源:sim.cpp

示例9: KNNJaccard

PNEANet KNNJaccard(PNGraph Graph, int K) {
  PNEANet KNN = TNEANet::New();

  int sum_neighbors = 0;
  int ct;
  int end;
  end = Graph->GetNodes();
  TIntV* Neighbors_old = new TIntV();
  TIntV* Neighbors = new TIntV();
  TIntV* temp;
  TIntV NIdV;
  Graph->GetNIdV (NIdV);
  int size = NIdV.Len();
  for (int ind = 0; ind < size; ind++) {
    KNN->AddNode(NIdV[ind]);
  }
  KNN->AddFltAttrE("sim");

  for (int ind = 0; ind < size; ind++) {
    TNGraph::TNodeI NI = Graph->GetNI(NIdV[ind]);
    if (NI.GetInDeg() > 0) {
      continue;
    }
    if (NI.GetOutDeg() == 0) {
      continue;
    }
    ct ++;

    TVec<TPair<TFlt, TInt> > TopK;
    for (int i = 0; i < K; i++) {
      TopK.Add(TPair<TFlt,TInt>(0.0, -1));
    }

    Neighbors->Clr(false);
    Neighbors_old->Clr(false);

    for (int i = 0; i < NI.GetOutDeg(); i++) {
      TNGraph::TNodeI Inst_NI = Graph->GetNI(NI.GetOutNId(i));
      MergeNbrs(Neighbors, Neighbors_old, Inst_NI);

      temp = Neighbors_old;
      temp->Clr(false);
      Neighbors_old = Neighbors;
      Neighbors = temp;
    }
    int num = Neighbors_old->Len();
    sum_neighbors += num;

    //Swap neighbors and Neighbors_old

    temp = Neighbors_old;
    Neighbors_old = Neighbors;
    Neighbors = temp;
    for (int j = 0; j< Neighbors->Len(); j++) {

      TNGraph::TNodeI Auth_NI = Graph->GetNI((*Neighbors)[j]);

      float similarity = JaccardSim(NI, Auth_NI);
      if (TopK[K-1].GetVal1() < similarity) {
        int index = 0;
        for (int i = K-2; i >= 0; i--)
          if (TopK[i].GetVal1() < similarity) {
            TopK.SetVal(i+1, TopK[i]);
          } else {
            index = i+1;
            break;
          }
        TopK.SetVal(index, TPair<TFlt, TInt>(similarity, (*Neighbors)[j]));
      }
    }

    for (int i = 0; i < K; i++) {
      int EId = KNN->AddEdge(NI.GetId(), TopK[i].GetVal2());
      KNN->AddFltAttrDatE(EId, TopK[i].GetVal1(), "sim");
    }

//    if (ct%10000 == 0)
//    	cout<<ct<<" avg neighbor degree = "<<sum_neighbors*1.0/ct<<" "<<currentDateTime()<<endl;

  }

  return KNN;
}
开发者ID:vid-koci,项目名称:snap,代码行数:83,代码来源:sim.cpp

示例10: FOut

// Test node, edge creation
TEST(TNEANet, ManipulateNodesEdges) {
  int NNodes = 1000;
  int NEdges = 100000;
  const char *FName = "test.graph.dat";

  PNEANet Graph;
  PNEANet Graph1;
  PNEANet Graph2;
  int i;
  int n;
  int NCount;
  int x,y;
  int Deg, InDeg, OutDeg;

  Graph = TNEANet::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 (TNEANet::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    NCount++;
  }
  EXPECT_EQ(NNodes,NCount);

  // edges per node iterator
  NCount = 0;
  for (TNEANet::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 (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    NCount++;
  }
  EXPECT_EQ(NEdges,NCount);

  // node degree
  for (TNEANet::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    Deg = NI.GetDeg();
    InDeg = NI.GetInDeg();
    OutDeg = NI.GetOutDeg();

    EXPECT_EQ(Deg,InDeg+OutDeg);
  }

  // assignment
  Graph1 = TNEANet::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 = TNEANet::Load(FIn);
  }

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

示例11: ManipulateNodeEdgeAttributes

// Test node attribute functionality
void ManipulateNodeEdgeAttributes() {
  int NNodes = 1000;
  int NEdges = 1000;
  const char *FName = "demo.graph.dat";

  PNEANet Graph;
  PNEANet Graph1;
  int i;
  int x, y;
  bool t;

  Graph = TNEANet::New();
  t = Graph->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Graph->AddNode(i);
  }

  // create the edges 
  for (i = 0; i < NEdges; i++) {
    x = rand() % NNodes;
    y = rand() % NNodes;
    Graph->AddEdge(x, y, i);
  }

  // create attributes and fill all nodes
  TStr attr1 = "str";
  TStr attr2 = "int";
  TStr attr3 = "float";
  TStr attr4 = "default";

  // Test vertical int iterator for node 3, 50, 700, 900
  // Check if we can set defaults to 0 for Int data.
  Graph->AddIntAttrN(attr2, 0);
  Graph->AddIntAttrDatN(3, 3*2, attr2);
  Graph->AddIntAttrDatN(50, 50*2, attr2);
  Graph->AddIntAttrDatN(700, 700*2, attr2);
  Graph->AddIntAttrDatN(900, 900*2, attr2);
  int NodeId = 0;
  for (TNEANet::TAIntI NI = Graph->BegNAIntI(attr2);
    NI < Graph->EndNAIntI(attr2); NI++) {
    // Check if defaults are now 0.
    if (NI.GetDat()() != 0) {
      printf("Attribute: %s, Node: %i, Val: %i\n", attr2(), NodeId, NI.GetDat()());
      NodeId++;
    }
  } 

  // Test vertical flt iterator for node 3, 50, 700, 900
  Graph->AddFltAttrDatN(5, 3.41, attr3);
  Graph->AddFltAttrDatN(50, 2.718, attr3);
  Graph->AddFltAttrDatN(300, 150.0, attr3);
  Graph->AddFltAttrDatN(653, 653, attr3);
  NodeId = 0;
  for (TNEANet::TAFltI NI = Graph->BegNAFltI(attr3);
    NI < Graph->EndNAFltI(attr3); NI++) {
    if (NI.GetDat() != TFlt::Mn) {
      printf("Attribute: %s, Node: %i, Val: %f\n", attr3(), NodeId, NI.GetDat()());
      NodeId++;
    } 
  }

  // Test vertical str iterator for node 3, 50, 700, 900
  Graph->AddStrAttrDatN(10, "abc", attr1);
  Graph->AddStrAttrDatN(20, "def", attr1);
  Graph->AddStrAttrDatN(400, "ghi", attr1);
  // this does not show since ""=null
  Graph->AddStrAttrDatN(455, "", attr1);
  NodeId = 0;
  
  for (TNEANet::TAStrI NI = Graph->BegNAStrI(attr1);
    NI < Graph->EndNAStrI(attr1); NI++) {
    if (NI.GetDat() != TStr::GetNullStr()) {
      printf("Attribute: %s, Node: %i, Val: %s\n", attr1(), NodeId, NI.GetDat()());
      NodeId++;
    }
  } 

  // Test vertical iterator over many types (must skip default/deleted attr) 
  int NId = 55;
  Graph->AddStrAttrDatN(NId, "aaa", attr1);
  Graph->AddIntAttrDatN(NId, 3*2, attr2);
  Graph->AddFltAttrDatN(NId, 3.41, attr3);
  Graph->AddStrAttrDatN(80, "dont appear", attr4); // should not show up
  TStrV NIdAttrName;
  Graph->AttrNameNI(NId, NIdAttrName);
  int AttrLen = NIdAttrName.Len();
  for (int i = 0; i < AttrLen; i++) {
    printf("Vertical Node: %i, Attr: %s\n", NId, NIdAttrName[i]());
  } 

  Graph->DelAttrDatN(NId, attr2);
  Graph->AttrNameNI(NId, NIdAttrName);
  AttrLen = NIdAttrName.Len();
  for (int i = 0; i < AttrLen; i++) {
    printf("Vertical Node (no int) : %i, Attr: %s\n", NId, NIdAttrName[i]());
  } 

//.........这里部分代码省略.........
开发者ID:hiepbkhn,项目名称:itce2011,代码行数:101,代码来源:demo-TNEANet.cpp

示例12: ManipulateNodesEdges

// Test node, edge creation
void ManipulateNodesEdges() {
  int NNodes = 1000;
  int NEdges = 100000;
  const char *FName = "demo.graph.dat";

  PNEANet Graph;
  PNEANet Graph1;
  PNEANet Graph2;
  int i;
  int n;
  int NCount;
  int ECount1;
  int ECount2;
  int x,y;
  bool t;

  Graph = TNEANet::New();
  t = Graph->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Graph->AddNode(i);
  }
  n = Graph->GetNodes();
  t = Graph->Empty();

  // create random edges
  NCount = NEdges;
  while (NCount > 0) {
    x = rand() % NNodes;
    y = rand() % NNodes;
    n = Graph->AddEdge(x, y);
    NCount--;
  }
  PrintGStats("ManipulateNodesEdges:Graph",Graph);

  // get all the nodes
  NCount = 0;
  for (TNEANet::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    NCount++;
  }

  // get all the edges for all the nodes
  ECount1 = 0;
  for (TNEANet::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      ECount1++;
    }
  }

  // get all the edges directly
  ECount2 = 0;
  for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    ECount2++;
  }
  printf("graph ManipulateNodesEdges:Graph, nodes %d, edges1 %d, edges2 %d\n",
      NCount, ECount1, ECount2);

  // assignment
  Graph1 = TNEANet::New();
  *Graph1 = *Graph;
  PrintGStats("ManipulateNodesEdges:Graph1",Graph1);

  // save the graph
  {
    TFOut FOut(FName);
    Graph->Save(FOut);
    FOut.Flush();
  }

  // load the graph
  {
    TFIn FIn(FName);
    Graph2 = TNEANet::Load(FIn);
  }
  PrintGStats("ManipulateNodesEdges:Graph2",Graph2);

  // remove all the nodes and edges
  for (i = 0; i < NNodes; i++) {
    n = Graph->GetRndNId();
    Graph->DelNode(n);
  }

  PrintGStats("ManipulateNodesEdges:Graph",Graph);

  Graph1->Clr();
  PrintGStats("ManipulateNodesEdges:Graph1",Graph1);
}
开发者ID:hiepbkhn,项目名称:itce2011,代码行数:89,代码来源:demo-TNEANet.cpp


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