本文整理汇总了C++中TPt::IsNode方法的典型用法代码示例。如果您正苦于以下问题:C++ TPt::IsNode方法的具体用法?C++ TPt::IsNode怎么用?C++ TPt::IsNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TPt
的用法示例。
在下文中一共展示了TPt::IsNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
示例4:
// 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;
//.........这里部分代码省略.........
示例5: 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);
}
//.........这里部分代码省略.........
示例6: MaxIncrementalInfluence
std::vector<int> MaxIncrementalInfluence(TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, int numRounds){
std::vector<int> vSeedSet;
tbb::concurrent_unordered_map<int,double> mSpreadIncrement;
auto pGraph_temp = TNodeEDatNet<TFlt, TFlt>::New();
double influence = 0.0; int i,chunk = 50;
static tbb::spin_mutex sMutex;
//Failure of using PeerSeeds due to insufficient memory
//std::map<int,std::vector<int> > mPeerSeeds;
//std::map<int,TPt<TNodeEDatNet<TFlt, TFlt>> > mMIOAs;
/* Initialization*/
int numNodes = pGraph->GetMxNId();
#pragma omp parallel shared(pGraph,chunk,mSpreadIncrement) private(pGraph_temp,i)
{
#pragma omp for schedule(dynamic,chunk) nowait
for (i =0;i<numNodes;++i)
{
if(pGraph->IsNode(i))
{
pGraph_temp = MIOA(pGraph, i, 0);
InitializationBeforePropagation(pGraph_temp);
ParallelBPFromNode_1DPartitioning(pGraph_temp, i);
mSpreadIncrement[i]=InfluenceSpreadFromSeedNodes(pGraph_temp);
//mMIOAs.insert(std::make_pair(i,pGraph_v));
}
}
}
/*
//build PeerSeeds
//Failure due to the insufficient memory
for (int v =0; v<pGraph->GetNodes();++v)
if(pGraph->IsNode(v))
mPeerSeeds[v]=GetPeerSeeds(mMIOAs,v);
*/
cout<<"--------------------------Finished Initialization---------------------"<<endl;
for (int i=0;i<numRounds;++i)
{
/* select the i'th seed by finding u = argmax(mSpreadIncrement)*/
auto it = std::max_element(mSpreadIncrement.begin(),mSpreadIncrement.end(),
[&](std::pair<int,double> const& a, std::pair<int,double> const& b) {
return a.second < b.second;
}
);
int SeedID = it->first;
cout << SeedID <<endl;
/* calculate the current influence spread */
vSeedSet.push_back(SeedID);
pGraph = GenerateDAG1(pGraph, vSeedSet, 0.0);
ParallelBPFromNode_1DPartitioning(pGraph, vSeedSet);
influence = InfluenceSpreadFromSeedNodes(pGraph);
/*remove the newly selected node*/
mSpreadIncrement.unsafe_erase(SeedID);
/* update incremental influence spread for each round */
double Delta_MAX = 0.0;
std::vector<int> vSeedSet_temp = vSeedSet;
#pragma omp parallel shared(pGraph,chunk,vSeedSet,mSpreadIncrement,Delta_MAX) private(pGraph_temp,vSeedSet_temp,i)
{
#pragma omp for schedule(dynamic,chunk) nowait
for (i =0;i<numNodes;++i)
{
/* exclude the nodes in seed set */
auto result = std::find(vSeedSet.begin(),vSeedSet.end(), i);
if (result != vSeedSet.end()) continue;
if(pGraph->IsNode(i) && mSpreadIncrement[i] > Delta_MAX)
{
/*different processors use different copied vSeedSet*/
vSeedSet_temp.push_back(i);
pGraph_temp = GenerateDAG1(pGraph, vSeedSet_temp, 0);
ParallelBPFromNode_1DPartitioning(pGraph_temp, vSeedSet_temp);
mSpreadIncrement[i]=InfluenceSpreadFromSeedNodes(pGraph_temp)-influence;
if (mSpreadIncrement[i]> Delta_MAX)
{
tbb::spin_mutex::scoped_lock lock(sMutex);
Delta_MAX = mSpreadIncrement[i];
}
vSeedSet_temp.pop_back();
}
}
}
}
return vSeedSet;
}