SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TCesnaUtil Class Reference

#include <agmattr.h>

Static Public Member Functions

template<class PGraph >
static double GetConductance (const PGraph &Graph, const TIntSet &CmtyS, const int Edges)
 
template<class PGraph >
static void GenHoldOutPairs (const PGraph &G, TVec< TIntSet > &HoldOutSet, double HOFrac, TRnd &Rnd)
 
template<class PGraph >
static void GetNbhCom (const PGraph &Graph, const int NID, TIntSet &NBCmtyS)
 
template<class PGraph >
static void GetNIdPhiV (const PGraph &G, TFltIntPrV &NIdPhiV)
 
static void LoadNIDAttrHFromNIDKH (const TIntV &NIDV, const TStr &InFNm, THash< TInt, TIntV > &NIDAttrH, const TStrHash< TInt > &NodeNameH, const TSsFmt Sep=ssfTabSep)
 
static void LoadNIDAttrHFromNIDKH (const TIntV &NIDV, const TStr &InFNm, THash< TInt, TIntV > &NIDAttrH)
 
static void DumpNIDAttrHToNIDK (const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH, const TStrHash< TInt > &FeatNameH, const TStrHash< TInt > &NodeNameH)
 
static void DumpNIDAttrHToNIDK (const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH, const TStrHash< TInt > &FeatNameH)
 
static void DumpNIDAttrHToNIDK (const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH)
 
static void DumpNIDAttrHToNIDK (const TStr &FNm, const THash< TInt, TIntV > &NIDAttrH, const TStrHash< TInt > &FeatNameH, const TStrHash< TInt > &NodeNameH)
 
static void DumpNIDAttrHToNIDK (const TStr &FNm, const THash< TInt, TIntV > &NIDAttrH, const TStrHash< TInt > &FeatNameH)
 
static void DumpNIDAttrHToNIDK (const TStr &FNm, const THash< TInt, TIntV > &NIDAttrH)
 
static int GetAttrs (const THash< TInt, TIntV > &NIDAttrH)
 
static void DumpNIDAttrHToMetis (const TStr &FNm, const THash< TInt, TIntV > &NIDAttrH, const TIntV &NIDV)
 
static void FilterLowEntropy (const THash< TInt, TIntV > &OldNIDAttrH, THash< TInt, TIntV > &NewNIDAttrH, const TIntStrH &OldNameH, TIntStrH &NewNameH, const double MinFrac=0.00001, const double MaxFrac=0.95, const int MinCnt=3)
 
static void FilterLowEntropy (const THash< TInt, TIntV > &OldNIDAttrH, THash< TInt, TIntV > &NewNIDAttrH, const double MinFrac=0.00001, const double MaxFrac=0.95, const int MinCnt=3)
 

Detailed Description

Definition at line 5 of file agmattr.h.

Member Function Documentation

static void TCesnaUtil::DumpNIDAttrHToMetis ( const TStr FNm,
const THash< TInt, TIntV > &  NIDAttrH,
const TIntV NIDV 
)
inlinestatic

Definition at line 179 of file agmattr.h.

References TStr::CStr(), THash< TKey, TDat, THashFunc >::GetDat(), IAssert, THash< TKey, TDat, THashFunc >::IsKey(), and TVec< TVal, TSizeTy >::Len().

179  {
180  int AttrCnt = 0;
181  for (int u = 1; u < NIDV.Len(); u++) {
182  if (! NIDAttrH.IsKey(NIDV[u])) { continue; }
183  AttrCnt += NIDAttrH.GetDat(NIDV[u]).Len();
184  }
185  IAssert (NIDV[0] == -1);
186  FILE* F = fopen(FNm.CStr(), "wt");
187  fprintf(F, "%d %d\n", NIDV.Len() - 1, AttrCnt);
188  int TmpCnt = 0;
189  for (int u = 1; u < NIDV.Len(); u++) {
190  if (NIDAttrH.IsKey(NIDV[u])) {
191  for (int k = 0; k < NIDAttrH.GetDat(NIDV[u]).Len(); k++) {
192  if (k > 0) { fprintf(F, " "); }
193  fprintf(F, "%d", NIDAttrH.GetDat(NIDV[u])[k].Val + 1);
194  TmpCnt++;
195  }
196  }
197  fprintf(F, "\n");
198  }
199  fclose(F);
200  IAssert(AttrCnt == TmpCnt);
201 
202  }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
char * CStr()
Definition: dt.h:476
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

