本文整理汇总了C++中PNGraph::AddNode方法的典型用法代码示例。如果您正苦于以下问题:C++ PNGraph::AddNode方法的具体用法?C++ PNGraph::AddNode怎么用?C++ PNGraph::AddNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PNGraph
的用法示例。
在下文中一共展示了PNGraph::AddNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeSlashdotNet
// Slashdot network
void MakeSlashdotNet(TStr InFNm, TStr OutFNm, TStr Desc) {
TSsParser Ss(InFNm, ssfTabSep);
PNGraph Graph = TNGraph::New();
TStrHash<TInt> StrSet(Mega(1), true);
while (Ss.Next()) {
const int SrcNId = StrSet.AddKey(Ss[0]);
if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
for (int dst = 2; dst < Ss.Len(); dst++) {
const int DstNId = StrSet.AddKey(Ss[dst]);
if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
Graph->AddEdge(SrcNId, DstNId);
}
}
PrintGraphStatTable(Graph, OutFNm, Desc);
}
示例2: GetSmallGraph
PNGraph TNGraph::GetSmallGraph() {
PNGraph G = TNGraph::New();
for (int i = 0; i < 5; i++) { G->AddNode(i); }
G->AddEdge(0,1); G->AddEdge(1,2); G->AddEdge(0,2);
G->AddEdge(1,3); G->AddEdge(3,4); G->AddEdge(2,3);
return G;
}
示例3: OnlyD3CEdgesNoBack
void OnlyD3CEdgesNoBack(PNGraph& dir_graph, PNGraph& d3c_graph) {
// Add all of the nodes into the new graph
for (TNGraph::TNodeI node = dir_graph->BegNI(); node < dir_graph->EndNI();
node++) {
int curr_node = node.GetId();
d3c_graph->AddNode(curr_node);
}
for (TNGraph::TNodeI node = dir_graph->BegNI(); node < dir_graph->EndNI();
node++) {
int curr_node = node.GetId();
auto curr_node_it = dir_graph->GetNI(curr_node);
for (int out_edge = 0; out_edge < curr_node_it.GetOutDeg(); ++out_edge) {
int out_node = curr_node_it.GetOutNId(out_edge);
for (int in_edge = 0; in_edge < curr_node_it.GetInDeg(); ++in_edge) {
int in_node = curr_node_it.GetInNId(in_edge);
if (dir_graph->IsEdge(out_node, in_node) && out_node != in_node) {
if (!d3c_graph->IsEdge(in_node, out_node) &&
!d3c_graph->IsEdge(curr_node, in_node) &&
!d3c_graph->IsEdge(out_node, curr_node)) {
if (!d3c_graph->IsEdge(out_node, in_node)) { d3c_graph->AddEdge(out_node, in_node); }
if (!d3c_graph->IsEdge(in_node, curr_node)) { d3c_graph->AddEdge(in_node, curr_node); }
if (!d3c_graph->IsEdge(curr_node, out_node)) { d3c_graph->AddEdge(curr_node, out_node); }
}
}
}
}
}
}
示例4: OnlyD3CEdges
void OnlyD3CEdges(PNGraph& dir_graph, PNGraph& d3c_graph, bool recip_edges) {
// Add all of the nodes into the new graph
for (TNGraph::TNodeI node = dir_graph->BegNI(); node < dir_graph->EndNI();
node++) {
int curr_node = node.GetId();
d3c_graph->AddNode(curr_node);
}
for (TNGraph::TNodeI node = dir_graph->BegNI(); node < dir_graph->EndNI();
node++) {
int curr_node = node.GetId();
auto curr_node_it = dir_graph->GetNI(curr_node);
for (int out_edge = 0; out_edge < curr_node_it.GetOutDeg(); ++out_edge) {
int out_node = curr_node_it.GetOutNId(out_edge);
for (int in_edge = 0; in_edge < curr_node_it.GetInDeg(); ++in_edge) {
int in_node = curr_node_it.GetInNId(in_edge);
if (out_node == in_node && !recip_edges) { continue; }
if (dir_graph->IsEdge(out_node, in_node) || recip_edges) {
if (!d3c_graph->IsEdge(out_node, in_node)) {
d3c_graph->AddEdge(out_node, in_node);
}
if (!d3c_graph->IsEdge(in_node, curr_node)) {
d3c_graph->AddEdge(in_node, curr_node);
}
if (!d3c_graph->IsEdge(curr_node, out_node)) {
d3c_graph->AddEdge(curr_node, out_node);
}
}
}
}
}
#ifdef _VERBOSE_
std::cout << "Original graph edge count: " << dir_graph->GetEdges() << std::endl
<< "D3C graph edge count: " << d3c_graph->GetEdges() << std::endl;
#endif
}
示例5: XmlLx
// DyNetML format, loads all the networks in the file
TVec<PNGraph> LoadDyNetGraphV(const TStr& FNm) {
TXmlLx XmlLx(TFIn::New(FNm), xspTruncate);
TVec<PNGraph> GraphV;
THashSet<TStr> NIdStr;
while (XmlLx.GetSym()!=xsyEof) {
if (XmlLx.Sym==xsySTag && XmlLx.TagNm=="network") {
PNGraph G = TNGraph::New();
GraphV.Add(G);
XmlLx.GetSym();
while (XmlLx.TagNm=="link") {
TStr Str1, Val1, Str2, Val2;
XmlLx.GetArg(0, Str1, Val1); XmlLx.GetArg(1, Str2, Val2);
IAssert(Str1=="source" && Str2=="target");
NIdStr.AddKey(Val1); NIdStr.AddKey(Val2);
const int src=NIdStr.GetKeyId(Val1);
const int dst=NIdStr.GetKeyId(Val2);
if (! G->IsNode(src)) { G->AddNode(src); }
if (! G->IsNode(dst)) { G->AddNode(dst); }
G->AddEdge(src, dst);
XmlLx.GetSym();
}
}
}
return GraphV;
}
示例6: GetNGraph
PNGraph TGraphKey::GetNGraph() const {
PNGraph G = TNGraph::New();
for (int i = 0; i < GetNodes(); i++) G->AddNode(i);
for (int e = 0; e < GetEdges(); e++) {
G->AddEdge(EdgeV[e].Val1, EdgeV[e].Val2);
}
G->Defrag();
return G;
}
示例7: while
int TTop2FriendNet::GetRnd2WccSz(const double ProbPick2nd) const {
TCnComV CnComV;
PNGraph G = TNGraph::New();
for (TWgtNet::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
if (NI.GetOutDeg() == 0) { continue; }
const int NId1 = NI.GetOutNId(TInt::Rnd.GetUniDevInt(NI.GetOutDeg()));
G->AddNode(NI.GetId());
G->AddNode(NId1);
G->AddEdge(NI.GetId(), NId1);
if (NI.GetOutDeg() > 1 && TInt::Rnd.GetUniDev() <= ProbPick2nd) {
int NId2 = NI.GetOutNId(TInt::Rnd.GetUniDevInt(NI.GetOutDeg()));
while (NId2 == NId1) { NId2 = NI.GetOutNId(TInt::Rnd.GetUniDevInt(NI.GetOutDeg())); }
G->AddNode(NId2);
G->AddEdge(NI.GetId(), NId2);
}
}
TCnCom::GetWccs(G, CnComV);
return CnComV[0].Len();
}
示例8: GetTree
/// returns a perfect binary tree
PNGraph GetTree() {
PNGraph G = TNGraph::New();
for (int i = 0; i < 15; i++) {
G->AddNode(i);
}
for (int i = 1; i < 15; i++) {
G->AddEdge(i,i/2);
}
return G;
}
示例9: RunSICascade2
// simulate SI model cascade using infection probability Beta until the cascade stops or reaches size MxCascSz
PNGraph RunSICascade2(PUNGraph G, const double& Beta, const int& MxCascSz, TIntH& NIdInfTmH) {
PNGraph Casc = TNGraph::New();
const int StartNId = G->GetRndNId();
Casc->AddNode(StartNId);
NIdInfTmH.AddDat(StartNId, NIdInfTmH.Len());
TIntQ Q; Q.Push(StartNId);
while (! Q.Empty()) {
const TUNGraph::TNodeI NI = G->GetNI(Q.Top()); Q.Pop();
for (int i = 0; i < NI.GetOutDeg(); i++) {
if (TInt::Rnd.GetUniDev() < Beta && ! NIdInfTmH.IsKey(NI.GetOutNId(i))) {
Casc->AddNode(NI.GetOutNId(i));
NIdInfTmH.AddDat(NI.GetOutNId(i), NIdInfTmH.Len());
Casc->AddEdge(NI.GetId(), NI.GetOutNId(i));
if (Casc->GetNodes() == MxCascSz) { return Casc; }
Q.Push(NI.GetOutNId(i));
}
}
}
return Casc;
}
示例10: RunSICascade
// simulate SI model cascade using infection probability Beta until the cascade reaches size CascSz
PNGraph RunSICascade(PUNGraph G, const double& Beta, const int& CascSz, TIntH& NIdInfTmH) {
PNGraph Casc = TNGraph::New();
const int StartId = G->GetRndNId();
Casc->AddNode(StartId);
NIdInfTmH.AddDat(StartId, NIdInfTmH.Len());
for (int X = 0; X < 10*CascSz; X++) {
TIntV CascNIdV; Casc->GetNIdV(CascNIdV);
for (int n = 0; n < CascNIdV.Len(); n++) {
const TUNGraph::TNodeI NI = G->GetNI(CascNIdV[n]);
for (int i = 0; i < NI.GetOutDeg(); i++) {
if (Casc->IsNode(NI.GetOutNId(i))) { continue; }
if (TInt::Rnd.GetUniDev() < Beta) {
Casc->AddNode(NI.GetOutNId(i));
NIdInfTmH.AddDat(NI.GetOutNId(i), NIdInfTmH.Len());
Casc->AddEdge(NI.GetId(), NI.GetOutNId(i));
if (Casc->GetNodes() == CascSz) { return Casc; }
}
}
}
}
return Casc;
}
示例11: MakeLJNets
void MakeLJNets(TStr InFNm, TStr OutFNm, TStr Desc){
TStrHash<TInt> StrSet(Mega(1), true);
for (int i = 1; i < 13; i++){
TStr tmp = "";
if (i < 10)
tmp = InFNm + "ljgraph.0" + TInt::GetStr(i);
else
tmp = InFNm + "ljgraph." + TInt::GetStr(i);
printf("%s\n",tmp());
TSsParser Ss(tmp, ssfTabSep);
PNGraph Graph = TNGraph::New();
while (Ss.Next()) {
const int SrcNId = StrSet.AddKey(Ss[0]);
if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
for (int dst = 2; dst < Ss.Len(); dst++) {
TStr ls,rs;
((TStr)Ss[dst]).SplitOnCh(ls,' ',rs);
if (ls == ">"){
const int DstNId = StrSet.AddKey(rs);
if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
Graph->AddEdge(SrcNId, DstNId);
}
}
}
if (i < 10)
OutFNm = "soc-lj-friends.0"+TInt::GetStr(i);
else
OutFNm = "soc-lj-friends."+TInt::GetStr(i);
PrintGraphStatTable(Graph, OutFNm, Desc);
}
}
示例12: GetTestTNGraph
// Generate TNGraph
PNGraph GetTestTNGraph() {
PNGraph Graph = TNGraph::New();
for (int i = 0; i < 20; i++) {
Graph->AddNode(i);
}
for (int i = 0; i < 20; i++) {
Graph->AddEdge(i,(i+1) % 20);
Graph->AddEdge(i,(i+2) % 20);
Graph->AddEdge(i,(i+3) % 20);
}
return Graph;
}
示例13: GetGraph
void TGraphEnumUtils::GetGraph(uint64 graphId, int nodes, PNGraph &G) {
G->Clr();
//Add nodes;
for(int i=0; i<nodes; i++) G->AddNode(i);
//Add edges
for(int row=0; row<nodes; row++) {
for(int col=0; col<nodes; col++) {
int n = row*nodes+col;
//
uint64 bits = graphId >> n;
uint64 mask = 1;
if((bits & mask)==1) G->AddEdge(row, col);
}
}
}
示例14: GetIndGraph
void TGraphEnumUtils::GetIndGraph(const PNGraph &G, const TIntV &sg, PNGraph &indG) {
//Add nodes
for(int i=0; i<sg.Len(); i++) indG->AddNode(sg[i]);
//Add edges
for(int i=0; i<sg.Len(); i++) {
int nId = sg[i];
TNGraph::TNodeI nIt = G->GetNI(nId);
//
int deg = nIt.GetOutDeg();
for(int j=0; j<deg; j++) {
int dstId = nIt.GetNbrNId(j);
if(nId == dstId) continue;
//
if(indG->IsNode(dstId)) indG->AddEdge(nId, dstId);
}
}
}
示例15: GetNormalizedGraph
void TGraphEnumUtils::GetNormalizedGraph(const PNGraph &G, PNGraph &nG) {
//Get bijective map from original node ids to normalized node ids(0,1,2,...)
THash<TInt,TInt> map;
GetNormalizedMap(G, map);
//Add nodes
for(int i=0; i<G->GetNodes(); i++) nG->AddNode(i);
//Add edges
for(TNGraph::TEdgeI eIt=G->BegEI(); eIt<G->EndEI(); eIt++) {
int srcId = eIt.GetSrcNId();
int dstId = eIt.GetDstNId();
//
int mSrcId = map.GetDat(srcId);
int mDstId = map.GetDat(dstId);
//
nG->AddEdge(mSrcId, mDstId);
}
}