本文整理汇总了C++中PGraph类的典型用法代码示例。如果您正苦于以下问题:C++ PGraph类的具体用法?C++ PGraph怎么用?C++ PGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintGStats
void PrintGStats(const char s[], PGraph Graph) {
printf("graph %s, nodes %d, edges %d, empty %s\n",
s, Graph->GetNodes(), Graph->GetEdges(),
Graph->Empty() ? "yes" : "no");
}
示例2: FindCascadeRoot
int FindCascadeRoot(const PGraph& G, const TIntH& NIdInfTmH) { // earliest infected node
int Min=TInt::Mx, MinNId=-1;
for (typename PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
const int t = NIdInfTmH.GetDat(NI.GetId());
if (t < Min && NI.GetInDeg()==0) { Min=t; MinNId=NI.GetId(); } }
IAssert(MinNId!=-1); return MinNId;
}
示例3: TakeStat
void TakeStat(const PGraph& InfG, const PGraph& NetG, const TIntH& NIdInfTmH, const double& P, const bool& DivByM=true) {
const double M = DivByM ? InfG->GetNodes() : 1; IAssert(M>=1);
PGraph CcInf, CcNet; // largest connected component
// connected components and sizes
{ TCnComV CnComV; TSnap::GetWccs(InfG, CnComV);
NCascInf.AddDat(P).Add(CnComV.Len()/M);
MxSzInf.AddDat(P).Add(CnComV[0].Len()/M);
{ int a=0; for (int i=0; i<CnComV.Len(); i++) { a+=CnComV[i].Len(); }
AvgSzInf.AddDat(P).Add(a/double(CnComV.Len()*M)); }
CcInf = TSnap::GetSubGraph(InfG, CnComV[0].NIdV);
TSnap::GetWccs(NetG, CnComV);
NCascNet.AddDat(P).Add(CnComV.Len()/M);
MxSzNet.AddDat(P).Add(CnComV[0].Len()/M);
{ int a=0; for (int i=0; i<CnComV.Len(); i++) { a+=CnComV[i].Len(); }
AvgSzNet.AddDat(P).Add(a/double(CnComV.Len()*M)); }
CcNet = TSnap::GetSubGraph(NetG, CnComV[0].NIdV); }
// count isolated nodes and leaves; average in- and out-degree (skip leaves)
{ int i1=0, i2=0,l1=0,l2=0,r1=0,r2=0,ENet=0,EInf=0; double ci1=0,ci2=0,co1=0,co2=0;
for (typename PGraph::TObj::TNodeI NI = InfG->BegNI(); NI < InfG->EndNI(); NI++) {
if (NI.GetOutDeg()==0 && NI.GetInDeg()>0) { l1++; }
if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) { r1++; }
if (NI.GetDeg()==0) { i1++; } if (NI.GetInDeg()>0) { ci1+=1; }
if (NI.GetOutDeg()>0) { co1+=1; } EInf+=NI.GetOutDeg(); }
for (typename PGraph::TObj::TNodeI NI = NetG->BegNI(); NI < NetG->EndNI(); NI++) {
if (NI.GetOutDeg()==0 && NI.GetInDeg()>0) { l2++; }
if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) { r2++; }
if (NI.GetDeg()==0) { i2++; } if (NI.GetInDeg()>0) { ci2+=1; }
if (NI.GetOutDeg()>0) { co2+=1; } ENet+=NI.GetOutDeg(); }
if(ci1>0)InDegInf.AddDat(P).Add(EInf/ci1); if(ci2>0)InDegNet.AddDat(P).Add(ENet/ci2);
if(co1>0)OutDegInf.AddDat(P).Add(EInf/co1); if(co2>0)OutDegNet.AddDat(P).Add(ENet/co2);
NLfInf.AddDat(P).Add(l1/M); NLfNet.AddDat(P).Add(l2/M);
NRtInf.AddDat(P).Add(r1/M); NRtNet.AddDat(P).Add(r2/M);
NIsoInf.AddDat(P).Add(i1/M); NIsoNet.AddDat(P).Add(i2/M); }
// cascade depth
{ const double M1 = DivByM ? CcNet->GetNodes() : 1; IAssert(M1>=1);
int Root=FindCascadeRoot(CcInf, NIdInfTmH); TIntPrV HopCntV;
TSnap::GetNodesAtHops(CcInf, Root, HopCntV, true);
int MxN=0, Lev=0, IncL=0;
for (int i = 0; i < HopCntV.Len(); i++) {
if (MxN<HopCntV[i].Val2) { MxN=HopCntV[i].Val2; Lev=HopCntV[i].Val1; }
if (i > 0 && HopCntV[i-1].Val2<=HopCntV[i].Val2) { IncL++; } }
double D=0; int c=0; TIntH DistH;
D = HopCntV.Last().Val1; c=1; // maximum depth
if (c!=0 && D!=0) { D = D/c;
DepthInf.AddDat(P).Add(D/M1); MxWidInf.AddDat(P).Add(MxN/M1);
MxLevInf.AddDat(P).Add(Lev/D); IncLevInf.AddDat(P).Add(IncL/D);
}
Root=FindCascadeRoot(CcNet, NIdInfTmH);
TSnap::GetNodesAtHops(CcNet, Root, HopCntV, true);
MxN=0; Lev=0; IncL=0; D=0; c=0;
for (int i = 0; i < HopCntV.Len(); i++) {
if (MxN<HopCntV[i].Val2) { MxN=HopCntV[i].Val2; Lev=HopCntV[i].Val1; }
if (i > 0 && HopCntV[i-1].Val2<=HopCntV[i].Val2) { IncL++; } }
D = HopCntV.Last().Val1; c=1; // maximum depth
if (c!=0 && D!=0) { D = D/c;
DepthNet.AddDat(P).Add(D/M1); MxWidNet.AddDat(P).Add(MxN/M1);
MxLevNet.AddDat(P).Add(Lev/D); IncLevNet.AddDat(P).Add(IncL/D); }
}
}
示例4: main
int main(int argc, char* argv[]) {
PGraph Graph = TSnap::LoadEdgeList<PNGraph>("facebook_combined.txt",0,1);
graphMl(Graph);
gexf(Graph);
gdf(Graph);
graphson(Graph);
IAssert(Graph->IsOk());
return 0;
}
示例5: PercentDegree
double PercentDegree(const PGraph& Graph, const int Threshold=0) {
int Cnt = 0;
for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++)
{
if (NI.GetDeg() >= Threshold) Cnt++;
}
return (double)Cnt / (double) Graph->GetNodes();
}
示例6: GetAvgDepthFromRoot
double GetAvgDepthFromRoot(const PGraph& G) {
TMom Mom;
TIntPrV HopCntV;
for (typename PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) {
TSnap::GetNodesAtHops(G, NI.GetId(), HopCntV, true);
Mom.Add(HopCntV.Last().Val1()); }
}
Mom.Def(); return Mom.GetMean();
}
示例7: main
int main()
{
//Number of levels
int emptyStart = 0;
int final_level = 0;
int final_number = 0;
int depth = 1;
//string config = "1110111111111111111111111111111111111111111111111111111";
//string final_config = "0000000000100000000000000000000000000000000000000000000";
int n;// = 8;
string config;// = "01111111111111111111111111111111111111111111111111111111111111111";
string final_config;// = "100000000000000000000000000000000000000000000000000000000000000000";
cout<<"Please enter the number of level's you would like in this game: ";
cin>>n;
cout<<endl<<"Please enter the initial state which is a series of "<<(float)(n*(n+1)/2)<<" 0's and 1's where 1 reprents a peg and 0 represents an empty space."<<endl;
cin>>config;
cout<<endl<<"Please enter the final state which is a series of "<<(float)(n*(n+1)/2)<<" 0's and 1's where 1 reprents a peg and 0 represents an empty space."<<endl;
cin>>final_config;
cout<<endl<<endl;
PegTable *found;
PegTable *table = new PegTable(n,config);
PGraph graph;
stack<PegTable*> stac;
const clock_t begin_time = clock();
found = graph.DFS(table,final_config);
cout<<endl<<float((clock() - begin_time))/1000<<" seconds"<<endl<<endl;
if(found == 0)
{
cout<<"The solution state for this configuration does not exist"<<endl;
return 0;
}
// sf::Clock Clock;
//
while(found != 0)
{
stac.push(found);
found = found->parent;
}
while(!stac.empty())
{
found = stac.top();
stac.pop();
found->Print();
}
return 0;
}
示例8: NodesGTEDegree
int NodesGTEDegree(const PGraph& Graph, const int Threshold=0) {
int Cnt = 0;
for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI();
NI++)
{
if (NI.GetDeg() >= Threshold) Cnt++;
}
return Cnt;
}
示例9: MxDegree
int MxDegree(const PGraph& Graph) {
int MaxDeg = 0;
for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
if (NI.GetDeg() > MaxDeg) {
MaxDeg = NI.GetDeg();
}
}
return MaxDeg;
}
示例10: SampleCascade
void SampleCascade(const PGraph& InfCasc, const PGraph& NetCasc, const TIntH& NIdInfTmH, const double& PStep=0.05, const int& NRuns=1, const bool& DivByM=true) {
for (int Run=0; Run < NRuns; Run++) {
for (double P = PStep; P <= 1.01; P += PStep) {
TIntV NIdV;
for (typename PGraph::TObj::TNodeI NI = InfCasc->BegNI(); NI < InfCasc->EndNI(); NI++) {
if (TInt::Rnd.GetUniDev() < P) { NIdV.Add(NI.GetId()); } }
PGraph InfG = TSnap::GetSubGraph(InfCasc, NIdV);
PGraph NetG = TSnap::GetSubGraph(NetCasc, NIdV);
if (InfG->GetNodes()==0) { continue; }
TakeStat(InfG, NetG, NIdInfTmH, P, DivByM);
}
}
}
示例11: BenchmarkGraphNodeI
void BenchmarkGraphNodeI(PGraph Graph, std::ofstream& file, bool isDefrag) {
int NCount = 0;
int i = 0;
clock_t start = clock();
for (i = 0; i < 50; i++) {
NCount = 0;
for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
NCount++;
}
}
double msec = (clock() - start) * 1000.0 / CLOCKS_PER_SEC;
printf("Nodes: %d Edges: %d Time: %f ms\n", NCount, Graph->GetEdges(), msec/50);
file << msec/50 << " ";
}
示例12: main
int main(int argc, char* argv[]) {
typedef PNGraph PGraph; // directed graph
printf("Creating graph for Livejournal\n");
TFIn FIn("data/livejournal_scc.graph");
PGraph graph = TNGraph::Load(FIn);
IAssert(graph->IsOk());
printf("Nodes: %d\n", graph->GetNodes());
test<PGraph>(graph, true, false);
test<PGraph>(graph, false, true);
test<PGraph>(graph, true, true);
return 0;
}
示例13: PrintGraphStatTable
void PrintGraphStatTable(const PGraph& G, TStr OutFNm, TStr Desc="") {
TFltPrV DegCCfV;
int64 ClosedTriads, OpenTriads;
int FullDiam;
double EffDiam;
TSnap::PrintInfo(G, OutFNm);
TExeTm ExeTm; printf("C");
const double CCF = TSnap::GetClustCf(G, DegCCfV, ClosedTriads, OpenTriads);
printf("[%s]D", ExeTm.GetStr());
TSnap::GetBfsEffDiam(G, 1000, false, EffDiam, FullDiam);
printf("[%s]CC", ExeTm.GetStr());
PGraph WCC = TSnap::GetMxWcc(G);
PGraph SCC = TSnap::GetMxScc(G);
printf("[%s]\n", ExeTm.GetStr());
FILE* F = stdout;
if (! OutFNm.Empty()) {
F = fopen(TStr::Fmt("%s.html", OutFNm.CStr()).CStr(), "wt"); }
fprintf(F, "\n");
fprintf(F, "<table id=\"datatab\" summary=\"Dataset statistics\">\n");
fprintf(F, " <tr> <th colspan=\"2\">Dataset statistics</th> </tr>\n");
fprintf(F, " <tr><td>Nodes</td> <td>%d</td></tr>\n", G->GetNodes());
fprintf(F, " <tr><td>Edges</td> <td>%d</td></tr>\n", G->GetEdges());
fprintf(F, " <tr><td>Nodes in largest WCC</td> <td>%d (%.3f)</td></tr>\n", WCC->GetNodes(), WCC->GetNodes()/double(G->GetNodes()));
fprintf(F, " <tr><td>Edges in largest WCC</td> <td>%d (%.3f)</td></tr>\n", WCC->GetEdges(), WCC->GetEdges()/double(G->GetEdges()));
fprintf(F, " <tr><td>Nodes in largest SCC</td> <td>%d (%.3f)</td></tr>\n", SCC->GetNodes(), SCC->GetNodes()/double(G->GetNodes()));
fprintf(F, " <tr><td>Edges in largest SCC</td> <td>%d (%.3f)</td></tr>\n", SCC->GetEdges(), SCC->GetEdges()/double(G->GetEdges()));
fprintf(F, " <tr><td>Average clustering coefficient</td> <td>%.4f</td></tr>\n", CCF);
fprintf(F, " <tr><td>Number of triangles</td> <td>%s</td></tr>\n", TUInt64(ClosedTriads).GetStr().CStr());
fprintf(F, " <tr><td>Fraction of closed triangles</td> <td>%.4g</td></tr>\n", ClosedTriads/double(ClosedTriads+OpenTriads));
fprintf(F, " <tr><td>Diameter (longest shortest path)</td> <td>%d</td></tr>\n", FullDiam);
fprintf(F, " <tr><td>90-percentile effective diameter</td> <td>%.2g</td></tr>\n", EffDiam);
fprintf(F, "</table>\n");
fprintf(F, "<br>\n");
if (! OutFNm.Empty()) {
fprintf(F, "\n<table id=\"datatab\" summary=\"Table of datasets\">\n");
fprintf(F, "<tr>\n");
fprintf(F, " <th>File</th>\n");
fprintf(F, " <th>Description</th>\n");
fprintf(F, "</tr>\n");
fprintf(F, "<tr>\n");
fprintf(F, " <td><a href=\"%s.txt.gz\">%s.txt.gz</a></td>\n", OutFNm.CStr(), OutFNm.CStr());
fprintf(F, " <td>%s</td>\n", Desc.CStr());
fprintf(F, "</tr>\n");
fprintf(F, "</table>\n");
fclose(F);
TSnap::SaveEdgeList(G, OutFNm+".txt", Desc);
}
}
示例14: main
int main(int argc, char* argv[]) {
typedef PNGraph PGraph; // directed graph
printf("Creating graph for wikiTalk\n");
PGraph graph = TSnap::LoadEdgeList<PGraph>("data/wiki-Talk.txt", 0, 1);
IAssert(graph->IsOk());
printf("Graph (%d, %d)\n", graph->GetNodes(), graph->GetEdges());
printf("Getting max scc\n");
PGraph maxScc = TSnap::GetMxScc(graph);
printf("Scc (%d, %d)\n", maxScc->GetNodes(), maxScc->GetEdges());
TFOut FOut("data/wikiTalk_scc.graph");
maxScc->Save(FOut);
return 0;
}
示例15: test
bool test(PGraph &graph, bool followOut, bool followIn) {
printf("\n================================\nFollowOut: %d, FollowIn: %d\n", followOut, followIn);
int iters = 10;
for (int k = 0; k < iters; k++) {
TRnd rnd = TRnd((int)time(0));
int start = graph->GetRndNId(rnd);
rnd.PutSeed(0);
// int target = graph->GetRndNId(rnd);
// printf("Start node: %d, target node: %d\n", start, target);
int target = -1;
printf("Start node: %d\n", start);
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
/* Hybrid */
TBreathFS<PGraph> bfs_hybrid(graph, true);
int maxDist_hybrid = bfs_hybrid.DoBfsHybrid(start, followOut, followIn, target);
gettimeofday(&tv2, NULL);
double time_hybrid = timeInSeconds(tv1, tv2);
/* Original */
gettimeofday(&tv1, NULL);
TBreathFS<PGraph> bfs(graph, true);
int maxDist = bfs.DoBfs(start, followOut, followIn, target);
gettimeofday(&tv2, NULL);
double time = timeInSeconds(tv1, tv2);
/* Check results */
if (maxDist_hybrid != maxDist) {
printf("MaxDist incorrect.\n");
return false;
}
if (target == -1) {
if (!checkResults<PGraph>(bfs_hybrid, bfs)) {
printf("NIdDistH values incorrect!\n");
return false;
}
}
printf("Execution times: Original: %.2f, Hybrid: %.2f\n", time, time_hybrid);
}
return true;
}