static void TCesnaUtil::DumpNIDAttrHToNIDK ( const TStr FNm,
const THash< TInt, TIntSet > &  NIDAttrH,
const TStrHash< TInt > &  FeatNameH,
const TStrHash< TInt > &  NodeNameH 
)
inlinestatic

Definition at line 127 of file agmattr.h.

References TStr::CStr(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::GetKey(), TStrHash< TDat, TStringPool, THashFunc >::GetKey(), TStrHash< TDat, TStringPool, THashFunc >::IsKeyId(), and THash< TKey, TDat, THashFunc >::Len().

Referenced by DumpNIDAttrHToNIDK().

127  {
128  FILE* F = fopen(FNm.CStr(), "wt");
129  for (int u = 0; u < NIDAttrH.Len(); u++) {
130  int NID = NIDAttrH.GetKey(u);
131  TStr NodeName = NodeNameH.IsKeyId(NID)? NodeNameH.GetKey(NID): TStr::Fmt("%d", NID);
132  for (int k = 0; k < NIDAttrH[u].Len(); k++) {
133  int KID = NIDAttrH[u][k];
134  TStr FeatName = FeatNameH.IsKeyId(KID)? FeatNameH.GetKey(KID): TStr::Fmt("%d", KID);
135  fprintf(F,"%s\t%s\n", NodeName.CStr(), FeatName.CStr());
136  }
137  }
138  fclose(F);
139  }
const char * GetKey(const int &KeyId) const
Definition: hash.h:893
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
int Len() const
Definition: hash.h:228
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
bool IsKeyId(const int &KeyId) const
Definition: hash.h:904

Here is the call graph for this function:

Here is the caller graph for this function:

static void TCesnaUtil::DumpNIDAttrHToNIDK ( const TStr FNm,
const THash< TInt, TIntSet > &  NIDAttrH,
const TStrHash< TInt > &  FeatNameH 
)
inlinestatic

Definition at line 140 of file agmattr.h.

References DumpNIDAttrHToNIDK().

140  {
141  TStrHash<TInt> TmpH;
142  DumpNIDAttrHToNIDK(FNm, NIDAttrH, FeatNameH, TmpH);
143  }
static void DumpNIDAttrHToNIDK(const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH, const TStrHash< TInt > &FeatNameH, const TStrHash< TInt > &NodeNameH)
Definition: agmattr.h:127
Definition: hash.h:781

Here is the call graph for this function:

static void TCesnaUtil::DumpNIDAttrHToNIDK ( const TStr FNm,
const THash< TInt, TIntSet > &  NIDAttrH 
)
inlinestatic

Definition at line 144 of file agmattr.h.

References DumpNIDAttrHToNIDK().

144  {
145  TStrHash<TInt> TmpH1, TmpH2;
146  DumpNIDAttrHToNIDK(FNm, NIDAttrH, TmpH1, TmpH2);
147  }
static void DumpNIDAttrHToNIDK(const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH, const TStrHash< TInt > &FeatNameH, const TStrHash< TInt > &NodeNameH)
Definition: agmattr.h:127
Definition: hash.h:781

Here is the call graph for this function:

static void TCesnaUtil::DumpNIDAttrHToNIDK ( const TStr FNm,
const THash< TInt, TIntV > &  NIDAttrH,
const TStrHash< TInt > &  FeatNameH,
const TStrHash< TInt > &  NodeNameH 
)
inlinestatic

Definition at line 148 of file agmattr.h.

References TStr::CStr(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::GetKey(), TStrHash< TDat, TStringPool, THashFunc >::GetKey(), TStrHash< TDat, TStringPool, THashFunc >::IsKeyId(), and THash< TKey, TDat, THashFunc >::Len().

148  {
149  FILE* F = fopen(FNm.CStr(), "wt");
150  for (int u = 0; u < NIDAttrH.Len(); u++) {
151  int NID = NIDAttrH.GetKey(u);
152  TStr NodeName = NodeNameH.IsKeyId(NID)? NodeNameH.GetKey(NID): TStr::Fmt("%d", NID);
153  for (int k = 0; k < NIDAttrH[u].Len(); k++) {
154  int KID = NIDAttrH[u][k];
155  TStr FeatName = FeatNameH.IsKeyId(KID)? FeatNameH.GetKey(KID): TStr::Fmt("%d", KID);
156  fprintf(F,"%s\t%s\n", NodeName.CStr(), FeatName.CStr());
157  }
158  }
159  fclose(F);
160  }
const char * GetKey(const int &KeyId) const
Definition: hash.h:893
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
int Len() const
Definition: hash.h:228
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
bool IsKeyId(const int &KeyId) const
Definition: hash.h:904

Here is the call graph for this function:

static void TCesnaUtil::DumpNIDAttrHToNIDK ( const TStr FNm,
const THash< TInt, TIntV > &  NIDAttrH,
const TStrHash< TInt > &  FeatNameH 
)
inlinestatic

Definition at line 161 of file agmattr.h.

References DumpNIDAttrHToNIDK().

161  {
162  TStrHash<TInt> TmpH;
163  DumpNIDAttrHToNIDK(FNm, NIDAttrH, FeatNameH, TmpH);
164  }
static void DumpNIDAttrHToNIDK(const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH, const TStrHash< TInt > &FeatNameH, const TStrHash< TInt > &NodeNameH)
Definition: agmattr.h:127
Definition: hash.h:781

Here is the call graph for this function:

static void TCesnaUtil::DumpNIDAttrHToNIDK ( const TStr FNm,
const THash< TInt, TIntV > &  NIDAttrH 
)
inlinestatic

Definition at line 165 of file agmattr.h.

References DumpNIDAttrHToNIDK().

165  {
166  TStrHash<TInt> TmpH1, TmpH2;
167  DumpNIDAttrHToNIDK(FNm, NIDAttrH, TmpH1, TmpH2);
168  }
static void DumpNIDAttrHToNIDK(const TStr &FNm, const THash< TInt, TIntSet > &NIDAttrH, const TStrHash< TInt > &FeatNameH, const TStrHash< TInt > &NodeNameH)
Definition: agmattr.h:127
Definition: hash.h:781

Here is the call graph for this function:

static void TCesnaUtil::FilterLowEntropy ( const THash< TInt, TIntV > &  OldNIDAttrH,
THash< TInt, TIntV > &  NewNIDAttrH,
const TIntStrH OldNameH,
TIntStrH NewNameH,
const double  MinFrac = 0.00001,
const double  MaxFrac = 0.95,
const int  MinCnt = 3 
)
inlinestatic

Definition at line 203 of file agmattr.h.

References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::Empty(), THash< TKey, TDat, THashFunc >::Gen(), THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::GetKey(), THash< TKey, TDat, THashFunc >::IsKey(), THash< TKey, TDat, THashFunc >::Len(), and THash< TKey, TDat, THashFunc >::SortByDat().

Referenced by FilterLowEntropy().

203  {
204  TIntH KIDCntH;
205  for (int u = 0; u < OldNIDAttrH.Len(); u++) {
206  for (int k = 0; k < OldNIDAttrH[u].Len(); k++) {
207  KIDCntH.AddDat(OldNIDAttrH[u][k])++;
208  }
209  }
210  KIDCntH.SortByDat(false);
211 
212  TIntSet SelectedK(KIDCntH.Len());
213  for (int c = 0; c < KIDCntH.Len(); c++) {
214  double Frac = (double) KIDCntH[c].Val / (double) OldNIDAttrH.Len();
215  if (KIDCntH[c].Val < MinCnt) { continue; }
216  if (Frac > MaxFrac || Frac < MinFrac) { continue; }
217  SelectedK.AddKey(KIDCntH.GetKey(c));
218  }
219  printf("%d attributes selected from %d\n", SelectedK.Len(), KIDCntH.Len());
220  NewNIDAttrH.Gen(OldNIDAttrH.Len());
221  for (int u = 0; u < OldNIDAttrH.Len(); u++) {
222  int NID = OldNIDAttrH.GetKey(u);
223  TIntV& AttrV = NewNIDAttrH.AddDat(NID);
224  for (int k = 0; k < OldNIDAttrH[u].Len(); k++) {
225  if (! SelectedK.IsKey(OldNIDAttrH[u][k])) { continue; }
226  AttrV.Add(SelectedK.GetKeyId(OldNIDAttrH[u][k]));
227  }
228  }
229 
230  if (! OldNameH.Empty()) {
231  NewNameH.Gen(SelectedK.Len());
232  for (int k = 0; k < SelectedK.Len(); k++) {
233  int OldKID = SelectedK.GetKey(k);
234  if (OldNameH.IsKey(OldKID)) {
235  NewNameH.AddDat(k, OldNameH.GetDat(OldKID));
236  }
237  }
238  printf("%d attributes names copied\n", NewNameH.Len());
239  }
240  }
bool Empty() const
Definition: hash.h:227
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
void Gen(const int &ExpectVals)
Definition: hash.h:222
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int Len() const
Definition: hash.h:228
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
void SortByDat(const bool &Asc=true)
Definition: hash.h:292

Here is the call graph for this function:

Here is the caller graph for this function:

static void TCesnaUtil::FilterLowEntropy ( const THash< TInt, TIntV > &  OldNIDAttrH,
THash< TInt, TIntV > &  NewNIDAttrH,
const double  MinFrac = 0.00001,
const double  MaxFrac = 0.95,
const int  MinCnt = 3 
)
inlinestatic

Definition at line 241 of file agmattr.h.

References FilterLowEntropy().

241  {
242  TIntStrH TmpH1, TmpH2;
243  FilterLowEntropy(OldNIDAttrH, NewNIDAttrH, TmpH1, TmpH2, MinFrac, MaxFrac, MinCnt);
244  }
static void FilterLowEntropy(const THash< TInt, TIntV > &OldNIDAttrH, THash< TInt, TIntV > &NewNIDAttrH, const TIntStrH &OldNameH, TIntStrH &NewNameH, const double MinFrac=0.00001, const double MaxFrac=0.95, const int MinCnt=3)
Definition: agmattr.h:203

Here is the call graph for this function:

template<class PGraph >
static void TCesnaUtil::GenHoldOutPairs ( const PGraph &  G,
TVec< TIntSet > &  HoldOutSet,
double  HOFrac,
TRnd Rnd 
)
inlinestatic

Definition at line 38 of file agmattr.h.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), TRnd::GetUniDevInt(), gfDirected, HasGraphFlag, and TMath::Round().

Referenced by TCesna::FindComs(), and TCesna::SetHoldOut().

38  {
39  TIntPrV EdgeV(G->GetEdges(), 0);
40  for (typename PGraph::TObj::TEdgeI EI = G->BegEI(); EI < G->EndEI(); EI++) {
41  EdgeV.Add(TIntPr(EI.GetSrcNId(), EI.GetDstNId()));
42  }
43  EdgeV.Shuffle(Rnd);
44 
45  const bool GraphType = HasGraphFlag(typename PGraph::TObj, gfDirected);
46  HoldOutSet.Gen(G->GetNodes());
47  int HOTotal = int(HOFrac * G->GetNodes() * (G->GetNodes() - 1) / 2.0);
48  if (GraphType) { HOTotal *= 2;}
49  int HOCnt = 0;
50  int HOEdges = (int) TMath::Round(HOFrac * G->GetEdges());
51  printf("holding out %d edges...\n", HOEdges);
52  for (int he = 0; he < (int) HOEdges; he++) {
53  HoldOutSet[EdgeV[he].Val1].AddKey(EdgeV[he].Val2);
54  if (! GraphType) { HoldOutSet[EdgeV[he].Val2].AddKey(EdgeV[he].Val1); }
55  HOCnt++;
56  }
57  printf("%d Edges hold out\n", HOCnt);
58  while(HOCnt++ < HOTotal) {
59  int SrcNID = Rnd.GetUniDevInt(G->GetNodes());
60  int DstNID = Rnd.GetUniDevInt(G->GetNodes());
61  if (SrcNID == DstNID) { continue; }
62  HoldOutSet[SrcNID].AddKey(DstNID);
63  if (! GraphType) { HoldOutSet[DstNID].AddKey(SrcNID); }
64  }
65  }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
static double Round(const double &Val)
Definition: xmath.h:16
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph
Definition: gbase.h:13
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

Here is the caller graph for this function:

static int TCesnaUtil::GetAttrs ( const THash< TInt, TIntV > &  NIDAttrH)
inlinestatic

Definition at line 169 of file agmattr.h.

References THash< TKey, TDat, THashFunc >::Len().

169  {
170  int Attrs = 0;
171  for (int u = 0; u < NIDAttrH.Len(); u++) {
172  for (int k = 0; k < NIDAttrH[u].Len(); k++) {
173  if (NIDAttrH[u][k] >= Attrs) { Attrs = NIDAttrH[u][k] + 1; }
174  }
175  }
176  return Attrs;
177  }
int Len() const
Definition: hash.h:228

Here is the call graph for this function:

template<class PGraph >
static double TCesnaUtil::GetConductance ( const PGraph &  Graph,
const TIntSet CmtyS,
const int  Edges 
)
inlinestatic

Definition at line 10 of file agmattr.h.

References gfDirected, HasGraphFlag, THashSet< TKey, THashFunc >::IsKey(), and THashSet< TKey, THashFunc >::Len().

Referenced by GetNIdPhiV().

10  {
11  const bool GraphType = HasGraphFlag(typename PGraph::TObj, gfDirected);
12  int Edges2;
13  if (GraphType) { Edges2 = Edges >= 0 ? Edges : Graph->GetEdges(); }
14  else { Edges2 = Edges >= 0 ? 2 * Edges : Graph->GetEdges(); }
15  int Vol = 0, Cut = 0;
16  double Phi = 0.0;
17  for (int i = 0; i < CmtyS.Len(); i++) {
18  if (! Graph->IsNode(CmtyS[i])) { continue; }
19  typename PGraph::TObj::TNodeI NI = Graph->GetNI(CmtyS[i]);
20  for (int e = 0; e < NI.GetOutDeg(); e++) {
21  if (! CmtyS.IsKey(NI.GetOutNId(e))) { Cut += 1; }
22  }
23  Vol += NI.GetOutDeg();
24  }
25  // get conductance
26  if (Vol != Edges2) {
27  if (2 * Vol > Edges2) { Phi = Cut / double (Edges2 - Vol); }
28  else if (Vol == 0) { Phi = 0.0; }
29  else { Phi = Cut / double(Vol); }
30  } else {
31  if (Vol == Edges2) { Phi = 1.0; }
32  }
33  return Phi;
34 }
bool IsKey(const TKey &Key) const
Definition: shash.h:1148
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph
Definition: gbase.h:13
int Len() const
Definition: shash.h:1121

Here is the call graph for this function:

Here is the caller graph for this function:

template<class PGraph >
static void TCesnaUtil::GetNbhCom ( const PGraph &  Graph,
const int  NID,
TIntSet NBCmtyS 
)
inlinestatic

Definition at line 68 of file agmattr.h.

References THashSet< TKey, THashFunc >::AddKey(), and THashSet< TKey, THashFunc >::Gen().

68  {
69  typename PGraph::TObj::TNodeI NI = Graph->GetNI(NID);
70  NBCmtyS.Gen(NI.GetDeg());
71  NBCmtyS.AddKey(NID);
72  for (int e = 0; e < NI.GetDeg(); e++) {
73  NBCmtyS.AddKey(NI.GetNbrNId(e));
74  }
75  }
void Gen(const int &ExpectVals)
Definition: shash.h:1115
int AddKey(const TKey &Key)
Definition: shash.h:1254

Here is the call graph for this function:

template<class PGraph >
static void TCesnaUtil::GetNIdPhiV ( const PGraph &  G,
TFltIntPrV NIdPhiV 
)
inlinestatic

Definition at line 77 of file agmattr.h.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), GetConductance(), and TExeTm::GetTmStr().

