本文整理汇总了C++中TPt类的典型用法代码示例。如果您正苦于以下问题:C++ TPt类的具体用法?C++ TPt怎么用?C++ TPt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TPt类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: TestGraphDAG
void TestGraphDAG(TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, std::vector<int> vSeedIDs, int numIterations)
{
cout << "Starting BP from nodeID {";
for(int sourceNode : vSeedIDs)
cout << sourceNode << " ";
cout << "}\nThe input graph has " << pGraph->GetNodes() << " nodes and " << pGraph->GetEdges() << " edges.\n";
// Start traversing the graph
tbb::tick_count tic = tbb::tick_count::now();
for(int i = 0; i<numIterations; ++i)
ParallelBPFromNodeDAG(pGraph, vSeedIDs);
double dElapsedTime = (tbb::tick_count::now() - tic).seconds();
cout << "Time elapsed for parallel BP: " << dElapsedTime/numIterations << " seconds\n";
tic = tbb::tick_count::now();
for(int i = 0; i<numIterations; ++i)
ParallelBPFromNodeDAG_LevelSynchronous(pGraph, vSeedIDs);
dElapsedTime = (tbb::tick_count::now() - tic).seconds();
cout << "Time elapsed for parallel level synchronous BP: " << dElapsedTime/numIterations << " seconds\n";
tic = tbb::tick_count::now();
for(int i = 0; i<numIterations; ++i)
PropagateFromNodeDAG(pGraph, vSeedIDs);
dElapsedTime = (tbb::tick_count::now() - tic).seconds();
cout << "Time elapsed for serial BP: " << dElapsedTime/numIterations << " seconds\n";
std::vector<int> vResult;
CalculateRankFromSource_BellmanFord(pGraph, vSeedIDs, vResult);
tic = tbb::tick_count::now();
for(int i = 0; i<numIterations; ++i)
ParallelBPFromNode_SingleNodeUpdate(pGraph, vResult, vSeedIDs);
dElapsedTime = (tbb::tick_count::now() - tic).seconds();
cout << "Time elapsed for ParallelBPFromNode_SingleNodeUpdate: " << dElapsedTime/numIterations << " seconds\n";
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:34,代码来源:Main.cpp
示例2: 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
示例3: 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;
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:11,代码来源:testgraph.cpp
示例4: 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
示例5: 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
示例6: Dijkstra
//! Given pGraph with data about edge weights, computes the distance of the shortest paths from sourceNode
//! and returns the result in the nodes of pDAGGraph.
//! Updates the edges if bUpdateEdges is set to true. Default is false. In that case only the node data is updated with the shortest distance to sourceNode.
//! @note Requires initial values for the nodes of pDAGGraph (edges are not needed)
void Dijkstra(const TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, int sourceNode, double dThreshold, TPt<TNodeEDatNet<TFlt, TFlt>>& pDAGGraph, bool bUpdateEdges = false)
{
double logThreshold = log(dThreshold);
if(dThreshold==0)
logThreshold=-DBL_MAX;
// List of visited nodes
std::map<int, bool> visitedNodes;
// Stores the edge vertices to build the final DAG
std::map<int, int> mapPrevious;
std::priority_queue<std::pair<int,double>, std::vector<std::pair<int,double>>, Order> nodesToVisit;
// Distance from source node to itself is 0
pDAGGraph->SetNDat(sourceNode, 0);
nodesToVisit.push(std::make_pair(sourceNode,0));
// Beginning of the loop of Dijkstra algorithm
while(!nodesToVisit.empty())
{
// Find the vertex in queue with the smallest distance and remove it
int iParentID = -1;
while (!nodesToVisit.empty() && visitedNodes[iParentID = nodesToVisit.top().first])
nodesToVisit.pop();
if (iParentID == -1) break;
// mark the vertex with the shortest distance
visitedNodes[iParentID]=true;
auto parent = pGraph->GetNI(iParentID);
int numChildren = parent.GetOutDeg();
for(int i = 0; i < numChildren; ++i)
{
int iChildID = parent.GetOutNId(i);
// Accumulate the shortest distance from source
double alt = pDAGGraph->GetNDat(iParentID) - log(parent.GetOutEDat(i).Val);
if(alt >= logThreshold)
{
auto it = visitedNodes.find(iChildID);
if (alt < pDAGGraph->GetNDat(iChildID) && it->second == false)
{
//1. update distance
//2. update the predecessor
//3. push new shortest rank of chidren nodes
pDAGGraph->SetNDat(iChildID, alt);
mapPrevious[iChildID]= iParentID;
nodesToVisit.push(std::make_pair(iChildID,alt));
}
}
}
}
if(bUpdateEdges)
for(auto it=mapPrevious.begin(); it!= mapPrevious.end(); ++it)
{
pDAGGraph->AddEdge(it->second, it->first);
pDAGGraph->SetEDat(it->second,it->first, pGraph->GetEDat(it->second,it->first));
}
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:64,代码来源:Utilities.cpp
示例7: GenerateDAG2
//???????
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;
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:44,代码来源:Utilities.cpp
示例8: MIOA
TPt<TNodeEDatNet<TFlt, TFlt>> MIOA(const TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, int sourceNode, double dThreshold)
{
//////////////////////////////////////////////////////////////
// Compte the Maximum Influence Out-Arborescence with Dijkstra
// Copy the nodes of pGraph
auto pDAGGraph = TNodeEDatNet<TFlt, TFlt>::New();
for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
{
int NodeID = NI.GetId();
pDAGGraph->AddNode(NodeID);
pDAGGraph->SetNDat(NodeID, FLT_MAX);
}
Dijkstra(pGraph, sourceNode, dThreshold, pDAGGraph, true);
// pDAGGraph is the MIOA starting from sourceNode
return pDAGGraph;
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:19,代码来源:Utilities.cpp
示例9: GenerateDAG1
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
示例10: main
int main(int argc, char* argv[]) {
// create a graph and save it
{ PNGraph Graph = TNGraph::New();
for (int i = 0; i < 10; i++) {
Graph->AddNode(i); }
for (int i = 0; i < 10; i++) {
Graph->AddEdge(i, TInt::Rnd.GetUniDevInt(10)); }
TSnap::SaveEdgeList(Graph, "graph.txt", "Edge list format"); }
// load a graph
PNGraph Graph;
Graph = TSnap::LoadEdgeList<PNGraph>("graph.txt", 0, 1);
// traverse nodes
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
printf("NodeId: %d, InDegree: %d, OutDegree: %d\n", NI.GetId(), NI.GetInDeg(), NI.GetOutDeg());
printf("OutNodes: ");
for (int e = 0; e < NI.GetOutDeg(); e++) { printf(" %d", NI.GetOutNId(e)); }
printf("\nInNodes: ");
for (int e = 0; e < NI.GetInDeg(); e++) { printf(" %d", NI.GetInNId(e)); }
printf("\n\n");
}
// graph statistic
TSnap::PrintInfo(Graph, "Graph info");
PNGraph MxWcc = TSnap::GetMxWcc(Graph);
TSnap::PrintInfo(MxWcc, "Largest Weakly connected component");
// random graph
PNGraph RndGraph = TSnap::GenRndGnm<PNGraph>(100, 1000);
TGStat GraphStat(RndGraph, TSecTm(1), TGStat::AllStat(), "Gnm graph");
GraphStat.PlotAll("RndGraph", "Random graph on 1000 nodes");
// Forest Fire graph
{ TFfGGen ForestFire(false, 1, 0.35, 0.30, 1.0, 0.0, 0.0);
ForestFire.GenGraph(100);
PNGraph FfGraph = ForestFire.GetGraph(); }
// network
TPt<TNodeEDatNet<TStr, TStr> > Net = TNodeEDatNet<TStr, TStr>::New();
Net->AddNode(0, "zero");
Net->AddNode(1, "one");
Net->AddEdge(0, 1, "zero to one");
return 0;
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:39,代码来源:testSnap.cpp
示例11: 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
示例12: TEST
// Test edge subgraphs
TEST(subgraph, TestEdgeSubNets) {
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
TPt <TNodeEdgeNet<TInt, TInt> > Net3;
TPt <TNodeEdgeNet<TInt, TInt> > Net4;
int i;
TIntV NIdV;
TIntV NIdV1;
Net = GetTestTNodeEdgeNet();
EXPECT_EQ(20,Net->GetNodes());
EXPECT_EQ(120,Net->GetEdges());
for (i = 10; i < 15; i++) {
NIdV.Add(i);
}
Net1 = TSnap::GetSubGraph(Net, NIdV);
EXPECT_EQ(5,Net1->GetNodes());
EXPECT_EQ(18,Net1->GetEdges());
for (i = 0; i < 20; i += 2) {
NIdV1.Add(i);
}
Net2 = TSnap::GetSubGraph(Net, NIdV1);
EXPECT_EQ(10,Net2->GetNodes());
EXPECT_EQ(20,Net2->GetEdges());
Net3 = TSnap::GetEDatSubGraph(Net, 1, 0);
EXPECT_EQ(20,Net3->GetNodes());
EXPECT_EQ(30,Net3->GetEdges());
Net4 = TSnap::GetEDatSubGraph(Net, 2, -1);
EXPECT_EQ(20,Net4->GetNodes());
EXPECT_EQ(60,Net4->GetEdges());
}
开发者ID:d-mittal,项目名称:snap,代码行数:39,代码来源:test-subgraph.cpp
示例13: TEST
// Test the default constructor
TEST(TNodeEdgeNet, DefaultConstructor) {
TPt <TNodeEdgeNet<TInt, TInt> > Net;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(0,Net->GetNodes());
EXPECT_EQ(0,Net->GetEdges());
EXPECT_EQ(1,Net->IsOk());
EXPECT_EQ(1,Net->Empty());
EXPECT_EQ(1,Net->HasFlag(gfDirected));
EXPECT_EQ(1,Net->HasFlag(gfNodeDat));
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:14,代码来源:test-TNodeEdgeNet.cpp
示例14: 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;
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:93,代码来源:Utilities.cpp
示例15: UpdateNodeData
// Test update node data
void UpdateNodeData() {
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 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,i+5);
}
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("UpdateNodeData:Net", Net);
// 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()+5;
if (NodeDat != Value) {
ok = false;
}
}
printf("network UpdateNodeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");
// update node data, node ID + 10
for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Net->SetNDat(NI.GetId(), NI.GetId()+10);
}
// 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()+10;
if (NodeDat != Value) {
ok = false;
}
}
printf("network UpdateNodeData:Net, status2 %s\n", (ok == true) ? "ok" : "ERROR");
}
开发者ID:Accio,项目名称:snap,代码行数:68,代码来源:demo-TNodeEDatNet.cpp
示例16: 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
示例17: 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
示例18: PrintNStats
// Print network statistics
void PrintNStats(const char s[], TPt <TNodeEDatNet<TInt, TInt> > Net) {
printf("network %s, nodes %d, edges %d, empty %s\n",
s, Net->GetNodes(), Net->GetEdges(),
Net->Empty() ? "yes" : "no");
}
开发者ID:Accio,项目名称:snap,代码行数:6,代码来源:demo-TNodeEDatNet.cpp
示例19: 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);
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:7,代码来源:Utilities.cpp
示例20: 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
注:本文中的TPt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论