本文整理汇总了C++中TIntH类的典型用法代码示例。如果您正苦于以下问题:C++ TIntH类的具体用法?C++ TIntH怎么用?C++ TIntH使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TIntH类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindAugV
/// Returns the amount the flow can be augmented over the paths, 0 if no path can be found. ##TSnap::FindAugV
int FindAugV (const PNEANet &Net, const int& CapIndex, TIntV &Flow, TIntQ &FwdNodeQ, TIntH &PredEdgeH, TIntQ &BwdNodeQ, TIntH &SuccEdgeH, TIntV &MidToSrcAugV, TIntV &MidToSnkAugV, const int& SrcNId, const int& SnkNId) {
int MidPtNId = IntFlowBiDBFS(Net, CapIndex, Flow, FwdNodeQ, PredEdgeH, BwdNodeQ, SuccEdgeH, SrcNId, SnkNId);
if (MidPtNId == -1) { return 0; }
int MinAug = TInt::Mx, NId = MidPtNId, AugFlow = 0;
// Build the path from the midpoint back to the source by tracing through the PredEdgeH
for (int EId = PredEdgeH.GetDat(NId); NId != SrcNId; EId = PredEdgeH.GetDat(NId)) {
MidToSrcAugV.Add(EId);
const TNEANet::TEdgeI &EI = Net->GetEI(EId);
if (EI.GetSrcNId() == NId) {
NId = EI.GetDstNId();
AugFlow = Flow[EId];
} else {
NId = EI.GetSrcNId();
AugFlow = Net->GetIntAttrIndDatE(EId, CapIndex) - Flow[EId];
}
if (AugFlow < MinAug) { MinAug = AugFlow; }
}
NId = MidPtNId;
// Build the path from the midpoint back to the sink by tracing through the SuccEdgeH
for (int EId = SuccEdgeH.GetDat(NId); NId != SnkNId; EId = SuccEdgeH.GetDat(NId)) {
MidToSnkAugV.Add(EId);
const TNEANet::TEdgeI &EI = Net->GetEI(EId);
if (EI.GetDstNId() == NId) {
NId = EI.GetSrcNId();
AugFlow = Flow[EId];
} else {
NId = EI.GetDstNId();
AugFlow = Net->GetIntAttrIndDatE(EId, CapIndex) - Flow[EId];
}
if (AugFlow < MinAug) { MinAug = AugFlow; }
}
return MinAug;
}
示例2: DocStrToWIdV
//////////////////////////////////////////////////////////////////////////
// String-To-Words
void TStrParser::DocStrToWIdV(const TStr& _DocStr, TIntV& WordIdV, const bool& Stemm) {
TStr DocStr = _DocStr.GetUc(); // to upper case
TStrV WordV; DocStr.SplitOnWs(WordV); int WordN = WordV.Len();
WordIdV.Reserve(WordN, 0);
PStemmer Stemmer = TStemmer::New(stmtPorter);
TIntH WordsInDoc;
for (int WordC = 0; WordC < WordN; WordC++) {
TStr WordStr;
if (Stemm) {
WordStr = Stemmer->GetStem(WordV[WordC]);
} else {
WordStr = WordV[WordC];
}
int WId = GetWId(WordStr);
if (WId == -1) {
WId = WordToIdH.AddKey(WordStr);
WordToIdH[WId] = 0;
}
WordIdV.Add(WId);
// is it first time we see this word in this doc?
if (!WordsInDoc.IsKey(WId)) WordsInDoc.AddKey(WId);
}
//do some statistics for DF
DocsParsed++;
for (int i = 0, l = WordsInDoc.Len(); i < l; i++)
WordToIdH[WordsInDoc.GetKey(i)]++;
Assert(WordV.Len() == WordIdV.Len());
}
示例3: 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);
}
}
}
示例4: GetGroupFarnessCentr
double GetGroupFarnessCentr(const PUNGraph& Graph, const TIntH& GroupNodes) {
TIntH* NDistH = new TIntH[GroupNodes.Len()];
for (int i = 0; i<GroupNodes.Len(); i++){
NDistH[i](Graph->GetNodes());
TSnap::GetShortPath<PUNGraph>(Graph, GroupNodes.GetDat(i), NDistH[i], true, TInt::Mx);
}
int min, dist, sum = 0, len = 0;
for (PUNGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++){
if (NDistH[0].IsKey(NI.GetId()))
min = NDistH[0].GetDat(NI.GetId());
else
min = -1;
for (int j = 1; j<GroupNodes.Len(); j++){
if (NDistH[j].IsKey(NI.GetId()))
dist = NDistH[j].GetDat(NI.GetId());
else
dist = -1;
if ((dist < min && dist != -1) || (dist > min && min == -1))
min = dist;
}
if (min>0){
sum += min;
len++;
}
}
if (len > 0) { return sum / double(len); }
else { return 0.0; }
}
示例5: 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);
}
示例6: FOut
void TGreedyAlg::saveOutputAdjacencyMatrix(const TStr& outputNetworkFilename) {
TFOut FOut(outputNetworkFilename);
// create adjacency matrix
const int noNodes = outputGraph->GetNodes();
TFltVV AdjMtx(noNodes, noNodes);
TIntH NodeIdH;
for (TKColourNet::TNodeI NI = outputGraph->BegNI(); NI < outputGraph->EndNI(); NI++) {
NodeIdH.AddKey(NI.GetId());
}
for (TKColourNet::TNodeI NI = outputGraph->BegNI(); NI < outputGraph->EndNI(); NI++) {
const int NodeId = NodeIdH.GetKeyId(NI.GetId());
for (int e = 0; e < NI.GetOutDeg(); e++) {
const int DstNId = NodeIdH.GetKeyId(NI.GetOutNId(e));
// no self edges
if (NodeId != DstNId) {
AdjMtx.At(NodeId, DstNId) = 1;
}
}
}
for (int row = 0; row < AdjMtx.GetRows(); row++) {
for (int col = 0; col < AdjMtx.GetCols(); col++) {
FOut.PutStr(TStr::Fmt("%d,", (int) AdjMtx.At(row, col)));
}
FOut.PutStr("\r\n");
}
// printf("Saved Adjacency matrix with : noRows = %d, noCols = %d\n", AdjMtx.GetRows(), AdjMtx.GetCols());
}
示例7: GetNodeMembership
/// get hash table of <Node ID, membership size>
void TAGMUtil::GetNodeMembership(TIntH& NIDComVH, const THash<TInt,TIntV >& CmtyVH) {
NIDComVH.Clr();
for (THash<TInt,TIntV>::TIter HI = CmtyVH.BegI(); HI < CmtyVH.EndI(); HI++) {
for (int j = 0; j < HI.GetDat().Len(); j++) {
int NID = HI.GetDat()[j];
NIDComVH.AddDat(NID)++;
}
}
}
示例8: GetBiConSzCnt
void GetBiConSzCnt(const PUNGraph& Graph, TIntPrV& SzCntV) {
TCnComV BiCnComV;
GetBiCon(Graph, BiCnComV);
TIntH SzCntH;
for (int c =0; c < BiCnComV.Len(); c++) {
SzCntH.AddDat(BiCnComV[c].Len()) += 1;
}
SzCntH.GetKeyDatPrV(SzCntV);
SzCntV.Sort();
}
示例9: Add
void TFtrGenSparseNumeric::Add(const TStr& Str, TIntFltKdV& SpV, int& Offset) const {
TStrV EltV; Str.SplitOnAllCh(';', EltV); TIntH UsedIdH;
for (int EltN = 0; EltN < EltV.Len(); EltN++) {
int Id; TStr Val; Split(EltV[EltN], Id, Val);
EAssertR(!UsedIdH.IsKey(Id), "Field ID repeated in '" + Str + "'!");
int TmpOffset = Offset + Id;
FtrGen->Add(Val, SpV, TmpOffset);
UsedIdH.AddKey(Id);
}
Offset += GetVals();
}
示例10: Intersect
int Intersect(TUNGraph::TNodeI Node, TIntH NNodes){
int br = 0;
for (int i = 0; i<Node.GetDeg(); i++)
{
if (NNodes.IsKey(Node.GetNbrNId(i)))
br++;
}
if (NNodes.IsKey(Node.GetId()))
br++;
return br;
}
示例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: GetGroupDegreeCentr
double GetGroupDegreeCentr(const PUNGraph& Graph, const PUNGraph& Group) {
int deg;
TIntH NN;
for (TUNGraph::TNodeI NI = Group->BegNI(); NI < Group->EndNI(); NI++) {
deg = Graph->GetNI(NI.GetId()).GetDeg();
for (int i = 0; i<deg; i++) {
if (Group->IsNode(Graph->GetNI(NI.GetId()).GetNbrNId(i)) == 0)
NN.AddDat(Graph->GetNI(NI.GetId()).GetNbrNId(i), NI.GetId());
}
}
return (double)NN.Len();
}
示例13: DegV
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();
}
示例14: 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);
}
示例15: 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();
}