77  {
78  NIdPhiV.Gen(G->GetNodes(), 0);
79  const int Edges = G->GetEdges();
80  TExeTm RunTm;
81  //compute conductance of neighborhood community
82  for (typename PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
83  TIntSet NBCmty(NI.GetDeg() + 1);
84  double Phi;
85  if (NI.GetDeg() < 5) { //do not include nodes with too few degree
86  Phi = 1.0;
87  } else {
88  TCesnaUtil::GetNbhCom<PGraph>(G, NI.GetId(), NBCmty);
89  //if (NBCmty.Len() != NI.GetDeg() + 1) { printf("NbCom:%d, Deg:%d\n", NBCmty.Len(), NI.GetDeg()); }
90  //IAssert(NBCmty.Len() == NI.GetDeg() + 1);
91  Phi = TCesnaUtil::GetConductance(G, NBCmty, Edges);
92  }
93  //NCPhiH.AddDat(u, Phi);
94  NIdPhiV.Add(TFltIntPr(Phi, NI.GetId()));
95  }
96  printf("conductance computation completed [%s]\n", RunTm.GetTmStr());
97  fflush(stdout);
98  }
TPair< TFlt, TInt > TFltIntPr
Definition: ds.h:97
Definition: tm.h:355
const char * GetTmStr() const
Definition: tm.h:370
static double GetConductance(const PGraph &Graph, const TIntSet &CmtyS, const int Edges)
Definition: agmattr.h:10
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

