本文整理汇总了C++中tngraph::TNodeI::GetOutNId方法的典型用法代码示例。如果您正苦于以下问题:C++ TNodeI::GetOutNId方法的具体用法?C++ TNodeI::GetOutNId怎么用?C++ TNodeI::GetOutNId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tngraph::TNodeI
的用法示例。
在下文中一共展示了TNodeI::GetOutNId方法的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: Edge
void TSubGraphsEnum::RecurBfs1(const int& NId, const int& Depth) {
if (Depth == 0) {
TIntPrV EdgeV;
EdgeH.GetKeyV(EdgeV);
EdgeV.Sort();
SgV.Add(EdgeV);
return;
}
const TNGraph::TNodeI NI = NGraph ->GetNI(NId);
for (int e = 0; e < NI.GetOutDeg(); e++) {
const TIntPr Edge(NId, NI.GetOutNId(e));
if (! EdgeH.IsKey(Edge)) {
EdgeH.AddKey(Edge);
RecurBfs1(NI.GetOutNId(e), Depth-1);
EdgeH.DelKey(Edge);
}
}
for (int e = 0; e < NI.GetInDeg(); e++) {
const TIntPr Edge(NI.GetInNId(e), NId);
if (! EdgeH.IsKey(Edge)) {
EdgeH.AddKey(Edge);
RecurBfs1(NI.GetInNId(e), Depth-1);
EdgeH.DelKey(Edge);
}
}
}
示例3: GetMergeSortedV1
// improved version
void GetMergeSortedV1(TIntV& NeighbourV, TNGraph::TNodeI NI) {
int j = 0;
int k = 0;
int prev = -1;
int indeg = NI.GetInDeg();
int outdeg = NI.GetOutDeg();
//while (j < NI.GetInDeg() && k < NI.GetOutDeg()) {
if (indeg > 0 && outdeg > 0) {
int v1 = NI.GetInNId(j);
int v2 = NI.GetOutNId(k);
while (1) {
if (v1 <= v2) {
if (prev != v1) {
NeighbourV.Add(v1);
prev = v1;
}
j += 1;
if (j >= indeg) {
break;
}
v1 = NI.GetInNId(j);
} else {
if (prev != v2) {
NeighbourV.Add(v2);
prev = v2;
}
k += 1;
if (k >= outdeg) {
break;
}
v2 = NI.GetOutNId(k);
}
}
}
while (j < indeg) {
int v = NI.GetInNId(j);
if (prev != v) {
NeighbourV.Add(v);
prev = v;
}
j += 1;
}
while (k < outdeg) {
int v = NI.GetOutNId(k);
if (prev != v) {
NeighbourV.Add(v);
prev = v;
}
k += 1;
}
}
示例4: KeepAtMostOneChildPerNode
void TIncrementalClustering::KeepAtMostOneChildPerNode(PNGraph& G, TQuoteBase *QB, TDocBase *DB) {
TIntSet::TIter EndNode = AffectedNodes.EndI();
for (TIntSet::TIter NodeId = AffectedNodes.BegI(); NodeId < EndNode; NodeId++) {
TNGraph::TNodeI Node = G->GetNI(NodeId.GetKey());
TQuote SourceQuote;
if (QB->GetQuote(Node.GetId(), SourceQuote)) {
TInt NodeDegree = Node.GetOutDeg();
if (NodeDegree > 1) {
TFlt MaxScore = 0;
TInt MaxNodeId = 0;
TIntV NodeV;
// first pass: check to see if we are pointing to any old nodes - if so, they get higher
// priority over the new ones for edge selection.
bool ContainsOldNode = false;
for (int i = 0; i < NodeDegree; ++i) {
if (!NewQuotes.IsKey(Node.GetOutNId(i))) {
ContainsOldNode = true;
}
}
// modified edge selection: filter out new nodes if old ones exist.
for (int i = 0; i < NodeDegree; ++i) {
TInt CurNode = Node.GetOutNId(i);
NodeV.Add(CurNode);
TQuote DestQuote;
if (QB->GetQuote(CurNode, DestQuote)) {
TFlt EdgeScore = 0;
if (!ContainsOldNode || !NewQuotes.IsKey(Node.GetOutNId(i))) {
EdgeScore = ComputeEdgeScore(SourceQuote, DestQuote, DB);
}
if (EdgeScore > MaxScore) {
MaxScore = EdgeScore;
MaxNodeId = CurNode;
}
}
}
// remove all other edges, backwards to prevent indexing fail
for (int i = 0; i < NodeV.Len(); i++) {
if (NodeV[i] != MaxNodeId) {
G->DelEdge(Node.GetId(), NodeV[i]);
}
}
//printf("Out degree: %d out of %d\n", Node.GetOutDeg(), NodeDegree.Val);
}
}
}
fprintf(stderr, "finished deleting edges\n");
}
示例5: GetSubGraph
TIntNNet TMultimodalGraphImplB::GetSubGraph(const TIntV ModeIds) const {
TIntNNet SubGraph = TIntNNet();
for (THash<TInt,TInt>::TIter CurI = NodeToModeMapping.BegI(); CurI < NodeToModeMapping.EndI(); CurI++) {
if (ModeIds.IsIn(CurI.GetDat())) {
SubGraph.AddNode(CurI.GetKey(), CurI.GetDat());
}
}
for (int ModeIdx1 = 0; ModeIdx1 < ModeIds.Len(); ModeIdx1++) {
int ModeId1 = ModeIds.GetVal(ModeIdx1);
for (int ModeIdx2 = 0; ModeIdx2 < ModeIds.Len(); ModeIdx2++) {
int ModeId2 = ModeIds.GetVal(ModeIdx2);
TPair<TInt,TInt> ModeIdsKey = GetModeIdsKey(ModeId1, ModeId2);
if (!Graphs.IsKey(ModeIdsKey)) { continue; }
const TNGraph& Graph = Graphs.GetDat(ModeIdsKey);
for (TNGraph::TNodeI it = Graph.BegNI(); it < Graph.EndNI(); it++) {
for (int e = 0; e < it.GetOutDeg(); e++) {
SubGraph.AddEdge(it.GetId(), it.GetOutNId(e));
}
}
}
}
printf("Number of nodes in SubGraph: %d...\n", SubGraph.GetNodes());
printf("Number of edges in SubGraph: %d...\n", SubGraph.GetEdges());
return SubGraph;
}
示例6: 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;
}
示例7: 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);
}
示例8: TIntPr
void TSubGraphsEnum::Gen2Graphs() {
// singe edge sub-graphs
SgV.Gen(NGraph->GetEdges(), 0);
TSimpleGraph SimpleG;
TIntPrV& EdgeV = SimpleG.GetEdgeV();
EdgeV.Gen(1);
for (TNGraph::TNodeI NI = NGraph->BegNI(); NI < NGraph->EndNI(); NI++) {
for (int e = 0; e < NI.GetOutDeg(); e++) {
EdgeV[0] = TIntPr(NI.GetId(), NI.GetOutNId(e));
SgV.Add(SimpleG);
}
}
SgV.Sort();
// two edge sub-graphs
EdgeV.Gen(2);
for (int g1 = 0; g1 < SgV.Len()-1; g1++) {
const TIntPr& E1 = SgV[g1].GetEdgeV()[0];
for (int g2 = g1+1; g2 < SgV.Len(); g2++) {
const TIntPr& E2 = SgV[g2].GetEdgeV()[0];
if (E1.Val2 == E2.Val1 || E1.Val1 == E2.Val2 || E1.Val1 == E2.Val1 || E1.Val2 == E2.Val2) {
EdgeV[0] = TMath::Mn(E1, E2);
EdgeV[1] = TMath::Mx(E1, E2);
SimpleG.Dump();
NextSgV.Add(SimpleG);
}
}
}
SgV.MoveFrom(NextSgV);
}
示例9: GetSubGraphMocked
int TMultimodalGraphImplB::GetSubGraphMocked(const TIntV ModeIds) const {
int NumVerticesAndEdges = 0;
for (THash<TInt,TInt>::TIter CurI = NodeToModeMapping.BegI(); CurI < NodeToModeMapping.EndI(); CurI++) {
if (ModeIds.IsIn(CurI.GetDat())) {
NumVerticesAndEdges++;
}
}
for (int ModeIdx1 = 0; ModeIdx1 < ModeIds.Len(); ModeIdx1++) {
int ModeId1 = ModeIds.GetVal(ModeIdx1);
for (int ModeIdx2 = 0; ModeIdx2 < ModeIds.Len(); ModeIdx2++) {
int ModeId2 = ModeIds.GetVal(ModeIdx2);
TPair<TInt,TInt> ModeIdsKey = GetModeIdsKey(ModeId1, ModeId2);
if (!Graphs.IsKey(ModeIdsKey)) { continue; }
const TNGraph& Graph = Graphs.GetDat(ModeIdsKey);
for (TNGraph::TNodeI it = Graph.BegNI(); it < Graph.EndNI(); it++) {
for (int e = 0; e < it.GetOutDeg(); e++) {
NumVerticesAndEdges += it.GetOutNId(e);
}
}
}
}
return NumVerticesAndEdges;
}
示例10: PruneGraph
void TGraphCascade::PruneGraph() {
// iterate over nodes
int Nodes = NodeNmIdH.Len();
TIntV NodeIdV; NodeNmIdH.GetDatV(NodeIdV);
TStrV NodeNmV; NodeNmIdH.GetKeyV(NodeNmV);
for (int NodeN = 0; NodeN < Nodes; NodeN++) {
int NodeId = NodeIdV[NodeN];
if (!EnabledNodeIdH.IsKey(NodeId)) {
// if a node is not enabled:
// - connect its parents to its children
TNGraph::TNodeI NI = Graph.GetNI(NodeId);
for (int ParentN = 0; ParentN < NI.GetInDeg(); ParentN++) {
for (int ChildN = 0; ChildN < NI.GetOutDeg(); ChildN++) {
if (!Graph.IsEdge(NI.GetInNId(ParentN), NI.GetOutNId(ChildN))) {
Graph.AddEdge(NI.GetInNId(ParentN), NI.GetOutNId(ChildN));
}
}
}
//printf("deleting node %s %d\n", NodeNmV[NodeN].CStr(), NodeId);
// - delete it (deletes edges)
Graph.DelNode(NodeId);
}
}
// generate search sequence from sinks to sources
TopologicalSort(NIdSweep);
//Print(NIdSweep);
}
示例11: BurnExpFire
// burn each link independently (forward with FwdBurnProb, backward with BckBurnProb)
void TForestFire::BurnExpFire() {
const double OldFwdBurnProb = FwdBurnProb;
const double OldBckBurnProb = BckBurnProb;
const int NInfect = InfectNIdV.Len();
const TNGraph& G = *Graph;
TIntH BurnedNIdH; // burned nodes
TIntV BurningNIdV = InfectNIdV; // currently burning nodes
TIntV NewBurnedNIdV; // nodes newly burned in current step
bool HasAliveNbrs; // has unburned neighbors
int NBurned = NInfect, NDiedFire=0;
for (int i = 0; i < InfectNIdV.Len(); i++) {
BurnedNIdH.AddDat(InfectNIdV[i]); }
NBurnedTmV.Clr(false); NBurningTmV.Clr(false); NewBurnedTmV.Clr(false);
for (int time = 0; ; time++) {
NewBurnedNIdV.Clr(false);
// for each burning node
for (int node = 0; node < BurningNIdV.Len(); node++) {
const int& BurningNId = BurningNIdV[node];
const TNGraph::TNodeI Node = G.GetNI(BurningNId);
HasAliveNbrs = false;
NDiedFire = 0;
// burn forward links (out-links)
for (int e = 0; e < Node.GetOutDeg(); e++) {
const int OutNId = Node.GetOutNId(e);
if (! BurnedNIdH.IsKey(OutNId)) { // not yet burned
HasAliveNbrs = true;
if (Rnd.GetUniDev() < FwdBurnProb) {
BurnedNIdH.AddDat(OutNId); NewBurnedNIdV.Add(OutNId); NBurned++; }
}
}
// burn backward links (in-links)
if (BckBurnProb > 0.0) {
for (int e = 0; e < Node.GetInDeg(); e++) {
const int InNId = Node.GetInNId(e);
if (! BurnedNIdH.IsKey(InNId)) { // not yet burned
HasAliveNbrs = true;
if (Rnd.GetUniDev() < BckBurnProb) {
BurnedNIdH.AddDat(InNId); NewBurnedNIdV.Add(InNId); NBurned++; }
}
}
}
if (! HasAliveNbrs) { NDiedFire++; }
}
NBurnedTmV.Add(NBurned);
NBurningTmV.Add(BurningNIdV.Len() - NDiedFire);
NewBurnedTmV.Add(NewBurnedNIdV.Len());
//BurningNIdV.AddV(NewBurnedNIdV); // node is burning eternally
BurningNIdV.Swap(NewBurnedNIdV); // node is burning just 1 time step
if (BurningNIdV.Empty()) break;
FwdBurnProb = FwdBurnProb * ProbDecay;
BckBurnProb = BckBurnProb * ProbDecay;
}
BurnedNIdV.Gen(BurnedNIdH.Len(), 0);
for (int i = 0; i < BurnedNIdH.Len(); i++) {
BurnedNIdV.Add(BurnedNIdH.GetKey(i)); }
FwdBurnProb = OldFwdBurnProb;
BckBurnProb = OldBckBurnProb;
}
示例12: GetAllNeighbors
void TempMotifCounter::GetAllNeighbors(int node, TIntV& nbrs) {
nbrs = TIntV();
TNGraph::TNodeI NI = static_graph_->GetNI(node);
for (int i = 0; i < NI.GetOutDeg(); i++) { nbrs.Add(NI.GetOutNId(i)); }
for (int i = 0; i < NI.GetInDeg(); i++) {
int nbr = NI.GetInNId(i);
if (!NI.IsOutNId(nbr)) { nbrs.Add(nbr); }
}
}
示例13: JaccardSim
float JaccardSim(TNGraph::TNodeI NI1, TNGraph::TNodeI NI2) {
int lenA = NI1.GetOutDeg();
int lenB = NI2.GetOutDeg();
int ct = 0;
int j = 0;
int i = 0;
while (i < lenA && j < lenB) {
if (NI1.GetOutNId(i) == NI2.GetOutNId(j)) {
ct++; i++; j++;
} else if (NI1.GetOutNId(i) > NI2.GetOutNId(j)) {
j++;
} else {
i++;
}
}
return ct*1.0/(lenA+lenB-ct);
}
示例14: TopologicalSort
void TGraphCascade::TopologicalSort(TIntV& SortedNIdV) {
int Nodes = Graph.GetNodes();
SortedNIdV.Gen(Nodes, 0); // result
THash<TInt, TBool> Marks(Nodes); // nodeid -> mark map
THash<TInt,TBool> TempMarks(Nodes); // nodeid -> temp mark map
THash<TInt, TBool> Added(Nodes);
TIntV NIdV; Graph.GetNIdV(NIdV); // all node ids
// set marks
for (int NodeN = 0; NodeN < Nodes; NodeN++) {
int NodeId = NIdV[NodeN];
Marks.AddDat(NodeId, false);
TempMarks.AddDat(NodeId, false);
Added.AddDat(NodeId, false);
}
TSStack<TInt> Stack;
for (int NodeN = 0; NodeN < Nodes; NodeN++) {
int NodeId = NIdV[NodeN];
// select an unmarked node
if (!Marks.GetDat(NodeId)) {
Stack.Push(NodeId);
while (!Stack.Empty()) {
// visit TopNode
int TopNodeId = Stack.Top();
Marks.GetDat(TopNodeId) = true;
TempMarks.GetDat(TopNodeId) = true;
// add children, set their temp marks to true
TNGraph::TNodeI NI = Graph.GetNI(TopNodeId);
int Children = NI.GetOutDeg();
bool IsFinal = true;
for (int ChildN = 0; ChildN < Children; ChildN++) {
int ChildId = NI.GetOutNId(ChildN);
EAssertR(!TempMarks.GetDat(ChildId), "TGraphCascade::TopologicalSort: the graph is not a DAG!");
if (!Marks.GetDat(ChildId)) {
// unvisited node
IsFinal = false;
Stack.Push(ChildId);
}
}
if (IsFinal) {
// push TopNode to tail
if (!Added.GetDat(TopNodeId)) {
SortedNIdV.Add(TopNodeId);
Added.GetDat(TopNodeId) = true;
}
TempMarks.GetDat(TopNodeId) = false;
Stack.Pop();
}
}
}
}
SortedNIdV.Reverse();
}
示例15: GetSubGraph
// RenumberNodes ... Renumber node ids in the subgraph to 0...N-1
PNGraph GetSubGraph(const PNGraph& Graph, const TIntV& NIdV, const bool& RenumberNodes) {
//if (! RenumberNodes) { return TSnap::GetSubGraph(Graph, NIdV); }
PNGraph NewGraphPt = TNGraph::New();
TNGraph& NewGraph = *NewGraphPt;
NewGraph.Reserve(NIdV.Len(), -1);
TIntSet NIdSet(NIdV.Len());
for (int n = 0; n < NIdV.Len(); n++) {
if (Graph->IsNode(NIdV[n])) {
NIdSet.AddKey(NIdV[n]);
if (! RenumberNodes) {
NewGraph.AddNode(NIdV[n]);
}
else {
NewGraph.AddNode(NIdSet.GetKeyId(NIdV[n]));
}
}
}
if (! RenumberNodes) {
for (int n = 0; n < NIdSet.Len(); n++) {
const int SrcNId = NIdSet[n];
const TNGraph::TNodeI NI = Graph->GetNI(SrcNId);
for (int edge = 0; edge < NI.GetOutDeg(); edge++) {
const int OutNId = NI.GetOutNId(edge);
if (NIdSet.IsKey(OutNId)) {
NewGraph.AddEdge(SrcNId, OutNId);
}
}
}
} else {
for (int n = 0; n < NIdSet.Len(); n++) {
const int SrcNId = NIdSet[n];
const TNGraph::TNodeI NI = Graph->GetNI(SrcNId);
for (int edge = 0; edge < NI.GetOutDeg(); edge++) {
const int OutNId = NI.GetOutNId(edge);
if (NIdSet.IsKey(OutNId)) {
NewGraph.AddEdge(NIdSet.GetKeyId(SrcNId), NIdSet.GetKeyId(OutNId));
}
}
}
}
return NewGraphPt;
}