本文整理汇总了C++中PNGraph::EndNI方法的典型用法代码示例。如果您正苦于以下问题:C++ PNGraph::EndNI方法的具体用法?C++ PNGraph::EndNI怎么用?C++ PNGraph::EndNI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PNGraph
的用法示例。
在下文中一共展示了PNGraph::EndNI方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MinSup
/////////////////////////////////////////////////
// Trawling the web for emerging communities
// graph, left points to right
TTrawling::TTrawling(const PNGraph& Graph, const int& MinSupport) : MinSup(MinSupport) {
TIntH ItemCntH;
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
IAssert(NI.GetOutDeg()==0 || NI.GetInDeg()==0); // edges only point from left to right
if (NI.GetOutDeg()==0) { continue; }
for (int e = 0; e < NI.GetOutDeg(); e++) {
ItemCntH.AddDat(NI.GetOutNId(e)) += 1;
}
}
TIntV RightV;
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
IAssert(NI.GetOutDeg()==0 || NI.GetInDeg()==0); // edges only point from left to right
if (NI.GetOutDeg()==0) { continue; }
RightV.Clr(false);
for (int e = 0; e < NI.GetOutDeg(); e++) {
const int itm = NI.GetOutNId(e);
// only include items that already are above minimum support
if (ItemCntH.GetDat(itm) >= MinSup) {
RightV.Add(itm); }
}
if (! RightV.Empty()) {
NIdSetH.AddDat(NI.GetId(), RightV);
}
}
//
for (int n = 0; n < NIdSetH.Len(); n++) {
const TIntV& Set = NIdSetH[n];
for (int s = 0; s < Set.Len(); s++) {
SetNIdH.AddDat(Set[s]).Add(n);
}
}
}
示例2: 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); }
}
}
}
}
}
}
示例3: 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
}
示例4: GetSngVec
void GetSngVec(const PNGraph& Graph, TFltV& LeftSV, TFltV& RightSV) {
const int Nodes = Graph->GetNodes();
TFltVV LSingV, RSingV;
TFltV SngValV;
if (Nodes < 500) {
// perform full SVD
TFltVV AdjMtx(Nodes+1, Nodes+1);
TIntH NodeIdH;
// create adjecency matrix
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
NodeIdH.AddKey(NodeI.GetId()); }
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
const int NodeId = NodeIdH.GetKeyId(NodeI.GetId()) + 1;
for (int e = 0; e < NodeI.GetOutDeg(); e++) {
const int DstNId = NodeIdH.GetKeyId(NodeI.GetOutNId(e)) + 1; // no self edges
if (NodeId != DstNId) AdjMtx.At(NodeId, DstNId) = 1;
}
}
try { // can fail to converge but results seem to be good
TSvd::Svd1Based(AdjMtx, LSingV, SngValV, RSingV); }
catch(...) {
printf("\n***No SVD convergence: G(%d, %d)\n", Nodes, Graph->GetEdges()); }
} else { // Lanczos
TNGraphMtx GraphMtx(Graph);
TSparseSVD::LanczosSVD(GraphMtx, 1, 8, ssotFull, SngValV, LSingV, RSingV);
}
TFlt MxSngVal = TFlt::Mn;
int ValN = 0;
for (int i = 0; i < SngValV.Len(); i++) {
if (MxSngVal < SngValV[i]) { MxSngVal = SngValV[i]; ValN = i; } }
LSingV.GetCol(ValN, LeftSV);
RSingV.GetCol(ValN, RightSV);
IsAllValVNeg(LeftSV, true);
IsAllValVNeg(RightSV, true);
}
示例5: DirectedModularity
double DirectedModularity(PNGraph& graph, std::vector<int>& communities) {
if (graph->GetNodes() != communities.size()) {
throw std::logic_error("Number of nodes does not match community size.");
}
int num_edges = graph->GetEdges();
double score = 0.0;
int num_unique = 10;
std::map<int, double> outdeg_sums;
std::map<int, double> indeg_sums;
for (TNGraph::TNodeI node = graph->BegNI(); node < graph->EndNI(); node++) {
int comm = communities[node.GetId()];
outdeg_sums[comm] += node.GetOutDeg();
indeg_sums[comm] += node.GetInDeg();
}
for (auto& kv : outdeg_sums) {
score -= (kv.second / num_edges) * indeg_sums[kv.first];
}
for (TNGraph::TNodeI node = graph->BegNI(); node < graph->EndNI(); node++) {
int node_ID = node.GetId();
for (int e = 0; e < node.GetOutDeg(); ++e) {
int nbr = node.GetOutNId(e);
if (communities[node_ID] == communities[nbr]) {
score += 1.0;
}
}
}
return score / num_edges;
}
示例6: GraphSONNodes
//GraphSON Node Formatting
std::string GraphSONNodes(const PNGraph & graph){
std::string nodes;
for (PNGraph::TObj::TNodeI NI = graph->BegNI(); NI < graph->EndNI(); ) {
nodes.append("{ \"id\": \"");
nodes.append(Helper::intToString(NI.GetId()));
nodes.append("\" }");
if (NI++ == graph->EndNI())
nodes.append(" ],\n");
else
nodes.append(",\n");
}
return nodes;
}
示例7: TakeSig
void TGraphKey::TakeSig(const PNGraph& Graph, const int& MnSvdGraph, const int& MxSvdGraph) {
const int Edges = Graph->GetEdges();
Nodes = Graph->GetNodes();
VariantId = 0;
SigV.Gen(2+Nodes, 0);
// degree sequence
TIntPrV DegV(Nodes, 0);
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
DegV.Add(TIntPr(NodeI.GetInDeg(), NodeI.GetOutDeg()));
}
DegV.Sort(false);
SigV.Add(TFlt(Nodes));
SigV.Add(TFlt(Edges));
for (int i = 0; i < DegV.Len(); i++) {
SigV.Add(DegV[i].Val1());
SigV.Add(DegV[i].Val2());
}
// singular values signature
// it turns out that it is cheaper to do brute force isomorphism
// checking than to calculate SVD and then check isomorphism
if (Nodes >= MnSvdGraph && Nodes < MxSvdGraph) {
// perform full SVD
TFltVV AdjMtx(Nodes+1, Nodes+1);
TFltV SngValV;
TFltVV LSingV, RSingV;
TIntH NodeIdH;
// create adjecency matrix
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
NodeIdH.AddKey(NodeI.GetId());
}
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
const int NodeId = NodeIdH.GetKeyId(NodeI.GetId()) + 1;
for (int e = 0; e < NodeI.GetOutDeg(); e++) {
const int DstNId = NodeIdH.GetKeyId(NodeI.GetOutNId(e)) + 1; // no self edges
if (NodeId != DstNId) AdjMtx.At(NodeId, DstNId) = 1;
}
}
try { // can fail to converge but results seem to be good
TSvd::Svd(AdjMtx, LSingV, SngValV, RSingV);
} catch(...) {
printf("\n***No SVD convergence: G(%d, %d): SngValV.Len():%d\n", Nodes(), Graph->GetEdges(), SngValV.Len());
}
// round singular values
SngValV.Sort(false);
for (int i = 0; i < SngValV.Len(); i++) {
SigV.Add(TMath::Round(SngValV[i], RoundTo));
}
}
//printf("SIG:\n"); for (int i = 0; i < SigV.Len(); i++) { printf("\t%f\n", SigV[i]); }
SigV.Pack();
}
示例8: GetSngVals
void GetSngVals(const PNGraph& Graph, const int& SngVals, TFltV& SngValV) {
const int Nodes = Graph->GetNodes();
IAssert(SngVals > 0);
if (Nodes < 100) {
// perform full SVD
TFltVV AdjMtx(Nodes+1, Nodes+1);
TFltVV LSingV, RSingV;
TIntH NodeIdH;
// create adjecency matrix
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
NodeIdH.AddKey(NodeI.GetId()); }
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
const int NodeId = NodeIdH.GetKeyId(NodeI.GetId()) + 1;
for (int e = 0; e < NodeI.GetOutDeg(); e++) {
const int DstNId = NodeIdH.GetKeyId(NodeI.GetOutNId(e)) + 1; // no self edges
if (NodeId != DstNId) AdjMtx.At(NodeId, DstNId) = 1;
}
}
try { // can fail to converge but results seem to be good
TSvd::Svd1Based(AdjMtx, LSingV, SngValV, RSingV); }
catch(...) {
printf("\n***No SVD convergence: G(%d, %d)\n", Nodes, Graph->GetEdges()); }
} else {
// Lanczos
TNGraphMtx GraphMtx(Graph);
int CalcVals = int(2*SngVals);
//if (CalcVals > Nodes) { CalcVals = int(2*Nodes); }
//if (CalcVals > Nodes) { CalcVals = Nodes; }
//while (SngValV.Len() < SngVals && CalcVals < 10*SngVals) {
try {
if (SngVals > 4) {
TSparseSVD::SimpleLanczosSVD(GraphMtx, 2*SngVals, SngValV, false); }
else { TFltVV LSingV, RSingV; // this is much more precise, but also much slower
TSparseSVD::LanczosSVD(GraphMtx, SngVals, 3*SngVals, ssotFull, SngValV, LSingV, RSingV); }
}
catch(...) {
printf("\n ***EXCEPTION: TRIED %d GOT %d values** \n", 2*SngVals, SngValV.Len()); }
if (SngValV.Len() < SngVals) {
printf(" ***TRIED %d GOT %d values** \n", CalcVals, SngValV.Len()); }
// CalcVals += SngVals;
//}
}
SngValV.Sort(false);
//if (SngValV.Len() > SngVals) {
// SngValV.Del(SngVals, SngValV.Len()-1); }
//else {
// while (SngValV.Len() < SngVals) SngValV.Add(1e-6); }
//IAssert(SngValV.Len() == SngVals);
}
示例9: TakeGraph
// renumbers nodes
void TGraphKey::TakeGraph(const PNGraph& Graph) {
TIntH NodeIdH;
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
NodeIdH.AddKey(NI.GetId()); }
Nodes = Graph->GetNodes();
EdgeV.Gen(Nodes, 0);
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
const int NewNId = NodeIdH.GetKeyId(NI.GetId());
for (int i = 0; i < NI.GetOutDeg(); i++) {
EdgeV.Add(TIntPr(NewNId, NodeIdH.GetKeyId(NI.GetOutNId(i))));
}
}
EdgeV.Sort(true);
EdgeV.Pack();
}
示例10: IOGViz
// Save directed, undirected and multi-graphs in GraphVizp .DOT format
void IOGViz() {
const int NNodes = 500;
const int NEdges = 2000;
const char *FName1 = "demo1.dot.dat", *FName2 = "demo2.dot.dat";
const char *Desc = "Randomly generated GgraphVizp for input/output.";
PNGraph GOut; // Can be PNEGraph or PUNGraph
GOut = GenRndGnm<PNGraph>(NNodes, NEdges);
SaveGViz(GOut, FName1);
// Output node IDs as numbers
TIntStrH NIdLabelH;
// Generate labels for random graph
for (TNGraph::TNodeI NI = GOut->BegNI(); NI < GOut->EndNI(); NI++) {
NIdLabelH.AddDat(NI.GetId(), TStr::Fmt("Node%d", NI.GetId()));
}
SaveGViz(GOut, FName2, Desc, NIdLabelH);
PrintGStats("IOGViz - In", GOut);
}
示例11: GDFNodes
//GDF Node Formatting
std::string GDFNodes(const PNGraph & graph){
std::string nodes;
for (PNGraph::TObj::TNodeI NI = graph->BegNI(); NI < graph->EndNI(); NI++){
nodes.append(Helper::intToString(NI.GetId()));
nodes.append("\n");
}
return nodes;
}
示例12: GetNormalizedMap
/////////////////////////////////////////////////
// TGraphEnumUtils implementation
void TGraphEnumUtils::GetNormalizedMap(const PNGraph &G, THash<TInt,TInt> &map) {
int nId=0;
for(TNGraph::TNodeI it=G->BegNI(); it<G->EndNI(); it++) {
//printf("%d -> %d\n", it.GetId(), nId);
map.AddDat(it.GetId(), nId);
nId++;
}
}
示例13: UndirCopy
void UndirCopy(PNGraph& dir_graph, PUNGraph& undir_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();
undir_graph->AddNode(curr_node);
}
for (TNGraph::TNodeI node = dir_graph->BegNI(); node < dir_graph->EndNI();
node++) {
int curr_node = node.GetId();
for (int e = 0; e < node.GetOutDeg(); ++e) {
int nbr_node = node.GetOutNId(e);
if (!undir_graph->IsEdge(curr_node, nbr_node)) {
undir_graph->AddEdge(curr_node, nbr_node);
}
}
}
}
示例14: gdf
void gdf(PNGraph Graph){
std::ofstream graph;
graph.open("graph.gdf");
graph << "nodedef>name VARCHAR\n";
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++)
graph << NI.GetId() << ",\n";
graph << "edgedef>node1 VARCHAR,node2 VARCHAR\n";
for (TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++)
graph << EI.GetSrcNId() << "," << EI.GetDstNId() << "\n";
graph.close();
}
示例15: analyzeSimNetProps
void analyzeSimNetProps(TStr messGraph, TStr netGraph) {
// Make graphs
PNGraph eGraph = TSnap::LoadEdgeListStr<PNGraph>(netGraph, 0, 1);
PNGraph mGraph = TSnap::LoadEdgeListStr<PNGraph>(messGraph, 0, 1);
PNGraph randGraph = TSnap::GenRndGnm<PNGraph>(mGraph->GetNodes(), mGraph->GetEdges(), true, TInt::Rnd);
// Induce network graph from the entire network based on message graph
TIntV NIdV;
for (TNGraph::TNodeI NI = mGraph->BegNI(); NI < mGraph->EndNI(); NI++)
NIdV.AddUnique(NI.GetId());
PNGraph indGraph = TSnap::GetSubGraph<PNGraph>(eGraph, NIdV);
//printf("%s:: ", messGraph.CStr()); printf("nodes %d; ", indGraph->GetNodes());
//printf("induced edges %d, random edges %d\n", indGraph->GetEdges(), randGraph->GetEdges());
printf("%d\t%d\t%d\n", indGraph->GetNodes(), indGraph->GetEdges(), mGraph->GetEdges());
}