static void TCesnaUtil::LoadNIDAttrHFromNIDKH ( const TIntV NIDV,
const TStr InFNm,
THash< TInt, TIntV > &  NIDAttrH,
const TStrHash< TInt > &  NodeNameH,
const TSsFmt  Sep = ssfTabSep 
)
inlinestatic

Definition at line 100 of file agmattr.h.

References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::Clr(), TStr::CStr(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::Gen(), TVec< TVal, TSizeTy >::Gen(), THash< TKey, TDat, THashFunc >::GetDat(), TSsParser::GetFld(), TSsParser::GetInt(), TStr::GetInt(), TStrHash< TDat, TStringPool, THashFunc >::GetKeyId(), TSsParser::GetLineNo(), TUInt64::GetStr(), IAssertR, TVec< TVal, TSizeTy >::IsIn(), THash< TKey, TDat, THashFunc >::IsKey(), TStrHash< TDat, TStringPool, THashFunc >::IsKey(), THash< TKey, TDat, THashFunc >::Len(), TVec< TVal, TSizeTy >::Len(), TStrHash< TDat, TStringPool, THashFunc >::Len(), TSsParser::Next(), ssfTabSep, and TInt::Val.

Referenced by LoadNIDAttrHFromNIDKH().

100  {
101  NIDAttrH.Clr();
102  NIDAttrH.Gen(NIDV.Len());
103  printf("nodes in the graph:%d\n", NIDV.Len());
104  for (int u = 0; u < NIDV.Len(); u++) { NIDAttrH.AddDat(NIDV[u]).Gen(0, 0); }
105  TSsParser Ss(InFNm, ssfTabSep);
106  while (Ss.Next()) {
107  TStr NodeName = Ss.GetFld(0);
108  TInt NID = NodeName.GetInt();
109  if (NodeNameH.Len() > 0 && ! NodeNameH.IsKey(NodeName)) { continue; }
110  if (NodeNameH.Len() > 0) {
111  IAssertR(NodeNameH.IsKey(NodeName), TStr::Fmt("NodeName:%s", NodeName.CStr()));
112  NID = NodeNameH.GetKeyId(NodeName);
113  }
114  if (! NIDAttrH.IsKey(NID)) {
115  //printf("NodeName %s, NID %d does not exist\n", NodeName.CStr(), NID);
116  continue; } //ignore nodes who are not in the graph
117  IAssertR(! NIDAttrH.GetDat(NID).IsIn(Ss.GetInt(1)), TStr::Fmt("NIdx:%d NID:%s, K:%d", NID.Val, NodeName.CStr(), Ss.GetInt(1)));
118  NIDAttrH.GetDat(NID).Add(Ss.GetInt(1));
119  }
120  printf("%s nodes, %s lines read \n", TUInt64::GetStr(NIDAttrH.Len()).CStr(), TUInt64::GetStr(Ss.GetLineNo()).CStr());
121  //printf("%d nodes, %d lines read \n", NIDAttrH.Len(), Ss.GetLineNo());
122  }
int GetInt() const
Definition: dt.h:578
#define IAssertR(Cond, Reason)
Definition: bd.h:265
int Val
Definition: dt.h:1136
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:828
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int Len() const
Definition: hash.h:842
Definition: ss.h:72
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
void Gen(const int &ExpectVals)
Definition: hash.h:222
bool IsKey(const char *Key) const
Definition: hash.h:897
Tab separated.
Definition: ss.h:6
Definition: dt.h:1134
TStr GetStr() const
Definition: dt.h:1360
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:361
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
char * CStr()
Definition: dt.h:476
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int Len() const
Definition: hash.h:228
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
int GetKeyId(const char *Key) const
Definition: hash.h:994

Here is the call graph for this function:

Here is the caller graph for this function:

static void TCesnaUtil::LoadNIDAttrHFromNIDKH ( const TIntV NIDV,
const TStr InFNm,
THash< TInt, TIntV > &  NIDAttrH 
)
inlinestatic

Definition at line 123 of file agmattr.h.

References LoadNIDAttrHFromNIDKH().

123  {
124  TStrHash<TInt> TmpH;
125  LoadNIDAttrHFromNIDKH(NIDV, InFNm, NIDAttrH, TmpH);
126  }
Definition: hash.h:781
static void LoadNIDAttrHFromNIDKH(const TIntV &NIDV, const TStr &InFNm, THash< TInt, TIntV > &NIDAttrH, const TStrHash< TInt > &NodeNameH, const TSsFmt Sep=ssfTabSep)
Definition: agmattr.h:100

Here is the call graph for this function:


The documentation for this class was generated from the following file: