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
network.cpp
Go to the documentation of this file.
1 void TNEANet::LoadNetworkShM(TShMIn& ShMIn) {
3  MxNId = TInt(ShMIn);
4  MxEId = TInt(ShMIn);
5 
6  LoadTNodeFunctor NodeFn;
7  NodeH.LoadShM(ShMIn, NodeFn);
8 
9  EdgeH.LoadShM(ShMIn);
10  KeyToIndexTypeN.LoadShM(ShMIn);
11  KeyToIndexTypeE.LoadShM(ShMIn);
12 
13  KeyToDenseN.LoadShM(ShMIn);
14  KeyToDenseE.LoadShM(ShMIn);
15 
16  IntDefaultsN.LoadShM(ShMIn);
17  IntDefaultsE.LoadShM(ShMIn);
18  StrDefaultsN.LoadShM(ShMIn);
19  StrDefaultsE.LoadShM(ShMIn);
20  FltDefaultsE.LoadShM(ShMIn);
21  FltDefaultsE.LoadShM(ShMIn);
22 
23  LoadVecFunctor vec_fn;
24  VecOfIntVecsN.LoadShM(ShMIn, vec_fn);
25  VecOfIntVecsE.LoadShM(ShMIn, vec_fn);
26  /* Strings and floats are complicated, so don't optimize on these */
27  VecOfStrVecsN.Load(ShMIn);
28  VecOfStrVecsE.Load(ShMIn);
29  VecOfFltVecsN.Load(ShMIn);
30  VecOfFltVecsE.Load(ShMIn);
31 
32  LoadVecOfVecFunctor vec_of_vec_fn;
33  VecOfIntVecVecsN.LoadShM(ShMIn, vec_of_vec_fn);
34  VecOfIntVecVecsE.LoadShM(ShMIn, vec_of_vec_fn);
35 
36  LoadHashOfVecFunctor hash_of_vec_fn;
37  VecOfIntHashVecsN.LoadShM(ShMIn, hash_of_vec_fn);
38  VecOfIntHashVecsE.LoadShM(ShMIn, hash_of_vec_fn);
39 
40  /* Attributes are complicated so load these straight */
41  SAttrN.Load(ShMIn);
42  SAttrE.Load(ShMIn);
43 }
44 
45 // Attribute Node Edge Network
46 bool TNEANet::HasFlag(const TGraphFlag& Flag) const {
47  return HasGraphFlag(TNEANet::TNet, Flag);
48 }
49 
50 bool TNEANet::TNodeI::IsInNId(const int& NId) const {
51  const TNode& Node = NodeHI.GetDat();
52  for (int edge = 0; edge < Node.GetInDeg(); edge++) {
53  if (NId == Graph->GetEdge(Node.GetInEId(edge)).GetSrcNId())
54  return true;
55  }
56  return false;
57 }
58 
59 bool TNEANet::TNodeI::IsOutNId(const int& NId) const {
60  const TNode& Node = NodeHI.GetDat();
61  for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
62  if (NId == Graph->GetEdge(Node.GetOutEId(edge)).GetDstNId())
63  return true;
64  }
65  return false;
66 }
67 
68 void TNEANet::AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
69  Names = TVec<TStr>();
70  while (!NodeHI.IsEnd()) {
71  if (!NodeAttrIsDeleted(NId, NodeHI)) {
72  Names.Add(NodeHI.GetKey());
73  }
74  NodeHI++;
75  }
76 }
77 
78 void TNEANet::AttrValueNI(const TInt& NId , TStrIntPrH::TIter NodeHI, TStrV& Values) const {
79  Values = TVec<TStr>();
80  while (!NodeHI.IsEnd()) {
81  if (!NodeAttrIsDeleted(NId, NodeHI)) {
82  Values.Add(GetNodeAttrValue(NId, NodeHI));
83  }
84  NodeHI++;
85  }
86 }
87 
88 void TNEANet::IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
89  Names = TVec<TStr>();
90  while (!NodeHI.IsEnd()) {
91  if (NodeHI.GetDat().Val1 == IntType && !NodeAttrIsIntDeleted(NId, NodeHI)) {
92  Names.Add(NodeHI.GetKey());
93  }
94  NodeHI++;
95  }
96 }
97 
98 void TNEANet::IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const {
99  Values = TVec<TInt>();
100  while (!NodeHI.IsEnd()) {
101  if (NodeHI.GetDat().Val1 == IntType && !NodeAttrIsIntDeleted(NId, NodeHI)) {
102  TInt val = this->VecOfIntVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NodeH.GetKeyId(NId));
103  Values.Add(val);
104  }
105  NodeHI++;
106  }
107 }
108 
109 void TNEANet::IntVAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
110  Names = TVec<TStr>();
111  while (!NodeHI.IsEnd()) {
112  if (NodeHI.GetDat().Val1 == IntVType) {
113  Names.Add(NodeHI.GetKey());
114  }
115  NodeHI++;
116  }
117 }
118 
119 void TNEANet::IntVAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TVec<TIntV>& Values) const {
120  Values = TVec<TIntV>();
121  while (!NodeHI.IsEnd()) {
122  if (NodeHI.GetDat().Val1 == IntVType) {
123  TInt index = NodeHI.GetDat().Val2;
124  TStr attr = NodeHI.GetKey();
125  TInt loc = CheckDenseOrSparseN(attr);
126  if (loc == 1) {
127  TIntV val = this->VecOfIntVecVecsN.GetVal(index).GetVal(NodeH.GetKeyId(NId));
128  if (val.Len() != 0) Values.Add(val);
129  } else {
130  const THash<TInt, TIntV>& NewHash = VecOfIntHashVecsN[index];
131  if (NewHash.IsKey(NodeH.GetKeyId(NId))) {
132  Values.Add(NewHash[NodeH.GetKeyId(NId)]);
133  }
134  }
135  }
136  NodeHI++;
137  }
138 }
139 
140 void TNEANet::StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
141  Names = TVec<TStr>();
142  while (!NodeHI.IsEnd()) {
143  if (NodeHI.GetDat().Val1 == StrType && !NodeAttrIsStrDeleted(NId, NodeHI)) {
144  Names.Add(NodeHI.GetKey());
145  }
146  NodeHI++;
147  }
148 }
149 
150 void TNEANet::StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const {
151  Values = TVec<TStr>();
152  while (!NodeHI.IsEnd()) {
153  if (NodeHI.GetDat().Val1 == StrType && !NodeAttrIsStrDeleted(NId, NodeHI)) {
154  TStr val = this->VecOfStrVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NodeH.GetKeyId(NId));
155  Values.Add(val);
156  }
157  NodeHI++;
158  }
159 }
160 
161 void TNEANet::FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
162  Names = TVec<TStr>();
163  while (!NodeHI.IsEnd()) {
164  if (NodeHI.GetDat().Val1 == FltType && !NodeAttrIsFltDeleted(NId, NodeHI)) {
165  Names.Add(NodeHI.GetKey());
166  }
167  NodeHI++;
168  }
169 }
170 
171 void TNEANet::FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const {
172  Values = TVec<TFlt>();
173  while (!NodeHI.IsEnd()) {
174  if (NodeHI.GetDat().Val1 == FltType && !NodeAttrIsFltDeleted(NId, NodeHI)) {
175  TFlt val = (this->VecOfFltVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NodeH.GetKeyId(NId)));
176  Values.Add(val);
177  }
178  NodeHI++;
179  }
180 }
181 
182 bool TNEANet::IsAttrDeletedN(const int& NId, const TStr& attr) const {
183  bool IntDel = IsIntAttrDeletedN(NId, attr);
184  bool StrDel = IsStrAttrDeletedN(NId, attr);
185  bool FltDel = IsFltAttrDeletedN(NId, attr);
186  bool IntVDel = IsIntVAttrDeletedN(NId, attr);
187  return IntDel || StrDel || FltDel || IntVDel;
188 }
189 
190 bool TNEANet::IsIntAttrDeletedN(const int& NId, const TStr& attr) const {
191  return NodeAttrIsIntDeleted(NId, KeyToIndexTypeN.GetI(attr));
192 }
193 
194 bool TNEANet::IsIntVAttrDeletedN(const int& NId, const TStr& attr) const {
195  return NodeAttrIsIntVDeleted(NId, KeyToIndexTypeN.GetI(attr));
196 }
197 
198 bool TNEANet::IsStrAttrDeletedN(const int& NId, const TStr& attr) const {
199  return NodeAttrIsStrDeleted(NId, KeyToIndexTypeN.GetI(attr));
200 }
201 
202 bool TNEANet::IsFltAttrDeletedN(const int& NId, const TStr& attr) const {
203  return NodeAttrIsFltDeleted(NId, KeyToIndexTypeN.GetI(attr));
204 }
205 
206 bool TNEANet::NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
207  bool IntDel = NodeAttrIsIntDeleted(NId, NodeHI);
208  bool StrDel = NodeAttrIsStrDeleted(NId, NodeHI);
209  bool FltDel = NodeAttrIsFltDeleted(NId, NodeHI);
210  bool IntVDel = NodeAttrIsIntVDeleted(NId, NodeHI);
211  return IntDel || StrDel || FltDel || IntVDel;
212 }
213 
214 bool TNEANet::NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
215  if (NodeHI.GetDat().Val1 != IntType) {
216  return false;
217  }
218  return (GetIntAttrDefaultN(NodeHI.GetKey()) == this->VecOfIntVecsN.GetVal(
219  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
220 }
221 
222 bool TNEANet::NodeAttrIsIntVDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
223  if (NodeHI.GetDat().Val1 != IntVType) {
224  return false;
225  }
226  return (TIntV() == this->VecOfIntVecVecsN.GetVal(
227  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
228 }
229 
230 bool TNEANet::NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
231  if (NodeHI.GetDat().Val1 != StrType) {
232  return false;
233  }
234  return (GetStrAttrDefaultN(NodeHI.GetKey()) == this->VecOfStrVecsN.GetVal(
235  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
236 }
237 
238 bool TNEANet::NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
239  if (NodeHI.GetDat().Val1 != FltType) {
240  return false;
241  }
242  return (GetFltAttrDefaultN(NodeHI.GetKey()) == this->VecOfFltVecsN.GetVal(
243  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
244 }
245 
246 TStr TNEANet::GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
247  if (NodeHI.GetDat().Val1 == IntType) {
248  return (this->VecOfIntVecsN.GetVal(
249  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId))).GetStr();
250  } else if(NodeHI.GetDat().Val1 == StrType) {
251  return this->VecOfStrVecsN.GetVal(
252  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId));
253  } else if (NodeHI.GetDat().Val1 == FltType) {
254  return (this->VecOfFltVecsN.GetVal(
255  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId))).GetStr();
256  }
257  return TStr::GetNullStr();
258 }
259 
260 void TNEANet::AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
261  Names = TVec<TStr>();
262  while (!EdgeHI.IsEnd()) {
263  if (!EdgeAttrIsDeleted(EId, EdgeHI)) {
264  Names.Add(EdgeHI.GetKey());
265  }
266  EdgeHI++;
267  }
268 }
269 
270 void TNEANet::AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const {
271  Values = TVec<TStr>();
272  while (!EdgeHI.IsEnd()) {
273  if (!EdgeAttrIsDeleted(EId, EdgeHI)) {
274  Values.Add(GetEdgeAttrValue(EId, EdgeHI));
275  }
276  EdgeHI++;
277  }
278 }
279 
280 void TNEANet::IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
281  Names = TVec<TStr>();
282  while (!EdgeHI.IsEnd()) {
283  if (EdgeHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, EdgeHI)) {
284  Names.Add(EdgeHI.GetKey());
285  }
286  EdgeHI++;
287  }
288 }
289 
290 void TNEANet::IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const {
291  Values = TVec<TInt>();
292  while (!EdgeHI.IsEnd()) {
293  if (EdgeHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, EdgeHI)) {
294  TInt val = (this->VecOfIntVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId));
295  Values.Add(val);
296  }
297  EdgeHI++;
298  }
299 }
300 
301 void TNEANet::IntVAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
302  Names = TVec<TStr>();
303  while (!EdgeHI.IsEnd()) {
304  if (EdgeHI.GetDat().Val1 == IntVType) {
305  Names.Add(EdgeHI.GetKey());
306  }
307  EdgeHI++;
308  }
309 }
310 
311 void TNEANet::IntVAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TVec<TIntV>& Values) const {
312  Values = TVec<TIntV>();
313  while (!EdgeHI.IsEnd()) {
314  if (EdgeHI.GetDat().Val1 == IntVType) {
315  TInt index = EdgeHI.GetDat().Val2;
316  TStr attr = EdgeHI.GetKey();
317  TInt loc = CheckDenseOrSparseE(attr);
318  if (loc == 1) {
319  TIntV val = this->VecOfIntVecVecsE.GetVal(index).GetVal(EdgeH.GetKeyId(EId));
320  if (val.Len() != 0) Values.Add(val);
321  } else {
322  const THash<TInt, TIntV>& NewHash = VecOfIntHashVecsE[index];
323  if (NewHash.IsKey(EdgeH.GetKeyId(EId))) {
324  Values.Add(NewHash[EdgeH.GetKeyId(EId)]);
325  }
326  }
327  }
328  EdgeHI++;
329  }
330 }
331 
332 void TNEANet::StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
333  Names = TVec<TStr>();
334  while (!EdgeHI.IsEnd()) {
335  if (EdgeHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, EdgeHI)) {
336  Names.Add(EdgeHI.GetKey());
337  }
338  EdgeHI++;
339  }
340 }
341 
342 void TNEANet::StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const {
343  Values = TVec<TStr>();
344  while (!EdgeHI.IsEnd()) {
345  if (EdgeHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, EdgeHI)) {
346  TStr val = this->VecOfStrVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId);
347  Values.Add(val);
348  }
349  EdgeHI++;
350  }
351 }
352 
353 void TNEANet::FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
354  Names = TVec<TStr>();
355  while (!EdgeHI.IsEnd()) {
356  if (EdgeHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, EdgeHI)) {
357  Names.Add(EdgeHI.GetKey());
358  }
359  EdgeHI++;
360  }
361 }
362 
363 void TNEANet::FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const {
364  Values = TVec<TFlt>();
365  while (!EdgeHI.IsEnd()) {
366  if (EdgeHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, EdgeHI)) {
367  TFlt val = (this->VecOfFltVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId));
368  Values.Add(val);
369  }
370  EdgeHI++;
371  }
372 }
373 
374 bool TNEANet::IsAttrDeletedE(const int& EId, const TStr& attr) const {
375  bool IntDel = IsIntAttrDeletedE(EId, attr);
376  bool IntVDel = IsIntVAttrDeletedE(EId, attr);
377  bool StrDel = IsStrAttrDeletedE(EId, attr);
378  bool FltDel = IsFltAttrDeletedE(EId, attr);
379  return IntDel || StrDel || FltDel || IntVDel;
380 }
381 
382 bool TNEANet::IsIntAttrDeletedE(const int& EId, const TStr& attr) const {
383  return EdgeAttrIsIntDeleted(EId, KeyToIndexTypeE.GetI(attr));
384 }
385 
386 bool TNEANet::IsIntVAttrDeletedE(const int& EId, const TStr& attr) const {
387  return EdgeAttrIsIntVDeleted(EId, KeyToIndexTypeE.GetI(attr));
388 }
389 
390 bool TNEANet::IsStrAttrDeletedE(const int& EId, const TStr& attr) const {
391  return EdgeAttrIsStrDeleted(EId, KeyToIndexTypeE.GetI(attr));
392 }
393 
394 bool TNEANet::IsFltAttrDeletedE(const int& EId, const TStr& attr) const {
395  return EdgeAttrIsFltDeleted(EId, KeyToIndexTypeE.GetI(attr));
396 }
397 
398 bool TNEANet::EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
399  bool IntDel = EdgeAttrIsIntDeleted(EId, EdgeHI);
400  bool IntVDel = EdgeAttrIsIntVDeleted(EId, EdgeHI);
401  bool StrDel = EdgeAttrIsStrDeleted(EId, EdgeHI);
402  bool FltDel = EdgeAttrIsFltDeleted(EId, EdgeHI);
403  return IntDel || StrDel || FltDel || IntVDel;
404 }
405 
406 bool TNEANet::EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
407  return (EdgeHI.GetDat().Val1 == IntType &&
408  GetIntAttrDefaultE(EdgeHI.GetKey()) == this->VecOfIntVecsE.GetVal(
409  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
410 }
411 
412 bool TNEANet::EdgeAttrIsIntVDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
413  return (EdgeHI.GetDat().Val1 == IntVType &&
414  TIntV() == this->VecOfIntVecVecsE.GetVal(
415  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
416 }
417 
418 bool TNEANet::EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
419  return (EdgeHI.GetDat().Val1 == StrType &&
420  GetStrAttrDefaultE(EdgeHI.GetKey()) == this->VecOfStrVecsE.GetVal(
421  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
422 }
423 
424 bool TNEANet::EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
425  return (EdgeHI.GetDat().Val1 == FltType &&
426  GetFltAttrDefaultE(EdgeHI.GetKey()) == this->VecOfFltVecsE.GetVal(
427  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
428 }
429 
430 TStr TNEANet::GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
431  if (EdgeHI.GetDat().Val1 == IntType) {
432  return (this->VecOfIntVecsE.GetVal(
433  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId))).GetStr();
434  } else if(EdgeHI.GetDat().Val1 == StrType) {
435  return this->VecOfStrVecsE.GetVal(
436  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId));
437  } else if (EdgeHI.GetDat().Val1 == FltType) {
438  return (this->VecOfFltVecsE.GetVal(
439  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId))).GetStr();
440  }
441  return TStr::GetNullStr();
442 }
443 
444 int TNEANet::AddNode(int NId) {
445  if (NId == -1) {
446  NId = MxNId; MxNId++;
447  } else {
448  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
449  MxNId = TMath::Mx(NId+1, MxNId());
450  }
451  NodeH.AddDat(NId, TNode(NId));
452  AddAttributes(NId);
453  return NId;
454 }
455 
457  if (NId == -1) {
458  NId = MxNId; MxNId++;
459  } else {
460  if (IsNode(NId)) { return -1;}
461  MxNId = TMath::Mx(NId+1, MxNId());
462  }
463  NodeH.AddDat(NId, TNode(NId));
464  AddAttributes(NId);
465  return NId;
466 }
467 
468 int TNEANet::AddAttributes(const int NId) {
469  int i;
470  // update attribute columns
471  for (i = 0; i < VecOfIntVecsN.Len(); i++) {
472  TVec<TInt>& IntVec = VecOfIntVecsN[i];
473  int KeyId = NodeH.GetKeyId(NId);
474  if (IntVec.Len() > KeyId) {
475  IntVec[KeyId] = TInt::Mn;
476  } else {
477  IntVec.Ins(KeyId, TInt::Mn);
478  }
479  }
480  TVec<TStr> DefIntVec = TVec<TStr>();
481  IntDefaultsN.GetKeyV(DefIntVec);
482  for (i = 0; i < DefIntVec.Len(); i++) {
483  TStr attr = DefIntVec[i];
484  TVec<TInt>& IntVec = VecOfIntVecsN[KeyToIndexTypeN.GetDat(DefIntVec[i]).Val2];
485  IntVec[NodeH.GetKeyId(NId)] = GetIntAttrDefaultN(attr);
486  }
487  for (i = 0; i < VecOfStrVecsN.Len(); i++) {
488  TVec<TStr>& StrVec = VecOfStrVecsN[i];
489  int KeyId = NodeH.GetKeyId(NId);
490  if (StrVec.Len() > KeyId) {
491  StrVec[KeyId] = TStr::GetNullStr();
492  } else {
493  StrVec.Ins(KeyId, TStr::GetNullStr());
494  }
495  }
496  TVec<TStr> DefStrVec = TVec<TStr>();
497  StrDefaultsN.GetKeyV(DefStrVec);
498  for (i = 0; i < DefStrVec.Len(); i++) {
499  TStr attr = DefStrVec[i];
500  TVec<TStr>& StrVec = VecOfStrVecsN[KeyToIndexTypeN.GetDat(DefStrVec[i]).Val2];
501  StrVec[NodeH.GetKeyId(NId)] = GetStrAttrDefaultN(attr);
502  }
503  for (i = 0; i < VecOfFltVecsN.Len(); i++) {
504  TVec<TFlt>& FltVec = VecOfFltVecsN[i];
505  int KeyId = NodeH.GetKeyId(NId);
506  if (FltVec.Len() > KeyId) {
507  FltVec[KeyId] = TFlt::Mn;
508  } else {
509  FltVec.Ins(KeyId, TFlt::Mn);
510  }
511  }
512  TVec<TStr> DefFltVec = TVec<TStr>();
513  FltDefaultsN.GetKeyV(DefFltVec);
514  for (i = 0; i < DefFltVec.Len(); i++) {
515  TStr attr = DefFltVec[i];
516  TVec<TFlt>& FltVec = VecOfFltVecsN[KeyToIndexTypeN.GetDat(DefFltVec[i]).Val2];
517  FltVec[NodeH.GetKeyId(NId)] = GetFltAttrDefaultN(attr);
518  }
519  for (i = 0; i < VecOfIntVecVecsN.Len(); i++) {
520  TVec<TIntV>& IntVecV = VecOfIntVecVecsN[i];
521  int KeyId = NodeH.GetKeyId(NId);
522  if (IntVecV.Len() > KeyId) {
523  IntVecV[KeyId] = TIntV();
524  } else {
525  IntVecV.Ins(KeyId, TIntV());
526  }
527  }
528  return NId;
529 }
530 
531 void TNEANet::DelNode(const int& NId) {
532  int i;
533  TInt Id(NId);
534  SAttrN.DelSAttrId(Id);
535  const TNode& Node = GetNode(NId);
536  for (int out = 0; out < Node.GetOutDeg(); out++) {
537  const int EId = Node.GetOutEId(out);
538  const TEdge& Edge = GetEdge(EId);
539  IAssert(Edge.GetSrcNId() == NId);
540  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
541  // Delete from Edge Attributes
542  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
543  TVec<TInt>& IntVec = VecOfIntVecsE[i];
544  IntVec[EdgeH.GetKeyId(EId)] = TInt::Mn;
545  }
546  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
547  TVec<TStr>& StrVec = VecOfStrVecsE[i];
548  StrVec[EdgeH.GetKeyId(EId)] = TStr::GetNullStr();
549  }
550  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
551  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
552  FltVec[EdgeH.GetKeyId(EId)] = TFlt::Mn;
553  }
554  for (i = 0; i < VecOfIntVecVecsE.Len(); i++) {
555  TVec<TIntV>& IntVecV = VecOfIntVecVecsE[i];
556  IntVecV[EdgeH.GetKeyId(EId)] = TIntV();
557  }
558  EdgeH.DelKey(EId);
559  for (i = 0; i < VecOfIntHashVecsE.Len(); i++) {
560  THash<TInt, TIntV>& IntHashV = VecOfIntHashVecsE[i];
561  if (IntHashV.IsKey(EdgeH.GetKeyId(EId))) {
562  IntHashV.DelKey(EdgeH.GetKeyId(EId));
563  }
564  }
565  }
566  for (int in = 0; in < Node.GetInDeg(); in++) {
567  const int EId = Node.GetInEId(in);
568  const TEdge& Edge = GetEdge(EId);
569  IAssert(Edge.GetDstNId() == NId);
570  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
571  // Delete from Edge Attributes
572  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
573  TVec<TInt>& IntVec = VecOfIntVecsE[i];
574  IntVec[EdgeH.GetKeyId(EId)] = TInt::Mn;
575  }
576  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
577  TVec<TStr>& StrVec = VecOfStrVecsE[i];
578  StrVec[EdgeH.GetKeyId(EId)] = TStr::GetNullStr();
579  }
580  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
581  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
582  FltVec[EdgeH.GetKeyId(EId)] = TFlt::Mn;
583  }
584  for (i = 0; i < VecOfIntVecVecsE.Len(); i++) {
585  TVec<TIntV>& IntVecV = VecOfIntVecVecsE[i];
586  IntVecV[EdgeH.GetKeyId(EId)] = TIntV();
587  }
588  for (i = 0; i < VecOfIntHashVecsE.Len(); i++) {
589  THash<TInt, TIntV>& IntHashV = VecOfIntHashVecsE[i];
590  if (IntHashV.IsKey(EdgeH.GetKeyId(EId))) {
591  IntHashV.DelKey(EdgeH.GetKeyId(EId));
592  }
593  }
594  EdgeH.DelKey(EId);
595  }
596 
597  for (i = 0; i < VecOfIntVecsN.Len(); i++) {
598  TVec<TInt>& IntVec = VecOfIntVecsN[i];
599  IntVec[NodeH.GetKeyId(NId)] = TInt::Mn;
600  }
601  for (i = 0; i < VecOfStrVecsN.Len(); i++) {
602  TVec<TStr>& StrVec = VecOfStrVecsN[i];
603  StrVec[NodeH.GetKeyId(NId)] = TStr::GetNullStr();
604  }
605  for (i = 0; i < VecOfFltVecsN.Len(); i++) {
606  TVec<TFlt>& FltVec = VecOfFltVecsN[i];
607  FltVec[NodeH.GetKeyId(NId)] = TFlt::Mn;
608  }
609  for (i = 0; i < VecOfIntVecVecsN.Len(); i++) {
610  TVec<TIntV>& IntVecV = VecOfIntVecVecsN[i];
611  IntVecV[NodeH.GetKeyId(NId)] = TIntV();
612  }
613  for (i = 0; i < VecOfIntHashVecsN.Len(); i++) {
614  THash<TInt, TIntV>& IntHashV = VecOfIntHashVecsN[i];
615  if (IntHashV.IsKey(NodeH.GetKeyId(NId))) {
616  IntHashV.DelKey(NodeH.GetKeyId(NId));
617  }
618  }
619  NodeH.DelKey(NId);
620 }
621 
622 int TNEANet::AddEdge(const int& SrcNId, const int& DstNId, int EId) {
623  int i;
624 
625  if (EId == -1) { EId = MxEId; MxEId++; }
626  else { MxEId = TMath::Mx(EId+1, MxEId()); }
627  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
628  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
629  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
630  GetNode(SrcNId).OutEIdV.AddSorted(EId);
631  GetNode(DstNId).InEIdV.AddSorted(EId);
632 
633  // update attribute columns
634  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
635  TVec<TInt>& IntVec = VecOfIntVecsE[i];
636  int KeyId = EdgeH.GetKeyId(EId);
637  if (IntVec.Len() > KeyId) {
638  IntVec[KeyId] = TInt::Mn;
639  } else {
640  IntVec.Ins(KeyId, TInt::Mn);
641  }
642  }
643  TVec<TStr> DefIntVec = TVec<TStr>();
644  IntDefaultsE.GetKeyV(DefIntVec);
645  for (i = 0; i < DefIntVec.Len(); i++) {
646  TStr attr = DefIntVec[i];
647  TVec<TInt>& IntVec = VecOfIntVecsE[KeyToIndexTypeE.GetDat(DefIntVec[i]).Val2];
648  IntVec[EdgeH.GetKeyId(EId)] = GetIntAttrDefaultE(attr);
649  }
650 
651  for (i = 0; i < VecOfIntVecVecsE.Len(); i++) {
652  TVec<TIntV>& IntVecV = VecOfIntVecVecsE[i];
653  IntVecV.Ins(EdgeH.GetKeyId(EId), TIntV());
654  }
655 
656  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
657  TVec<TStr>& StrVec = VecOfStrVecsE[i];
658  int KeyId = EdgeH.GetKeyId(EId);
659  if (StrVec.Len() > KeyId) {
660  StrVec[KeyId] = TStr::GetNullStr();
661  } else {
662  StrVec.Ins(KeyId, TStr::GetNullStr());
663  }
664  }
665  TVec<TStr> DefStrVec = TVec<TStr>();
666  StrDefaultsE.GetKeyV(DefStrVec);
667  for (i = 0; i < DefStrVec.Len(); i++) {
668  TStr attr = DefStrVec[i];
669  TVec<TStr>& StrVec = VecOfStrVecsE[KeyToIndexTypeE.GetDat(DefStrVec[i]).Val2];
670  StrVec[EdgeH.GetKeyId(EId)] = GetStrAttrDefaultE(attr);
671  }
672 
673  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
674  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
675  int KeyId = EdgeH.GetKeyId(EId);
676  if (FltVec.Len() > KeyId) {
677  FltVec[KeyId] = TFlt::Mn;
678  } else {
679  FltVec.Ins(KeyId, TFlt::Mn);
680  }
681  }
682  TVec<TStr> DefFltVec = TVec<TStr>();
683  FltDefaultsE.GetKeyV(DefFltVec);
684  for (i = 0; i < DefFltVec.Len(); i++) {
685  TStr attr = DefFltVec[i];
686  TVec<TFlt>& FltVec = VecOfFltVecsE[KeyToIndexTypeE.GetDat(DefFltVec[i]).Val2];
687  FltVec[EdgeH.GetKeyId(EId)] = GetFltAttrDefaultE(attr);
688  }
689  return EId;
690 }
691 
692 void TNEANet::DelEdge(const int& EId) {
693  int i;
694 
695  IAssert(IsEdge(EId));
696  const int SrcNId = GetEdge(EId).GetSrcNId();
697  const int DstNId = GetEdge(EId).GetDstNId();
698  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
699  GetNode(DstNId).InEIdV.DelIfIn(EId);
700  TInt Id(EId);
701  SAttrE.DelSAttrId(Id);
702 
703  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
704  TVec<TInt>& IntVec = VecOfIntVecsE[i];
705  IntVec[EdgeH.GetKeyId(EId)] = TInt::Mn;
706  }
707  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
708  TVec<TStr>& StrVec = VecOfStrVecsE[i];
709  StrVec[EdgeH.GetKeyId(EId)] = TStr::GetNullStr();
710  }
711  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
712  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
713  FltVec[EdgeH.GetKeyId(EId)] = TFlt::Mn;
714  }
715 
716  EdgeH.DelKey(EId);
717 }
718 
719 // delete all edges between the two nodes
720 void TNEANet::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
721  int EId = 0;
722  bool Edge = IsEdge(SrcNId, DstNId, EId, IsDir);
723  IAssert(Edge); // there is at least one edge
724  while (Edge) {
725  DelEdge(EId);
726  Edge = IsEdge(SrcNId, DstNId, EId, IsDir);
727  }
728 }
729 
730 bool TNEANet::IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir) const {
731  const TNode& SrcNode = GetNode(SrcNId);
732  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
733  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
734  if (DstNId == Edge.GetDstNId()) {
735  EId = Edge.GetId();
736  return true;
737  }
738  }
739  if (! IsDir) {
740  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
741  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
742  if (DstNId == Edge.GetSrcNId()) {
743  EId = Edge.GetId();
744  return true;
745  }
746  }
747  }
748  return false;
749 }
750 
751 void TNEANet::GetNIdV(TIntV& NIdV) const {
752  NIdV.Gen(GetNodes(), 0);
753  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
754  NIdV.Add(NodeH.GetKey(N));
755  }
756 }
757 
758 void TNEANet::GetEIdV(TIntV& EIdV) const {
759  EIdV.Gen(GetEdges(), 0);
760  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
761  EIdV.Add(EdgeH.GetKey(E));
762  }
763 }
764 
765 void TNEANet::Defrag(const bool& OnlyNodeLinks) {
766  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid); ) {
767  TNode& Node = NodeH[kid];
768  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
769  }
770  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
771  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
772 }
773 
774 bool TNEANet::IsOk(const bool& ThrowExcept) const {
775  bool RetVal = true;
776  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
777  const TNode& Node = NodeH[N];
778  if (! Node.OutEIdV.IsSorted()) {
779  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
780  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
781  }
782  if (! Node.InEIdV.IsSorted()) {
783  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
784  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
785  }
786  // check out-edge ids
787  int prevEId = -1;
788  for (int e = 0; e < Node.GetOutDeg(); e++) {
789  if (! IsEdge(Node.GetOutEId(e))) {
790  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
791  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
792  }
793  if (e > 0 && prevEId == Node.GetOutEId(e)) {
794  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
795  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
796  }
797  prevEId = Node.GetOutEId(e);
798  }
799  // check in-edge ids
800  prevEId = -1;
801  for (int e = 0; e < Node.GetInDeg(); e++) {
802  if (! IsEdge(Node.GetInEId(e))) {
803  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
804  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
805  }
806  if (e > 0 && prevEId == Node.GetInEId(e)) {
807  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
808  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
809  }
810  prevEId = Node.GetInEId(e);
811  }
812  }
813  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
814  const TEdge& Edge = EdgeH[E];
815  if (! IsNode(Edge.GetSrcNId())) {
816  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
817  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
818  }
819  if (! IsNode(Edge.GetDstNId())) {
820  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
821  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
822  }
823  }
824  return RetVal;
825 }
826 
827 void TNEANet::Dump(FILE *OutF) const {
828  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
829  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
830  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network with Attributes: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
831  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
832  fprintf(OutF, " %*d:", NodePlaces, NodeI.GetId());
833  fprintf(OutF, " in[%d]", NodeI.GetInDeg());
834  for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
835  fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
836  //fprintf(OutF, "\n");
837  fprintf(OutF, " out[%d]", NodeI.GetOutDeg());
838  for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
839  fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
840  //fprintf(OutF, "\n");
841 
842  // load node attributes
843  TIntV IntAttrN;
844  IntAttrValueNI(NodeI.GetId(), IntAttrN);
845  fprintf(OutF, " nai[%d]", IntAttrN.Len());
846  for (int i = 0; i < IntAttrN.Len(); i++) {
847  fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
848  //fprintf(OutF, "\n");
849 
850  TStrV StrAttrN;
851  StrAttrValueNI(NodeI.GetId(), StrAttrN);
852  fprintf(OutF, " nas[%d]", StrAttrN.Len());
853  for (int i = 0; i < StrAttrN.Len(); i++) {
854  fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
855  //fprintf(OutF, "\n");
856 
857  TFltV FltAttrN;
858  FltAttrValueNI(NodeI.GetId(), FltAttrN);
859  fprintf(OutF, " naf[%d]", FltAttrN.Len());
860  for (int i = 0; i < FltAttrN.Len(); i++) {
861  fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }
862  //fprintf(OutF, "\n");
863  fprintf(OutF, "\n");
864  }
865  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
866  fprintf(OutF, " %*d: %*d -> %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
867 
868  // load edge attributes
869  TIntV IntAttrE;
870  IntAttrValueEI(EdgeI.GetId(), IntAttrE);
871  fprintf(OutF, " eai[%d]", IntAttrE.Len());
872  for (int i = 0; i < IntAttrE.Len(); i++) {
873  fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]());
874  }
875  TStrV StrAttrE;
876  StrAttrValueEI(EdgeI.GetId(), StrAttrE);
877  fprintf(OutF, " eas[%d]", StrAttrE.Len());
878  for (int i = 0; i < StrAttrE.Len(); i++) {
879  fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]());
880  }
881  TFltV FltAttrE;
882  FltAttrValueEI(EdgeI.GetId(), FltAttrE);
883  fprintf(OutF, " eaf[%d]", FltAttrE.Len());
884  for (int i = 0; i < FltAttrE.Len(); i++) {
885  fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]());
886  }
887  fprintf(OutF, "\n");
888  }
889  //fprintf(OutF, "\n");
890 }
891 
892 // Attribute related function
893 
894 int TNEANet::AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr) {
895  int i;
896  TInt CurrLen;
897  if (!IsNode(NId)) {
898  // AddNode(NId);
899  return -1;
900  }
901  if (KeyToIndexTypeN.IsKey(attr)) {
903  NewVec[NodeH.GetKeyId(NId)] = value;
904  } else {
905  CurrLen = VecOfIntVecsN.Len();
906  KeyToIndexTypeN.AddDat(attr, TIntPr(IntType, CurrLen));
907  TVec<TInt> NewVec = TVec<TInt>();
908  for (i = 0; i < MxNId; i++) {
909  NewVec.Ins(i, GetIntAttrDefaultN(attr));
910  }
911  NewVec[NodeH.GetKeyId(NId)] = value;
912  VecOfIntVecsN.Add(NewVec);
913  }
914  return 0;
915 }
916 
917 int TNEANet::AddIntVAttrDatN(const int& NId, const TIntV& value, const TStr& attr, TBool UseDense) {
918  if (!IsNode(NId)) {
919  // AddNode(NId);
920  return -1;
921  }
922  TInt location = CheckDenseOrSparseN(attr);
923  if (location==-1) {
924  AddIntVAttrN(attr, UseDense);
925  location = CheckDenseOrSparseN(attr);
926  }
927  if (UseDense) {
928  IAssertR(location != 0, TStr::Fmt("NodeId %d exists for %s in sparse representation", NId, attr.CStr()));
930  NewVec[NodeH.GetKeyId(NId)] = value;
931  } else {
932  IAssertR(location != 1, TStr::Fmt("NodeId %d exists for %s in dense representation", NId, attr.CStr()));
934  NewHash.AddDat(NodeH.GetKeyId(NId), value);
935  }
936 
937  return 0;
938 }
939 
940 int TNEANet::AppendIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr, TBool UseDense) {
941  if (!IsNode(NId)) {
942  // AddNode(NId);
943  return -1;
944  }
945  TInt location = CheckDenseOrSparseN(attr);
946  if (location==-1) {
947  AddIntVAttrN(attr, UseDense);
948  location = CheckDenseOrSparseN(attr);
949  }
950  if (UseDense) {
951  IAssertR(location != 0, TStr::Fmt("NodeId %d exists for %s in sparse representation", NId, attr.CStr()));
953  NewVec[NodeH.GetKeyId(NId)].Add(value);
954  } else {
955  IAssertR(location != 1, TStr::Fmt("NodeId %d exists for %s in dense representation", NId, attr.CStr()));
957  NewHash[NodeH.GetKeyId(NId)].Add(value);
958  }
959  return 0;
960 }
961 
962 int TNEANet::DelFromIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr) {
963  TInt CurrLen;
964  if (!IsNode(NId)) {
965  // AddNode(NId);
966  return -1;
967  }
968  TInt location = CheckDenseOrSparseN(attr);
969  if (location != -1) {
970  if (location == 1) {
972  if (!NewVec[NodeH.GetKeyId(NId)].DelIfIn(value)) {
973  return -1;
974  }
975  } else {
977  if (!NewHash[NodeH.GetKeyId(NId)].DelIfIn(value)) {
978  return -1;
979  }
980  }
981  } else {
982  return -1;
983  }
984  return 0;
985 }
986 
987 int TNEANet::AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr) {
988  int i;
989  TInt CurrLen;
990  if (!IsNode(NId)) {
991  // AddNode(NId);
992  return -1;
993  }
994  if (KeyToIndexTypeN.IsKey(attr)) {
996  NewVec[NodeH.GetKeyId(NId)] = value;
997  } else {
998  CurrLen = VecOfStrVecsN.Len();
999  KeyToIndexTypeN.AddDat(attr, TIntPr(StrType, CurrLen));
1000  TVec<TStr> NewVec = TVec<TStr>();
1001  for (i = 0; i < MxNId; i++) {
1002  NewVec.Ins(i, GetStrAttrDefaultN(attr));
1003  }
1004  NewVec[NodeH.GetKeyId(NId)] = value;
1005  VecOfStrVecsN.Add(NewVec);
1006  }
1007  return 0;
1008 }
1009 
1010 int TNEANet::AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr) {
1011  int i;
1012  TInt CurrLen;
1013 
1014  if (!IsNode(NId)) {
1015  // AddNode(NId);
1016  return -1;
1017  }
1018  if (KeyToIndexTypeN.IsKey(attr)) {
1020  NewVec[NodeH.GetKeyId(NId)] = value;
1021  } else {
1022  CurrLen = VecOfFltVecsN.Len();
1023  KeyToIndexTypeN.AddDat(attr, TIntPr(FltType, CurrLen));
1024  TVec<TFlt> NewVec = TVec<TFlt>();
1025  for (i = 0; i < MxNId; i++) {
1026  NewVec.Ins(i, GetFltAttrDefaultN(attr));
1027  }
1028  NewVec[NodeH.GetKeyId(NId)] = value;
1029  VecOfFltVecsN.Add(NewVec);
1030  }
1031  return 0;
1032 }
1033 
1034 int TNEANet::AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr) {
1035  int i;
1036  TInt CurrLen;
1037  if (!IsEdge(EId)) {
1038  //AddEdge(EId);
1039  return -1;
1040  }
1041  if (KeyToIndexTypeE.IsKey(attr)) {
1043  NewVec[EdgeH.GetKeyId(EId)] = value;
1044  } else {
1045  CurrLen = VecOfIntVecsE.Len();
1046  KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
1047  TVec<TInt> NewVec = TVec<TInt>();
1048  for (i = 0; i < MxEId; i++) {
1049  NewVec.Ins(i, GetIntAttrDefaultE(attr));
1050  }
1051  NewVec[EdgeH.GetKeyId(EId)] = value;
1052  VecOfIntVecsE.Add(NewVec);
1053  }
1054  return 0;
1055 }
1056 
1057 int TNEANet::AddIntVAttrDatE(const int& EId, const TIntV& value, const TStr& attr, TBool UseDense) {
1058  if (!IsNode(EId)) {
1059  // AddNode(NId);
1060  return -1;
1061  }
1062  TInt location = CheckDenseOrSparseE(attr);
1063  if (location==-1) {
1064  AddIntVAttrE(attr, UseDense);
1065  location = CheckDenseOrSparseE(attr);
1066  }
1067  if (UseDense) {
1068  IAssertR(location != 0, TStr::Fmt("EdgeID %d exists for %s in sparse representation", EId, attr.CStr()));
1070  NewVec[EdgeH.GetKeyId(EId)] = value;
1071  } else {
1072  IAssertR(location != 1, TStr::Fmt("NodeId %d exists for %s in dense representation", EId, attr.CStr()));
1074  NewHash.AddDat(EdgeH.GetKeyId(EId), value);
1075  }
1076  return 0;
1077 }
1078 
1079 int TNEANet::AppendIntVAttrDatE(const int& EId, const TInt& value, const TStr& attr, TBool UseDense) {
1080  if (!IsNode(EId)) {
1081  // AddNode(NId);
1082  return -1;
1083  }
1084  TInt location = CheckDenseOrSparseE(attr);
1085  if (location==-1) return -1;
1086  if (UseDense) {
1087  IAssertR(location != 0, TStr::Fmt("Edge %d exists for %s in sparse representation", EId, attr.CStr()));
1089  NewVec[EdgeH.GetKeyId(EId)].Add(value);
1090  } else {
1091  IAssertR(location != 1, TStr::Fmt("Edge %d exists for %s in dense representation", EId, attr.CStr()));
1093  NewHash[EdgeH.GetKeyId(EId)].Add(value);
1094  }
1095  return 0;
1096 }
1097 
1098 int TNEANet::AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr) {
1099  int i;
1100  TInt CurrLen;
1101  if (!IsEdge(EId)) {
1102  //AddEdge(EId);
1103  return -1;
1104  }
1105  if (KeyToIndexTypeE.IsKey(attr)) {
1107  NewVec[EdgeH.GetKeyId(EId)] = value;
1108  } else {
1109  CurrLen = VecOfStrVecsE.Len();
1110  KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
1111  TVec<TStr> NewVec = TVec<TStr>();
1112  for (i = 0; i < MxEId; i++) {
1113  NewVec.Ins(i, GetStrAttrDefaultE(attr));
1114  }
1115  NewVec[EdgeH.GetKeyId(EId)] = value;
1116  VecOfStrVecsE.Add(NewVec);
1117  }
1118  return 0;
1119 }
1120 
1121 int TNEANet::AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr) {
1122  int i;
1123  TInt CurrLen;
1124 
1125  if (!IsEdge(EId)) {
1126  //AddEdge(EId);
1127  return -1;
1128  }
1129  if (KeyToIndexTypeE.IsKey(attr)) {
1131  NewVec[EdgeH.GetKeyId(EId)] = value;
1132  } else {
1133  CurrLen = VecOfFltVecsE.Len();
1134  KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
1135  TVec<TFlt> NewVec = TVec<TFlt>();
1136  for (i = 0; i < MxEId; i++) {
1137  NewVec.Ins(i, GetFltAttrDefaultE(attr));
1138  }
1139  NewVec[EdgeH.GetKeyId(EId)] = value;
1140  VecOfFltVecsE.Add(NewVec);
1141  }
1142  return 0;
1143 }
1144 
1146  return VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2];
1147 }
1148 
1149 int TNEANet::GetFltKeyIdE(const int& EId) {
1150  return EdgeH.GetKeyId(EId);
1151 }
1152 
1153 TInt TNEANet::GetIntAttrDatN(const int& NId, const TStr& attr) {
1154  return VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NodeH.GetKeyId(NId)];
1155 }
1156 
1157 TIntV TNEANet::GetIntVAttrDatN(const int& NId, const TStr& attr) const {
1158  TInt location = CheckDenseOrSparseN(attr);
1159  if (location != 0) return VecOfIntVecVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NodeH.GetKeyId(NId)];
1160  else return VecOfIntHashVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NodeH.GetKeyId(NId)];
1161 }
1162 
1163 TStr TNEANet::GetStrAttrDatN(const int& NId, const TStr& attr) {
1164  return VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NodeH.GetKeyId(NId)];
1165 }
1166 
1167 TFlt TNEANet::GetFltAttrDatN(const int& NId, const TStr& attr) {
1168  return VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NodeH.GetKeyId(NId)];
1169 }
1170 
1171 TInt TNEANet::GetIntAttrIndDatN(const int& NId, const int& index) {
1172  return VecOfIntVecsN[index][NodeH.GetKeyId(NId)];
1173 }
1174 
1175 TStr TNEANet::GetStrAttrIndDatN(const int& NId, const int& index) {
1176  return VecOfStrVecsN[index][NodeH.GetKeyId(NId)];
1177 }
1178 
1179 TFlt TNEANet::GetFltAttrIndDatN(const int& NId, const int& index) {
1180  return VecOfFltVecsN[index][NodeH.GetKeyId(NId)];
1181 }
1182 
1183 int TNEANet::GetIntAttrIndN(const TStr& attr) {
1184  return KeyToIndexTypeN.GetDat(attr).Val2.Val;
1185 }
1186 
1187 int TNEANet::GetAttrIndN(const TStr& attr) {
1188  return KeyToIndexTypeN.GetDat(attr).Val2.Val;
1189 }
1190 
1191 TInt TNEANet::GetIntAttrDatE(const int& EId, const TStr& attr) {
1192  return VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EdgeH.GetKeyId(EId)];
1193 }
1194 
1195 TIntV TNEANet::GetIntVAttrDatE(const int& EId, const TStr& attr) {
1196  TInt location = CheckDenseOrSparseE(attr);
1197  if (location != 0) return VecOfIntVecVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EdgeH.GetKeyId(EId)];
1198  else return VecOfIntHashVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EdgeH.GetKeyId(EId)];
1199 }
1200 
1201 TStr TNEANet::GetStrAttrDatE(const int& EId, const TStr& attr) {
1202  return VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EdgeH.GetKeyId(EId)];
1203 }
1204 
1205 TFlt TNEANet::GetFltAttrDatE(const int& EId, const TStr& attr) {
1206  return VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EdgeH.GetKeyId(EId)];
1207 }
1208 
1209 TInt TNEANet::GetIntAttrIndDatE(const int& EId, const int& index) {
1210  return VecOfIntVecsE[index][EdgeH.GetKeyId(EId)];
1211 }
1212 
1213 TStr TNEANet::GetStrAttrIndDatE(const int& EId, const int& index) {
1214  return VecOfStrVecsE[index][EdgeH.GetKeyId(EId)];
1215 }
1216 
1217 TFlt TNEANet::GetFltAttrIndDatE(const int& EId, const int& index) {
1218  return VecOfFltVecsE[index][EdgeH.GetKeyId(EId)];
1219 }
1220 
1221 int TNEANet::GetIntAttrIndE(const TStr& attr) {
1222  return KeyToIndexTypeE.GetDat(attr).Val2.Val;
1223 }
1224 
1225 int TNEANet::GetAttrIndE(const TStr& attr) {
1226  return KeyToIndexTypeE.GetDat(attr).Val2.Val;
1227 }
1228 
1229 int TNEANet::DelAttrDatN(const int& NId, const TStr& attr) {
1230  TInt vecType = KeyToIndexTypeN(attr).Val1;
1231  if (vecType == IntType) {
1233  } else if (vecType == StrType) {
1235  } else if (vecType == FltType) {
1237  } else if (vecType ==IntVType) {
1238  TInt location = CheckDenseOrSparseN(attr);
1239  if (location == 0) VecOfIntHashVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NodeH.GetKeyId(NId)] = TIntV();
1241  } else {
1242  return -1;
1243  }
1244  return 0;
1245 }
1246 
1247 int TNEANet::DelAttrDatE(const int& EId, const TStr& attr) {
1248  // TODO(nkhadke): add error checking
1249  TInt vecType = KeyToIndexTypeE(attr).Val1;
1250  if (vecType == IntType) {
1252  } else if (vecType == StrType) {
1254  } else if (vecType == FltType) {
1256  } else if (vecType == IntVType) {
1257  TInt location = CheckDenseOrSparseE(attr);
1258  if (location == 0) VecOfIntHashVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EdgeH.GetKeyId(EId)] = TIntV();
1260  } else {
1261  return -1;
1262  }
1263  return 0;
1264 }
1265 
1266 int TNEANet::AddIntAttrN(const TStr& attr, TInt defaultValue){
1267  int i;
1268  TInt CurrLen;
1269  TVec<TInt> NewVec;
1270  CurrLen = VecOfIntVecsN.Len();
1271  KeyToIndexTypeN.AddDat(attr, TIntPr(IntType, CurrLen));
1272  NewVec = TVec<TInt>();
1273  for (i = 0; i < MxNId; i++) {
1274  NewVec.Ins(i, defaultValue);
1275  }
1276  VecOfIntVecsN.Add(NewVec);
1277  if (!IntDefaultsN.IsKey(attr)) {
1278  IntDefaultsN.AddDat(attr, defaultValue);
1279  } else {
1280  return -1;
1281  }
1282  return 0;
1283 }
1284 
1285 int TNEANet::AddIntVAttrN(const TStr& attr, TBool UseDense){
1286  TInt CurrLen;
1287  if (UseDense) {
1288  CurrLen = VecOfIntVecVecsN.Len();
1289  KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
1290  KeyToDenseN.AddDat(attr, true);
1291  TVec<TIntV> NewVec = TVec<TIntV>(MxNId);
1292  VecOfIntVecVecsN.Add(NewVec);
1293  } else {
1294  CurrLen = VecOfIntHashVecsN.Len();
1295  KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
1296  KeyToDenseN.AddDat(attr, false);
1297  THash<TInt, TIntV> NewHash;
1298  VecOfIntHashVecsN.Add(NewHash);
1299  }
1300  return 0;
1301 }
1302 
1303 int TNEANet::AddStrAttrN(const TStr& attr, TStr defaultValue) {
1304  int i;
1305  TInt CurrLen;
1306  TVec<TStr> NewVec;
1307  CurrLen = VecOfStrVecsN.Len();
1308  KeyToIndexTypeN.AddDat(attr, TIntPr(StrType, CurrLen));
1309  NewVec = TVec<TStr>();
1310  for (i = 0; i < MxNId; i++) {
1311  NewVec.Ins(i, defaultValue);
1312  }
1313  VecOfStrVecsN.Add(NewVec);
1314  if (!StrDefaultsN.IsKey(attr)) {
1315  StrDefaultsN.AddDat(attr, defaultValue);
1316  } else {
1317  return -1;
1318  }
1319  return 0;
1320 }
1321 
1322 int TNEANet::AddFltAttrN(const TStr& attr, TFlt defaultValue) {
1323  // TODO(nkhadke): add error checking
1324  int i;
1325  TInt CurrLen;
1326  TVec<TFlt> NewVec;
1327  CurrLen = VecOfFltVecsN.Len();
1328  KeyToIndexTypeN.AddDat(attr, TIntPr(FltType, CurrLen));
1329  NewVec = TVec<TFlt>();
1330  for (i = 0; i < MxNId; i++) {
1331  NewVec.Ins(i, defaultValue);
1332  }
1333  VecOfFltVecsN.Add(NewVec);
1334  if (!FltDefaultsN.IsKey(attr)) {
1335  FltDefaultsN.AddDat(attr, defaultValue);
1336  } else {
1337  return -1;
1338  }
1339  return 0;
1340 }
1341 
1342 int TNEANet::AddIntAttrE(const TStr& attr, TInt defaultValue){
1343  // TODO(nkhadke): add error checking
1344  int i;
1345  TInt CurrLen;
1346  TVec<TInt> NewVec;
1347  CurrLen = VecOfIntVecsE.Len();
1348  KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
1349  NewVec = TVec<TInt>();
1350  for (i = 0; i < MxEId; i++) {
1351  NewVec.Ins(i, defaultValue);
1352  }
1353  VecOfIntVecsE.Add(NewVec);
1354  if (!IntDefaultsE.IsKey(attr)) {
1355  IntDefaultsE.AddDat(attr, defaultValue);
1356  } else {
1357  return -1;
1358  }
1359  return 0;
1360 }
1361 
1362 int TNEANet::AddIntVAttrE(const TStr& attr, TBool UseDense){
1363  TInt CurrLen;
1364  if (UseDense) {
1365  CurrLen = VecOfIntVecVecsE.Len();
1366  KeyToIndexTypeE.AddDat(attr, TIntPr(IntVType, CurrLen));
1367  KeyToDenseE.AddDat(attr, true);
1368  TVec<TIntV> NewVec = TVec<TIntV>(MxEId);
1369  VecOfIntVecVecsE.Add(NewVec);
1370  } else {
1371  CurrLen = VecOfIntHashVecsE.Len();
1372  KeyToIndexTypeE.AddDat(attr, TIntPr(IntVType, CurrLen));
1373  KeyToDenseE.AddDat(attr, false);
1374  THash<TInt, TIntV> NewHash;
1375  VecOfIntHashVecsE.Add(NewHash);
1376  }
1377  return 0;
1378 }
1379 
1380 int TNEANet::AddStrAttrE(const TStr& attr, TStr defaultValue) {
1381  int i;
1382  TInt CurrLen;
1383  TVec<TStr> NewVec;
1384  CurrLen = VecOfStrVecsE.Len();
1385  KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
1386  NewVec = TVec<TStr>();
1387  for (i = 0; i < MxEId; i++) {
1388  NewVec.Ins(i, defaultValue);
1389  }
1390  VecOfStrVecsE.Add(NewVec);
1391  if (!StrDefaultsE.IsKey(attr)) {
1392  StrDefaultsE.AddDat(attr, defaultValue);
1393  } else {
1394  return -1;
1395  }
1396  return 0;
1397 }
1398 
1399 int TNEANet::AddFltAttrE(const TStr& attr, TFlt defaultValue) {
1400  int i;
1401  TInt CurrLen;
1402  TVec<TFlt> NewVec;
1403  CurrLen = VecOfFltVecsE.Len();
1404  KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
1405  NewVec = TVec<TFlt>();
1406  for (i = 0; i < MxEId; i++) {
1407  NewVec.Ins(i, defaultValue);
1408  }
1409  VecOfFltVecsE.Add(NewVec);
1410  if (!FltDefaultsE.IsKey(attr)) {
1411  FltDefaultsE.AddDat(attr, defaultValue);
1412  } else {
1413  return -1;
1414  }
1415  return 0;
1416 }
1417 
1418 int TNEANet::DelAttrN(const TStr& attr) {
1419  TInt vecType = KeyToIndexTypeN(attr).Val1;
1420  if (vecType == IntType) {
1422  if (IntDefaultsN.IsKey(attr)) {
1423  IntDefaultsN.DelKey(attr);
1424  }
1425  } else if (vecType == StrType) {
1427  if (StrDefaultsN.IsKey(attr)) {
1428  StrDefaultsN.DelKey(attr);
1429  }
1430  } else if (vecType == FltType) {
1432  if (FltDefaultsN.IsKey(attr)) {
1433  FltDefaultsN.DelKey(attr);
1434  }
1435  } else if (vecType == IntVType) {
1436  TInt location = CheckDenseOrSparseN(attr);
1437  if (location == 1) VecOfIntVecVecsN[KeyToIndexTypeN.GetDat(attr).Val2] = TVec<TIntV>();
1439  KeyToDenseN.DelKey(attr);
1440  } else {
1441  return -1;
1442  }
1443  KeyToIndexTypeN.DelKey(attr);
1444  return 0;
1445 }
1446 
1447 int TNEANet::DelAttrE(const TStr& attr) {
1448  TInt vecType = KeyToIndexTypeE(attr).Val1;
1449  if (vecType == IntType) {
1451  if (IntDefaultsE.IsKey(attr)) {
1452  IntDefaultsE.DelKey(attr);
1453  }
1454  } else if (vecType == StrType) {
1456  if (StrDefaultsE.IsKey(attr)) {
1457  StrDefaultsE.DelKey(attr);
1458  }
1459  } else if (vecType == FltType) {
1461  if (FltDefaultsE.IsKey(attr)) {
1462  FltDefaultsE.DelKey(attr);
1463  }
1464  } else {
1465  return -1;
1466  }
1467  KeyToIndexTypeE.DelKey(attr);
1468  return 0;
1469 }
1470 
1471 // Return a small graph on 5 nodes and 6 edges.
1473  PNEANet Net = TNEANet::New();
1474  for (int i = 0; i < 5; i++) { Net->AddNode(i); }
1475  Net->AddEdge(0,1); Net->AddEdge(0,2);
1476  Net->AddEdge(0,3); Net->AddEdge(0,4);
1477  Net->AddEdge(1,2); Net->AddEdge(1,2);
1478  return Net;
1479 }
1480 
1481 void TNEANet::GetAttrNNames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const {
1482  for (TStrIntPrH::TIter it = KeyToIndexTypeN.BegI(); it < KeyToIndexTypeN.EndI(); it++) {
1483  if (it.GetDat().GetVal1() == IntType) {
1484  IntAttrNames.Add(it.GetKey());
1485  }
1486  if (it.GetDat().GetVal1() == FltType) {
1487  FltAttrNames.Add(it.GetKey());
1488  }
1489  if (it.GetDat().GetVal1() == StrType) {
1490  StrAttrNames.Add(it.GetKey());
1491  }
1492  }
1493 }
1494 
1495 void TNEANet::GetAttrENames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const {
1496  for (TStrIntPrH::TIter it = KeyToIndexTypeE.BegI(); it < KeyToIndexTypeE.EndI(); it++) {
1497  if (it.GetDat().GetVal1() == IntType) {
1498  IntAttrNames.Add(it.GetKey());
1499  }
1500  if (it.GetDat().GetVal1() == FltType) {
1501  FltAttrNames.Add(it.GetKey());
1502  }
1503  if (it.GetDat().GetVal1() == StrType) {
1504  StrAttrNames.Add(it.GetKey());
1505  }
1506  }
1507 }
1508 
1509 TFlt TNEANet::GetWeightOutEdges(const TNodeI& NI, const TStr& attr) {
1510  TNode Node = GetNode(NI.GetId());
1511  TIntV OutEIdV = Node.OutEIdV;
1512  TFlt total = 0;
1513  int len = Node.OutEIdV.Len();
1514  for (int i = 0; i < len; i++) {
1515  total += GetFltAttrDatE(Node.OutEIdV[i], attr);
1516  }
1517  return total;
1518 }
1519 
1520 void TNEANet::GetWeightOutEdgesV(TFltV& OutWeights, const TFltV& AttrVal) {
1521  for (TEdgeI it = BegEI(); it < EndEI(); it++) {
1522  int EId = it.GetId();
1523  int SrcId = it.GetSrcNId();
1524  OutWeights[SrcId] +=AttrVal[GetFltKeyIdE(EId)];
1525  }
1526 }
1527 
1528 bool TNEANet::IsFltAttrE(const TStr& attr) {
1529  return (KeyToIndexTypeE.IsKey(attr) &&
1530  KeyToIndexTypeE.GetDat(attr).Val1 == FltType);
1531 }
1532 
1533 bool TNEANet::IsIntAttrE(const TStr& attr) {
1534  return (KeyToIndexTypeE.IsKey(attr) &&
1535  KeyToIndexTypeE.GetDat(attr).Val1 == IntType);
1536 }
1537 
1538 bool TNEANet::IsStrAttrE(const TStr& attr) {
1539  return (KeyToIndexTypeE.IsKey(attr) &&
1540  KeyToIndexTypeE.GetDat(attr).Val1 == StrType);
1541 }
1542 
1543 int TNEANet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val) {
1544  if (!IsNode(NId)) {
1545  return -1;
1546  }
1547  return SAttrN.AddSAttrDat(NId, AttrName, Val);
1548 }
1549 
1550 int TNEANet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val) {
1551  if (!IsNode(NId)) {
1552  return -1;
1553  }
1554  return SAttrN.AddSAttrDat(NId, AttrId, Val);
1555 }
1556 
1557 int TNEANet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val) {
1558  if (!IsNode(NId)) {
1559  return -1;
1560  }
1561  return SAttrN.AddSAttrDat(NId, AttrName, Val);
1562 }
1563 
1564 int TNEANet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val) {
1565  if (!IsNode(NId)) {
1566  return -1;
1567  }
1568  return SAttrN.AddSAttrDat(NId, AttrId, Val);
1569 }
1570 
1571 int TNEANet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val) {
1572  if (!IsNode(NId)) {
1573  return -1;
1574  }
1575  return SAttrN.AddSAttrDat(NId, AttrName, Val);
1576 }
1577 
1578 int TNEANet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val) {
1579  if (!IsNode(NId)) {
1580  return -1;
1581  }
1582  return SAttrN.AddSAttrDat(NId, AttrId, Val);
1583 }
1584 
1585 int TNEANet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& Val) const {
1586  if (!IsNode(NId)) {
1587  return -1;
1588  }
1589  return SAttrN.GetSAttrDat(NId, AttrName, Val);
1590 }
1591 
1592 int TNEANet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& Val) const {
1593  if (!IsNode(NId)) {
1594  return -1;
1595  }
1596  return SAttrN.GetSAttrDat(NId, AttrId, Val);
1597 }
1598 
1599 int TNEANet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& Val) const {
1600  if (!IsNode(NId)) {
1601  return -1;
1602  }
1603  return SAttrN.GetSAttrDat(NId, AttrName, Val);
1604 }
1605 
1606 int TNEANet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& Val) const {
1607  if (!IsNode(NId)) {
1608  return -1;
1609  }
1610  return SAttrN.GetSAttrDat(NId, AttrId, Val);
1611 }
1612 
1613 int TNEANet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& Val) const {
1614  if (!IsNode(NId)) {
1615  return -1;
1616  }
1617  return SAttrN.GetSAttrDat(NId, AttrName, Val);
1618 }
1619 
1620 int TNEANet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& Val) const {
1621  if (!IsNode(NId)) {
1622  return -1;
1623  }
1624  return SAttrN.GetSAttrDat(NId, AttrId, Val);
1625 }
1626 
1627 int TNEANet::DelSAttrDatN(const TInt& NId, const TStr& AttrName) {
1628  if (!IsNode(NId)) {
1629  return -1;
1630  }
1631  return SAttrN.DelSAttrDat(NId, AttrName);
1632 }
1633 
1634 int TNEANet::DelSAttrDatN(const TInt& NId, const TInt& AttrId) {
1635  if (!IsNode(NId)) {
1636  return -1;
1637  }
1638  return SAttrN.DelSAttrDat(NId, AttrId);
1639 }
1640 
1641 int TNEANet::GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const {
1642  if (!IsNode(NId)) {
1643  return -1;
1644  }
1645  SAttrN.GetSAttrV(NId, AttrType, AttrV);
1646  return 0;
1647 }
1648 
1649 int TNEANet::GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const {
1650  return SAttrN.GetIdVSAttr(AttrName, IdV);
1651 }
1652 
1653 int TNEANet::GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const {
1654  return SAttrN.GetIdVSAttr(AttrId, IdV);
1655 }
1656 
1657 int TNEANet::AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId) {
1658  return SAttrN.AddSAttr(Name, AttrType, AttrId);
1659 }
1660 
1661 int TNEANet::GetSAttrIdN(const TStr& Name, TInt& AttrId, TAttrType& AttrType) const {
1662  return SAttrN.GetSAttrId(Name, AttrId, AttrType);
1663 }
1664 
1665 int TNEANet::GetSAttrNameN(const TInt& AttrId, TStr& Name, TAttrType& AttrType) const {
1666  return SAttrN.GetSAttrName(AttrId, Name, AttrType);
1667 }
1668 
1669 int TNEANet::AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TInt& Val) {
1670  if (!IsEdge(EId)) {
1671  return -1;
1672  }
1673  return SAttrE.AddSAttrDat(EId, AttrName, Val);
1674 }
1675 
1676 int TNEANet::AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TInt& Val) {
1677  if (!IsEdge(EId)) {
1678  return -1;
1679  }
1680  return SAttrE.AddSAttrDat(EId, AttrId, Val);
1681 }
1682 
1683 int TNEANet::AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TFlt& Val) {
1684  if (!IsEdge(EId)) {
1685  return -1;
1686  }
1687  return SAttrE.AddSAttrDat(EId, AttrName, Val);
1688 }
1689 
1690 int TNEANet::AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TFlt& Val) {
1691  if (!IsEdge(EId)) {
1692  return -1;
1693  }
1694  return SAttrE.AddSAttrDat(EId, AttrId, Val);
1695 }
1696 
1697 int TNEANet::AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TStr& Val) {
1698  if (!IsEdge(EId)) {
1699  return -1;
1700  }
1701  return SAttrE.AddSAttrDat(EId, AttrName, Val);
1702 }
1703 
1704 int TNEANet::AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TStr& Val) {
1705  if (!IsEdge(EId)) {
1706  return -1;
1707  }
1708  return SAttrE.AddSAttrDat(EId, AttrId, Val);
1709 }
1710 
1711 int TNEANet::GetSAttrDatE(const TInt& EId, const TStr& AttrName, TInt& Val) const {
1712  if (!IsEdge(EId)) {
1713  return -1;
1714  }
1715  return SAttrE.GetSAttrDat(EId, AttrName, Val);
1716 }
1717 
1718 int TNEANet::GetSAttrDatE(const TInt& EId, const TInt& AttrId, TInt& Val) const {
1719  if (!IsEdge(EId)) {
1720  return -1;
1721  }
1722  return SAttrE.GetSAttrDat(EId, AttrId, Val);
1723 }
1724 
1725 int TNEANet::GetSAttrDatE(const TInt& EId, const TStr& AttrName, TFlt& Val) const {
1726  if (!IsEdge(EId)) {
1727  return -1;
1728  }
1729  return SAttrE.GetSAttrDat(EId, AttrName, Val);
1730 }
1731 
1732 int TNEANet::GetSAttrDatE(const TInt& EId, const TInt& AttrId, TFlt& Val) const {
1733  if (!IsEdge(EId)) {
1734  return -1;
1735  }
1736  return SAttrE.GetSAttrDat(EId, AttrId, Val);
1737 }
1738 
1739 int TNEANet::GetSAttrDatE(const TInt& EId, const TStr& AttrName, TStr& Val) const {
1740  if (!IsEdge(EId)) {
1741  return -1;
1742  }
1743  return SAttrE.GetSAttrDat(EId, AttrName, Val);
1744 }
1745 
1746 int TNEANet::GetSAttrDatE(const TInt& EId, const TInt& AttrId, TStr& Val) const {
1747  if (!IsEdge(EId)) {
1748  return -1;
1749  }
1750  return SAttrE.GetSAttrDat(EId, AttrId, Val);
1751 }
1752 
1753 int TNEANet::DelSAttrDatE(const TInt& EId, const TStr& AttrName) {
1754  if (!IsEdge(EId)) {
1755  return -1;
1756  }
1757  return SAttrE.DelSAttrDat(EId, AttrName);
1758 }
1759 
1760 int TNEANet::DelSAttrDatE(const TInt& EId, const TInt& AttrId) {
1761  if (!IsEdge(EId)) {
1762  return -1;
1763  }
1764  return SAttrE.DelSAttrDat(EId, AttrId);
1765 }
1766 
1767 int TNEANet::GetSAttrVE(const TInt& EId, const TAttrType AttrType, TAttrPrV& AttrV) const {
1768  if (!IsEdge(EId)) {
1769  return -1;
1770  }
1771  SAttrE.GetSAttrV(EId, AttrType, AttrV);
1772  return 0;
1773 }
1774 
1775 int TNEANet::GetIdVSAttrE(const TStr& AttrName, TIntV& IdV) const {
1776  return SAttrE.GetIdVSAttr(AttrName, IdV);
1777 }
1778 
1779 int TNEANet::GetIdVSAttrE(const TInt& AttrId, TIntV& IdV) const {
1780  return SAttrE.GetIdVSAttr(AttrId, IdV);
1781 }
1782 
1783 int TNEANet::AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId) {
1784  return SAttrE.AddSAttr(Name, AttrType, AttrId);
1785 }
1786 
1787 int TNEANet::GetSAttrIdE(const TStr& Name, TInt& AttrId, TAttrType& AttrType) const {
1788  return SAttrE.GetSAttrId(Name, AttrId, AttrType);
1789 }
1790 
1791 int TNEANet::GetSAttrNameE(const TInt& AttrId, TStr& Name, TAttrType& AttrType) const {
1792  return SAttrE.GetSAttrName(AttrId, Name, AttrType);
1793 }
1794 
1796 // Undirected Graph
1797 bool TUndirNet::HasFlag(const TGraphFlag& Flag) const {
1798  return HasGraphFlag(TUndirNet::TNet, Flag);
1799 }
1800 
1801 // Add a node of ID NId to the graph.
1802 int TUndirNet::AddNode(int NId) {
1803  if (NId == -1) {
1804  NId = MxNId; MxNId++;
1805  } else {
1806  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1807  MxNId = TMath::Mx(NId+1, MxNId());
1808  }
1809  NodeH.AddDat(NId, TNode(NId));
1810  return NId;
1811 }
1812 
1814  if (NId == -1) {
1815  NId = MxNId; MxNId++;
1816  } else {
1817  if (IsNode(NId)) { return -1;}
1818  MxNId = TMath::Mx(NId+1, MxNId());
1819  }
1820  NodeH.AddDat(NId, TNode(NId));
1821  return NId;
1822 }
1823 
1824 // Add a node of ID NId to the graph and create edges to all nodes in vector NbrNIdV.
1825 int TUndirNet::AddNode(const int& NId, const TIntV& NbrNIdV) {
1826  int NewNId;
1827  if (NId == -1) {
1828  NewNId = MxNId; MxNId++;
1829  } else {
1830  IAssertR(! IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1831  NewNId = NId;
1832  MxNId = TMath::Mx(NewNId+1, MxNId());
1833  }
1834  TNode& Node = NodeH.AddDat(NewNId);
1835  Node.Id = NewNId;
1836  Node.NIdV = NbrNIdV;
1837  Node.NIdV.Sort();
1838  NEdges += Node.GetDeg();
1839  for (int i = 0; i < NbrNIdV.Len(); i++) {
1840  GetNode(NbrNIdV[i]).NIdV.AddSorted(NewNId);
1841  }
1842  return NewNId;
1843 }
1844 
1845 // Add a node of ID NId to the graph and create edges to all nodes in the vector NIdVId in the vector pool Pool).
1846 int TUndirNet::AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& NIdVId) {
1847  int NewNId;
1848  if (NId == -1) {
1849  NewNId = MxNId; MxNId++;
1850  } else {
1851  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1852  NewNId = NId;
1853  MxNId = TMath::Mx(NewNId+1, MxNId());
1854  }
1855  TNode& Node = NodeH.AddDat(NewNId);
1856  Node.Id = NewNId;
1857  Node.NIdV.GenExt(Pool.GetValVPt(NIdVId), Pool.GetVLen(NIdVId));
1858  Node.NIdV.Sort();
1859  NEdges += Node.GetDeg();
1860  return NewNId;
1861 }
1862 
1863 // Delete node of ID NId from the graph.
1864 void TUndirNet::DelNode(const int& NId) {
1865  { AssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist", NId));
1866  TInt Id(NId);
1867  SAttrN.DelSAttrId(Id);
1868  TNode& Node = GetNode(NId);
1869  NEdges -= Node.GetDeg();
1870  for (int e = 0; e < Node.GetDeg(); e++) {
1871  const int nbr = Node.GetNbrNId(e);
1872  if (nbr == NId) { continue; }
1873  TNode& N = GetNode(nbr);
1874  const int n = N.NIdV.SearchBin(NId);
1875  IAssert(n != -1); // if NId points to N, then N also should point back
1876  if (n!= -1) { N.NIdV.Del(n); }
1877  } }
1878  NodeH.DelKey(NId);
1879 }
1880 
1881 int TUndirNet::GetEdges() const {
1882  //int Edges = 0;
1883  //for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1884  // Edges += NodeH[N].GetDeg();
1885  //}
1886  //return Edges/2;
1887  return NEdges;
1888 }
1889 
1890 // Add an edge between SrcNId and DstNId to the graph.
1891 int TUndirNet::AddEdge(const int& SrcNId, const int& DstNId) {
1892  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1893  if (IsEdge(SrcNId, DstNId)) { return -2; } // edge already exists
1894  GetNode(SrcNId).NIdV.AddSorted(DstNId);
1895  if (SrcNId!=DstNId) { // not a self edge
1896  GetNode(DstNId).NIdV.AddSorted(SrcNId); }
1897  NEdges++;
1898  return -1; // no edge id
1899 }
1900 
1901 // Add an edge between SrcNId and DstNId to the graph.
1902 int TUndirNet::AddEdgeUnchecked(const int& SrcNId, const int& DstNId) {
1903  GetNode(SrcNId).NIdV.Add(DstNId);
1904  if (SrcNId!=DstNId) { // not a self edge
1905  GetNode(DstNId).NIdV.Add(SrcNId); }
1906  NEdges++;
1907  return -1; // no edge id
1908 }
1909 
1910 // Delete an edge between node IDs SrcNId and DstNId from the graph.
1911 void TUndirNet::DelEdge(const int& SrcNId, const int& DstNId) {
1912  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1913  { TNode& N = GetNode(SrcNId);
1914  const int n = N.NIdV.SearchBin(DstNId);
1915  TIntPr Id(SrcNId, DstNId);
1916  SAttrE.DelSAttrId(Id);
1917  if (n!= -1) { N.NIdV.Del(n); NEdges--; } }
1918  if (SrcNId != DstNId) { // not a self edge
1919  TNode& N = GetNode(DstNId);
1920  const int n = N.NIdV.SearchBin(SrcNId);
1921  if (n!= -1) { N.NIdV.Del(n); }
1922  }
1923 }
1924 
1925 // Test whether an edge between node IDs SrcNId and DstNId exists the graph.
1926 bool TUndirNet::IsEdge(const int& SrcNId, const int& DstNId) const {
1927  if (! IsNode(SrcNId) || ! IsNode(DstNId)) return false;
1928  return GetNode(SrcNId).IsNbrNId(DstNId);
1929 }
1930 
1931 // Return an iterator referring to edge (SrcNId, DstNId) in the graph.
1932 TUndirNet::TEdgeI TUndirNet::GetEI(const int& SrcNId, const int& DstNId) const {
1933  const int MnNId = TMath::Mn(SrcNId, DstNId);
1934  const int MxNId = TMath::Mx(SrcNId, DstNId);
1935  const TNodeI SrcNI = GetNI(MnNId);
1936  const int NodeN = SrcNI.NodeHI.GetDat().NIdV.SearchBin(MxNId);
1937  IAssert(NodeN != -1);
1938  return TEdgeI(SrcNI, EndNI(), NodeN);
1939 }
1940 
1941 
1942 // Get a vector IDs of all nodes in the graph.
1943 void TUndirNet::GetNIdV(TIntV& NIdV) const {
1944  NIdV.Gen(GetNodes(), 0);
1945  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1946  NIdV.Add(NodeH.GetKey(N)); }
1947 }
1948 
1949 // Defragment the graph.
1950 void TUndirNet::Defrag(const bool& OnlyNodeLinks) {
1951  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
1952  NodeH[n].NIdV.Pack();
1953  }
1954  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
1955  NodeH.Defrag();
1956  }
1957 }
1958 
1959 // Check the graph data structure for internal consistency.
1960 bool TUndirNet::IsOk(const bool& ThrowExcept) const {
1961  bool RetVal = true;
1962  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1963  const TNode& Node = NodeH[N];
1964  if (! Node.NIdV.IsSorted()) {
1965  const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", Node.GetId());
1966  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1967  RetVal=false;
1968  }
1969  int prevNId = -1;
1970  for (int e = 0; e < Node.GetDeg(); e++) {
1971  if (! IsNode(Node.GetNbrNId(e))) {
1972  const TStr Msg = TStr::Fmt("Edge %d --> %d: node %d does not exist.",
1973  Node.GetId(), Node.GetNbrNId(e), Node.GetNbrNId(e));
1974  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1975  RetVal=false;
1976  }
1977  if (e > 0 && prevNId == Node.GetNbrNId(e)) {
1978  const TStr Msg = TStr::Fmt("Node %d has duplicate edge %d --> %d.",
1979  Node.GetId(), Node.GetId(), Node.GetNbrNId(e));
1980  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1981  RetVal=false;
1982  }
1983  prevNId = Node.GetNbrNId(e);
1984  }
1985  }
1986  int EdgeCnt = 0;
1987  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) { EdgeCnt++; }
1988  if (EdgeCnt != GetEdges()) {
1989  const TStr Msg = TStr::Fmt("Number of edges counter is corrupted: GetEdges():%d, EdgeCount:%d.", GetEdges(), EdgeCnt);
1990  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1991  RetVal=false;
1992  }
1993  return RetVal;
1994 }
1995 
1996 // Print the graph in a human readable form to an output stream OutF.
1997 void TUndirNet::Dump(FILE *OutF) const {
1998  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
1999  fprintf(OutF, "-------------------------------------------------\nUndirected Node Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
2000  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2001  const TNode& Node = NodeH[N];
2002  fprintf(OutF, " %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
2003  for (int edge = 0; edge < Node.GetDeg(); edge++) {
2004  fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
2005  fprintf(OutF, "\n");
2006  }
2007  fprintf(OutF, "\n");
2008 }
2009 
2010 // Return a small graph on 5 nodes and 5 edges.
2012  PUndirNet Graph = TUndirNet::New();
2013  for (int i = 0; i < 5; i++) { Graph->AddNode(i); }
2014  Graph->AddEdge(0,1); Graph->AddEdge(0,2);
2015  Graph->AddEdge(0,3); Graph->AddEdge(0,4);
2016  Graph->AddEdge(1,2);
2017  return Graph;
2018 }
2019 
2020 int TUndirNet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val) {
2021  if (!IsNode(NId)) {
2022  return -1;
2023  }
2024  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2025 }
2026 
2027 int TUndirNet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val) {
2028  if (!IsNode(NId)) {
2029  return -1;
2030  }
2031  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2032 }
2033 
2034 int TUndirNet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val) {
2035  if (!IsNode(NId)) {
2036  return -1;
2037  }
2038  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2039 }
2040 
2041 int TUndirNet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val) {
2042  if (!IsNode(NId)) {
2043  return -1;
2044  }
2045  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2046 }
2047 
2048 int TUndirNet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val) {
2049  if (!IsNode(NId)) {
2050  return -1;
2051  }
2052  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2053 }
2054 
2055 int TUndirNet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val) {
2056  if (!IsNode(NId)) {
2057  return -1;
2058  }
2059  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2060 }
2061 
2062 int TUndirNet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& Val) const {
2063  if (!IsNode(NId)) {
2064  return -1;
2065  }
2066  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2067 }
2068 
2069 int TUndirNet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& Val) const {
2070  if (!IsNode(NId)) {
2071  return -1;
2072  }
2073  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2074 }
2075 
2076 int TUndirNet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& Val) const {
2077  if (!IsNode(NId)) {
2078  return -1;
2079  }
2080  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2081 }
2082 
2083 int TUndirNet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& Val) const {
2084  if (!IsNode(NId)) {
2085  return -1;
2086  }
2087  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2088 }
2089 
2090 int TUndirNet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& Val) const {
2091  if (!IsNode(NId)) {
2092  return -1;
2093  }
2094  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2095 }
2096 
2097 int TUndirNet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& Val) const {
2098  if (!IsNode(NId)) {
2099  return -1;
2100  }
2101  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2102 }
2103 
2104 int TUndirNet::DelSAttrDatN(const TInt& NId, const TStr& AttrName) {
2105  if (!IsNode(NId)) {
2106  return -1;
2107  }
2108  return SAttrN.DelSAttrDat(NId, AttrName);
2109 }
2110 
2111 int TUndirNet::DelSAttrDatN(const TInt& NId, const TInt& AttrId) {
2112  if (!IsNode(NId)) {
2113  return -1;
2114  }
2115  return SAttrN.DelSAttrDat(NId, AttrId);
2116 }
2117 
2118 int TUndirNet::GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const {
2119  if (!IsNode(NId)) {
2120  return -1;
2121  }
2122  SAttrN.GetSAttrV(NId, AttrType, AttrV);
2123  return 0;
2124 }
2125 
2126 int TUndirNet::GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const {
2127  return SAttrN.GetIdVSAttr(AttrName, IdV);
2128 }
2129 
2130 int TUndirNet::GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const {
2131  return SAttrN.GetIdVSAttr(AttrId, IdV);
2132 }
2133 
2134 int TUndirNet::AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId) {
2135  return SAttrN.AddSAttr(Name, AttrType, AttrId);
2136 }
2137 
2138 int TUndirNet::GetSAttrIdN(const TStr& Name, TInt& AttrId, TAttrType& AttrType) const {
2139  return SAttrN.GetSAttrId(Name, AttrId, AttrType);
2140 }
2141 
2142 int TUndirNet::GetSAttrNameN(const TInt& AttrId, TStr& Name, TAttrType& AttrType) const {
2143  return SAttrN.GetSAttrName(AttrId, Name, AttrType);
2144 }
2145 
2146 TIntPr TUndirNet::OrderEdgeNodes(const int& SrcNId, const int& DstNId) const{
2147  if (SrcNId < DstNId) {
2148  return TIntPr(SrcNId, DstNId);
2149  }
2150  return TIntPr(DstNId, SrcNId);
2151 }
2152 
2153 int TUndirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val) {
2154  if (!IsEdge(SrcNId, DstNId)) {
2155  return -1;
2156  }
2157  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2158  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2159 }
2160 
2161 int TUndirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val) {
2162  if (!IsEdge(SrcNId, DstNId)) {
2163  return -1;
2164  }
2165  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2166  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2167 }
2168 
2169 int TUndirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val) {
2170  if (!IsEdge(SrcNId, DstNId)) {
2171  return -1;
2172  }
2173  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2174  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2175 }
2176 
2177 int TUndirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val) {
2178  if (!IsEdge(SrcNId, DstNId)) {
2179  return -1;
2180  }
2181  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2182  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2183 }
2184 
2185 int TUndirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val) {
2186  if (!IsEdge(SrcNId, DstNId)) {
2187  return -1;
2188  }
2189  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2190  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2191 }
2192 
2193 int TUndirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val) {
2194  if (!IsEdge(SrcNId, DstNId)) {
2195  return -1;
2196  }
2197  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2198  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2199 }
2200 
2201 int TUndirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& Val) const {
2202  if (!IsEdge(SrcNId, DstNId)) {
2203  return -1;
2204  }
2205  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2206  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2207 }
2208 
2209 int TUndirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& Val) const {
2210  if (!IsEdge(SrcNId, DstNId)) {
2211  return -1;
2212  }
2213  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2214  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2215 }
2216 
2217 int TUndirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& Val) const {
2218  if (!IsEdge(SrcNId, DstNId)) {
2219  return -1;
2220  }
2221  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2222  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2223 }
2224 
2225 int TUndirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& Val) const {
2226  if (!IsEdge(SrcNId, DstNId)) {
2227  return -1;
2228  }
2229  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2230  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2231 }
2232 
2233 int TUndirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& Val) const {
2234  if (!IsEdge(SrcNId, DstNId)) {
2235  return -1;
2236  }
2237  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2238  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2239 }
2240 
2241 int TUndirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& Val) const {
2242  if (!IsEdge(SrcNId, DstNId)) {
2243  return -1;
2244  }
2245  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2246  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2247 }
2248 
2249 int TUndirNet::DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName) {
2250  if (!IsEdge(SrcNId, DstNId)) {
2251  return -1;
2252  }
2253  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2254  return SAttrE.DelSAttrDat(EId, AttrName);
2255 }
2256 
2257 int TUndirNet::DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId) {
2258  if (!IsEdge(SrcNId, DstNId)) {
2259  return -1;
2260  }
2261  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2262  return SAttrE.DelSAttrDat(EId, AttrId);
2263 }
2264 
2265 int TUndirNet::GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const {
2266  if (!IsEdge(SrcNId, DstNId)) {
2267  return -1;
2268  }
2269  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2270  SAttrE.GetSAttrV(EId, AttrType, AttrV);
2271  return 0;
2272 }
2273 
2274 int TUndirNet::GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const {
2275  return SAttrE.GetIdVSAttr(AttrName, IdV);
2276 }
2277 
2278 int TUndirNet::GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const {
2279  return SAttrE.GetIdVSAttr(AttrId, IdV);
2280 }
2281 
2282 int TUndirNet::AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId) {
2283  return SAttrE.AddSAttr(Name, AttrType, AttrId);
2284 }
2285 
2286 int TUndirNet::GetSAttrIdE(const TStr& Name, TInt& AttrId, TAttrType& AttrType) const {
2287  return SAttrE.GetSAttrId(Name, AttrId, AttrType);
2288 }
2289 
2290 int TUndirNet::GetSAttrNameE(const TInt& AttrId, TStr& Name, TAttrType& AttrType) const {
2291  return SAttrE.GetSAttrName(AttrId, Name, AttrType);
2292 }
2293 
2295 // Directed Node Graph
2296 bool TDirNet::HasFlag(const TGraphFlag& Flag) const {
2297  return HasGraphFlag(TDirNet::TNet, Flag);
2298 }
2299 
2300 int TDirNet::AddNode(int NId) {
2301  if (NId == -1) {
2302  NId = MxNId; MxNId++;
2303  } else {
2304  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
2305  MxNId = TMath::Mx(NId+1, MxNId());
2306  }
2307  NodeH.AddDat(NId, TNode(NId));
2308  return NId;
2309 }
2310 
2312  if (NId == -1) {
2313  NId = MxNId; MxNId++;
2314  } else {
2315  if (IsNode(NId)) { return -1;}
2316  MxNId = TMath::Mx(NId+1, MxNId());
2317  }
2318  NodeH.AddDat(NId, TNode(NId));
2319  return NId;
2320 }
2321 
2322 // add a node with a list of neighbors
2323 // (use TDirNet::IsOk to check whether the graph is consistent)
2324 int TDirNet::AddNode(const int& NId, const TIntV& InNIdV, const TIntV& OutNIdV) {
2325  int NewNId;
2326  if (NId == -1) {
2327  NewNId = MxNId; MxNId++;
2328  } else {
2329  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
2330  NewNId = NId;
2331  MxNId = TMath::Mx(NewNId+1, MxNId());
2332  }
2333  TNode& Node = NodeH.AddDat(NewNId);
2334  Node.Id = NewNId;
2335  Node.InNIdV = InNIdV;
2336  Node.OutNIdV = OutNIdV;
2337  Node.InNIdV.Sort();
2338  Node.OutNIdV.Sort();
2339  return NewNId;
2340 }
2341 
2342 // add a node from a vector pool
2343 // (use TDirNet::IsOk to check whether the graph is consistent)
2344 int TDirNet::AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& SrcVId, const int& DstVId) {
2345  int NewNId;
2346  if (NId == -1) {
2347  NewNId = MxNId; MxNId++;
2348  } else {
2349  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
2350  NewNId = NId;
2351  MxNId = TMath::Mx(NewNId+1, MxNId());
2352  }
2353  TNode& Node = NodeH.AddDat(NewNId);
2354  Node.Id = NewNId;
2355  Node.InNIdV.GenExt(Pool.GetValVPt(SrcVId), Pool.GetVLen(SrcVId));
2356  Node.OutNIdV.GenExt(Pool.GetValVPt(DstVId), Pool.GetVLen(DstVId));
2357  Node.InNIdV.Sort();
2358  Node.OutNIdV.Sort();
2359  return NewNId;
2360 }
2361 
2362 void TDirNet::DelNode(const int& NId) {
2363  { TNode& Node = GetNode(NId);
2364  TInt Id(NId);
2365  SAttrN.DelSAttrId(Id);
2366  for (int e = 0; e < Node.GetOutDeg(); e++) {
2367  const int nbr = Node.GetOutNId(e);
2368  if (nbr == NId) { continue; }
2369  TNode& N = GetNode(nbr);
2370  const int n = N.InNIdV.SearchBin(NId);
2371  if (n!= -1) { N.InNIdV.Del(n); }
2372  }
2373  for (int e = 0; e < Node.GetInDeg(); e++) {
2374  const int nbr = Node.GetInNId(e);
2375  if (nbr == NId) { continue; }
2376  TNode& N = GetNode(nbr);
2377  const int n = N.OutNIdV.SearchBin(NId);
2378  if (n!= -1) { N.OutNIdV.Del(n); }
2379  } }
2380  NodeH.DelKey(NId);
2381 }
2382 
2383 int TDirNet::GetEdges() const {
2384  int edges=0;
2385  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2386  edges+=NodeH[N].GetOutDeg();
2387  }
2388  return edges;
2389 }
2390 
2391 int TDirNet::AddEdge(const int& SrcNId, const int& DstNId) {
2392  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
2393  //IAssert(! IsEdge(SrcNId, DstNId));
2394  if (IsEdge(SrcNId, DstNId)) { return -2; }
2395  GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
2396  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
2397  return -1; // no edge id
2398 }
2399 
2400 int TDirNet::AddEdgeUnchecked(const int& SrcNId, const int& DstNId) {
2401  GetNode(SrcNId).OutNIdV.Add(DstNId);
2402  GetNode(DstNId).InNIdV.Add(SrcNId);
2403  return -1; // no edge id
2404 }
2405 
2406 void TDirNet::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
2407  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
2408  { TNode& N = GetNode(SrcNId);
2409  TIntPr Id(SrcNId, DstNId);
2410  SAttrE.DelSAttrId(Id);
2411  const int n = N.OutNIdV.SearchBin(DstNId);
2412  if (n!= -1) { N.OutNIdV.Del(n); } }
2413  { TNode& N = GetNode(DstNId);
2414  const int n = N.InNIdV.SearchBin(SrcNId);
2415  if (n!= -1) { N.InNIdV.Del(n); } }
2416  if (! IsDir) {
2417  { TNode& N = GetNode(SrcNId);
2418  const int n = N.InNIdV.SearchBin(DstNId);
2419  if (n!= -1) { N.InNIdV.Del(n); } }
2420  { TNode& N = GetNode(DstNId);
2421  const int n = N.OutNIdV.SearchBin(SrcNId);
2422  if (n!= -1) { N.OutNIdV.Del(n); } }
2423  }
2424 }
2425 
2426 bool TDirNet::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
2427  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
2428  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
2429  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
2430 }
2431 
2432 TDirNet::TEdgeI TDirNet::GetEI(const int& SrcNId, const int& DstNId) const {
2433  const TNodeI SrcNI = GetNI(SrcNId);
2434  const int NodeN = SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
2435  IAssert(NodeN != -1);
2436  return TEdgeI(SrcNI, EndNI(), NodeN);
2437 }
2438 
2439 void TDirNet::GetNIdV(TIntV& NIdV) const {
2440  NIdV.Gen(GetNodes(), 0);
2441  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2442  NIdV.Add(NodeH.GetKey(N)); }
2443 }
2444 
2445 void TDirNet::Defrag(const bool& OnlyNodeLinks) {
2446  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
2447  TNode& Node = NodeH[n];
2448  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
2449  }
2450  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
2451 }
2452 
2453 // for each node check that their neighbors are also nodes
2454 bool TDirNet::IsOk(const bool& ThrowExcept) const {
2455  bool RetVal = true;
2456  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2457  const TNode& Node = NodeH[N];
2458  if (! Node.OutNIdV.IsSorted()) {
2459  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
2460  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
2461  }
2462  if (! Node.InNIdV.IsSorted()) {
2463  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
2464  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
2465  }
2466  // check out-edges
2467  int prevNId = -1;
2468  for (int e = 0; e < Node.GetOutDeg(); e++) {
2469  if (! IsNode(Node.GetOutNId(e))) {
2470  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
2471  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
2472  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
2473  }
2474  if (e > 0 && prevNId == Node.GetOutNId(e)) {
2475  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
2476  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
2477  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
2478  }
2479  prevNId = Node.GetOutNId(e);
2480  }
2481  // check in-edges
2482  prevNId = -1;
2483  for (int e = 0; e < Node.GetInDeg(); e++) {
2484  if (! IsNode(Node.GetInNId(e))) {
2485  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
2486  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
2487  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
2488  }
2489  if (e > 0 && prevNId == Node.GetInNId(e)) {
2490  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
2491  Node.GetId(), Node.GetId(), Node.GetInNId(e));
2492  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
2493  }
2494  prevNId = Node.GetInNId(e);
2495  }
2496  }
2497  return RetVal;
2498 }
2499 
2500 void TDirNet::Dump(FILE *OutF) const {
2501  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
2502  fprintf(OutF, "-------------------------------------------------\nDirected Node Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
2503  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2504  const TNode& Node = NodeH[N];
2505  fprintf(OutF, " %*d]\n", NodePlaces, Node.GetId());
2506  fprintf(OutF, " in [%d]", Node.GetInDeg());
2507  for (int edge = 0; edge < Node.GetInDeg(); edge++) {
2508  fprintf(OutF, " %*d", NodePlaces, Node.GetInNId(edge)); }
2509  fprintf(OutF, "\n out[%d]", Node.GetOutDeg());
2510  for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
2511  fprintf(OutF, " %*d", NodePlaces, Node.GetOutNId(edge)); }
2512  fprintf(OutF, "\n");
2513  }
2514  fprintf(OutF, "\n");
2515 }
2516 
2518  PDirNet G = TDirNet::New();
2519  for (int i = 0; i < 5; i++) { G->AddNode(i); }
2520  G->AddEdge(0,1); G->AddEdge(1,2); G->AddEdge(0,2);
2521  G->AddEdge(1,3); G->AddEdge(3,4); G->AddEdge(2,3);
2522  return G;
2523 }
2524 
2525 int TDirNet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val) {
2526  if (!IsNode(NId)) {
2527  return -1;
2528  }
2529  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2530 }
2531 
2532 int TDirNet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val) {
2533  if (!IsNode(NId)) {
2534  return -1;
2535  }
2536  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2537 }
2538 
2539 int TDirNet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val) {
2540  if (!IsNode(NId)) {
2541  return -1;
2542  }
2543  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2544 }
2545 
2546 int TDirNet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val) {
2547  if (!IsNode(NId)) {
2548  return -1;
2549  }
2550  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2551 }
2552 
2553 int TDirNet::AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val) {
2554  if (!IsNode(NId)) {
2555  return -1;
2556  }
2557  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2558 }
2559 
2560 int TDirNet::AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val) {
2561  if (!IsNode(NId)) {
2562  return -1;
2563  }
2564  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2565 }
2566 
2567 int TDirNet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& Val) const {
2568  if (!IsNode(NId)) {
2569  return -1;
2570  }
2571  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2572 }
2573 
2574 int TDirNet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& Val) const {
2575  if (!IsNode(NId)) {
2576  return -1;
2577  }
2578  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2579 }
2580 
2581 int TDirNet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& Val) const {
2582  if (!IsNode(NId)) {
2583  return -1;
2584  }
2585  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2586 }
2587 
2588 int TDirNet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& Val) const {
2589  if (!IsNode(NId)) {
2590  return -1;
2591  }
2592  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2593 }
2594 
2595 int TDirNet::GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& Val) const {
2596  if (!IsNode(NId)) {
2597  return -1;
2598  }
2599  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2600 }
2601 
2602 int TDirNet::GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& Val) const {
2603  if (!IsNode(NId)) {
2604  return -1;
2605  }
2606  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2607 }
2608 
2609 int TDirNet::DelSAttrDatN(const TInt& NId, const TStr& AttrName) {
2610  if (!IsNode(NId)) {
2611  return -1;
2612  }
2613  return SAttrN.DelSAttrDat(NId, AttrName);
2614 }
2615 
2616 int TDirNet::DelSAttrDatN(const TInt& NId, const TInt& AttrId) {
2617  if (!IsNode(NId)) {
2618  return -1;
2619  }
2620  return SAttrN.DelSAttrDat(NId, AttrId);
2621 }
2622 
2623 int TDirNet::GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const {
2624  if (!IsNode(NId)) {
2625  return -1;
2626  }
2627  SAttrN.GetSAttrV(NId, AttrType, AttrV);
2628  return 0;
2629 }
2630 
2631 int TDirNet::GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const {
2632  return SAttrN.GetIdVSAttr(AttrName, IdV);
2633 }
2634 
2635 int TDirNet::GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const {
2636  return SAttrN.GetIdVSAttr(AttrId, IdV);
2637 }
2638 
2639 int TDirNet::AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId) {
2640  return SAttrN.AddSAttr(Name, AttrType, AttrId);
2641 }
2642 
2643 int TDirNet::GetSAttrIdN(const TStr& Name, TInt& AttrId, TAttrType& AttrType) const {
2644  return SAttrN.GetSAttrId(Name, AttrId, AttrType);
2645 }
2646 
2647 int TDirNet::GetSAttrNameN(const TInt& AttrId, TStr& Name, TAttrType& AttrType) const {
2648  return SAttrN.GetSAttrName(AttrId, Name, AttrType);
2649 }
2650 
2651 int TDirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val) {
2652  if (!IsEdge(SrcNId, DstNId)) {
2653  return -1;
2654  }
2655  TIntPr EId(SrcNId, DstNId);
2656  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2657 }
2658 
2659 int TDirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val) {
2660  if (!IsEdge(SrcNId, DstNId)) {
2661  return -1;
2662  }
2663  TIntPr EId(SrcNId, DstNId);
2664  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2665 }
2666 
2667 int TDirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val) {
2668  if (!IsEdge(SrcNId, DstNId)) {
2669  return -1;
2670  }
2671  TIntPr EId(SrcNId, DstNId);
2672  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2673 }
2674 
2675 int TDirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val) {
2676  if (!IsEdge(SrcNId, DstNId)) {
2677  return -1;
2678  }
2679  TIntPr EId(SrcNId, DstNId);
2680  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2681 }
2682 
2683 int TDirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val) {
2684  if (!IsEdge(SrcNId, DstNId)) {
2685  return -1;
2686  }
2687  TIntPr EId(SrcNId, DstNId);
2688  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2689 }
2690 
2691 int TDirNet::AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val) {
2692  if (!IsEdge(SrcNId, DstNId)) {
2693  return -1;
2694  }
2695  TIntPr EId(SrcNId, DstNId);
2696  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2697 }
2698 
2699 int TDirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& Val) const {
2700  if (!IsEdge(SrcNId, DstNId)) {
2701  return -1;
2702  }
2703  TIntPr EId(SrcNId, DstNId);
2704  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2705 }
2706 
2707 int TDirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& Val) const {
2708  if (!IsEdge(SrcNId, DstNId)) {
2709  return -1;
2710  }
2711  TIntPr EId(SrcNId, DstNId);
2712  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2713 }
2714 
2715 int TDirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& Val) const {
2716  if (!IsEdge(SrcNId, DstNId)) {
2717  return -1;
2718  }
2719  TIntPr EId(SrcNId, DstNId);
2720  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2721 }
2722 
2723 int TDirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& Val) const {
2724  if (!IsEdge(SrcNId, DstNId)) {
2725  return -1;
2726  }
2727  TIntPr EId(SrcNId, DstNId);
2728  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2729 }
2730 
2731 int TDirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& Val) const {
2732  if (!IsEdge(SrcNId, DstNId)) {
2733  return -1;
2734  }
2735  TIntPr EId(SrcNId, DstNId);
2736  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2737 }
2738 
2739 int TDirNet::GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& Val) const {
2740  if (!IsEdge(SrcNId, DstNId)) {
2741  return -1;
2742  }
2743  TIntPr EId(SrcNId, DstNId);
2744  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2745 }
2746 
2747 int TDirNet::DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName) {
2748  if (!IsEdge(SrcNId, DstNId)) {
2749  return -1;
2750  }
2751  TIntPr EId(SrcNId, DstNId);
2752  return SAttrE.DelSAttrDat(EId, AttrName);
2753 }
2754 
2755 int TDirNet::DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId) {
2756  if (!IsEdge(SrcNId, DstNId)) {
2757  return -1;
2758  }
2759  TIntPr EId(SrcNId, DstNId);
2760  return SAttrE.DelSAttrDat(EId, AttrId);
2761 }
2762 
2763 int TDirNet::GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const {
2764  if (!IsEdge(SrcNId, DstNId)) {
2765  return -1;
2766  }
2767  TIntPr EId(SrcNId, DstNId);
2768  SAttrE.GetSAttrV(EId, AttrType, AttrV);
2769  return 0;
2770 }
2771 
2772 int TDirNet::GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const {
2773  return SAttrE.GetIdVSAttr(AttrName, IdV);
2774 }
2775 
2776 int TDirNet::GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const {
2777  return SAttrE.GetIdVSAttr(AttrId, IdV);
2778 }
2779 
2780 int TDirNet::AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId) {
2781  return SAttrE.AddSAttr(Name, AttrType, AttrId);
2782 }
2783 
2784 int TDirNet::GetSAttrIdE(const TStr& Name, TInt& AttrId, TAttrType& AttrType) const {
2785  return SAttrE.GetSAttrId(Name, AttrId, AttrType);
2786 }
2787 
2788 int TDirNet::GetSAttrNameE(const TInt& AttrId, TStr& Name, TAttrType& AttrType) const {
2789  return SAttrE.GetSAttrName(AttrId, Name, AttrType);
2790 }
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.cpp:1960
#define IAssert(Cond)
Definition: bd.h:262
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
Definition: network.cpp:751
TVec< TIntV > VecOfIntVecsN
Definition: network.h:2038
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
Definition: network.cpp:2426
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.cpp:1797
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
THash< TStr, TBool > KeyToDenseE
Definition: network.h:2033
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.cpp:2439
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
void IntVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2411
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2701
int GetAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr.
Definition: network.cpp:1225
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1212
int GetEdges() const
Returns the number of edges in the network.
Definition: network.cpp:2383
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.cpp:50
int GetId() const
Definition: network.h:1781
int DelSAttrDat(const TInt &Id, const TStr &AttrName)
Delete attribute with name AttrName for the given id Id.
Definition: attr.cpp:103
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2286
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
Definition: network.h:3295
void GetAttrENames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of edge attributes of the given type.
Definition: network.cpp:1495
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2276
bool IsKeyIdEqKeyN() const
Definition: hash.h:233
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2643
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:2623
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2784
#define IAssertR(Cond, Reason)
Definition: bd.h:265
int GetSrcNId() const
Definition: network.h:1782
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2705
THash< TStr, TFlt > FltDefaultsE
Definition: network.h:2037
int AddIntVAttrN(const TStr &attr, TBool UseDense=true)
Adds a new IntV node attribute to the hashmap.
Definition: network.cpp:1285
int AppendIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
Definition: network.h:2672
int AddFltAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2690
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns edge attribute value, converted to Str type.
Definition: network.cpp:430
enum TAttrType_ TAttrType
Types for tables, sparse and dense attributes.
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2138
TVec< TStrV > VecOfStrVecsE
Definition: network.h:2039
THash< TStr, TInt > IntDefaultsE
Definition: network.h:2035
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr (same as GetAttrIndN for compatibility...
Definition: network.cpp:1183
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node str attr iterator.
Definition: network.cpp:230
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
Gets the sum of the weights of all the outgoing edges of the node.
Definition: network.cpp:1509
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
Definition: network.cpp:1418
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.cpp:1950
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted for current node attr iterator.
Definition: network.cpp:206
bool IsStrAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Str attr exists for node NId and has default value.
Definition: network.cpp:198
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1189
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3234
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
Definition: network.cpp:2126
TInt CheckDenseOrSparseN(const TStr &attr) const
Return 1 if in Dense, 0 if in Sparse, -1 if neither.
Definition: network.h:2083
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: network.h:2438
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TVec< THash< TInt, TIntV > > VecOfIntHashVecsE
Definition: network.h:2042
int GetOutNId(const int &NodeN) const
Definition: network.h:3734
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2788
int GetSAttrVE(const TInt &EId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with id EId.
Definition: network.cpp:1767
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:1791
TNode & GetNode(const int &NId)
Definition: network.h:2005
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2421
int AddSAttrDatE(const TInt &EId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with id EId.
Definition: network.cpp:1669
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2429
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.cpp:1864
void IntVAttrValueEI(const TInt &EId, TVec< TIntV > &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2460
Directed network.
Definition: network.h:3714
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge flt attr iterator.
Definition: network.cpp:424
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: network.h:2019
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.cpp:456
TInt CheckDenseOrSparseE(const TStr &attr) const
Definition: network.h:2089
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge attr iterator.
Definition: network.cpp:398
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: network.h:2741
int AddIntVAttrDatE(const TEdgeI &EdgeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2695
TIter BegI() const
Definition: hash.h:213
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if attr exists for edge EId and has default value.
Definition: network.cpp:374
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Flt attr exists for edge NId and has default value.
Definition: network.cpp:394
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
const TNEANet * Graph
Definition: network.h:1796
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int attr iterator.
Definition: network.cpp:406
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2525
int GetSAttrName(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Given the attribute id AttrId, get the attribute name.
Definition: attr.cpp:233
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
Definition: network.cpp:1447
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2425
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2142
TIntV GetIntVAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of the intv attr from the edge attr value vector.
Definition: network.h:2744
void GenExt(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
Definition: ds.h:534
TStrIntPrH KeyToIndexTypeE
Definition: network.h:2031
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: network.h:2738
int GetNbrNId(const int &NodeN) const
Definition: network.h:3166
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.cpp:2311
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2567
TAttr SAttrN
Definition: network.h:2045
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3751
void DelEdge(const int &EId)
Deletes an edge with edge ID EId from the graph.
Definition: network.cpp:692
THash< TStr, TFlt > FltDefaultsN
Definition: network.h:2037
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: network.h:2595
Definition: fl.h:384
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2450
static PUndirNet GetSmallGraph()
Returns a small network on 5 nodes and 5 edges.
Definition: network.cpp:2011
int AddIntAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2680
TInt MxNId
Definition: network.h:2027
TIntV OutEIdV
Definition: network.h:1749
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
Definition: network.h:2711
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1792
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2396
TVec< TIntV > VecOfIntVecsE
Definition: network.h:2038
TIter EndI() const
Definition: hash.h:218
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2401
int GetInDeg() const
Definition: network.h:3731
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.cpp:444
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:1585
bool NodeAttrIsIntVDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int vector attr iterator. ...
Definition: network.cpp:222
virtual void DelNode(const int &NId)
Deletes node of ID NId from the graph.
Definition: network.cpp:531
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2647
void DelSAttrId(const TInt &Id)
Delete all attributes for the given id Id.
Definition: attr.cpp:124
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
const TKey & GetKey() const
Definition: hash.h:80
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1117
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
void Defrag()
Definition: hash.h:555
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:1926
Definition: dt.h:1383
TVec< TStrV > VecOfStrVecsN
Definition: network.h:2039
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Int attr exists for edge EId and has default value.
Definition: network.cpp:382
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
Definition: network.cpp:758
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
Definition: network.cpp:827
bool IsFltAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Flt attr exists for node NId and has default value.
Definition: network.cpp:202
int AddFltAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2664
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node flt attr iterator.
Definition: network.cpp:238
void IntVAttrValueNI(const TInt &NId, TVec< TIntV > &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2415
THash< TInt, TEdge > EdgeH
Definition: network.h:2029
void GetAttrNNames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of node attributes of the given type.
Definition: network.cpp:1481
int DelFromIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Deletes value from the TIntV attribute for the given node.
Definition: network.h:2675
int AddIntVAttrDatN(const TNodeI &NodeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2669
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.cpp:59
int GetAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr.
Definition: network.cpp:1187
TStr GetStrAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a string edge attr specified by edge iterator EdgeI and the attr index...
Definition: network.h:2763
void DelEdge(const int &SrcNId, const int &DstNId)
Deletes an edge between node IDs SrcNId and DstNId from the network.
Definition: network.cpp:1911
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Str attr exists for edge NId and has default value.
Definition: network.cpp:390
void DelKey(const TKey &Key)
Definition: hash.h:404
TAttr SAttrE
Definition: network.h:2046
int GetId() const
Returns ID of the current node.
Definition: network.h:1807
static const int Mn
Definition: dt.h:1138
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:1641
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:649
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:1783
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2104
TVec< TFltV > VecOfFltVecsE
Definition: network.h:2040
int GetFltKeyIdE(const int &EId)
Gets keyid for edge with id EId.
Definition: network.cpp:1149
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.cpp:1813
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:2031
const TDat & GetDat() const
Definition: hash.h:81
TInt GetIntAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: network.h:2735
int AddStrAttrDatN(const TNodeI &NodeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2659
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1730
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2020
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2470
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
Definition: hash.h:78
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2478
int GetSAttrDatE(const TInt &EId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with id EId.
Definition: network.cpp:1711
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:1787
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1728
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2651
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
Definition: network.cpp:46
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
Definition: network.cpp:1266
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: network.h:2021
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge with ID EId between node IDs SrcNId and DstNId to the graph.
Definition: network.cpp:622
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:1543
THashIter NodeHI
Definition: network.h:3184
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2699
THash< TStr, TStr > StrDefaultsN
Definition: network.h:2036
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
Definition: network.h:2392
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
Definition: network.cpp:2274
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
Definition: network.cpp:1380
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2708
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
Definition: network.h:2603
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
Definition: network.cpp:774
TInt GetIntAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of an int node attr specified by node iterator NodeI and the attr index.
Definition: network.h:2720
void IntVAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2456
int FFirstKeyId() const
Definition: hash.h:278
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.cpp:2454
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntV &IdV) const
Definition: attr.cpp:167
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:1665
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
Definition: network.h:2605
int GetDstNId() const
Definition: network.h:1783
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the network.
Definition: network.cpp:2406
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.cpp:2296
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
Definition: network.h:2015
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.cpp:2362
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns node attribute value, converted to Str type.
Definition: network.cpp:246
TVec< TVec< TIntV > > VecOfIntVecVecsE
Definition: network.h:2041
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2201
static TStr GetNullStr()
Definition: dt.cpp:1626
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2442
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2433
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.cpp:1943
Directed multigraph with node edge attributes.
Definition: network.h:1741
void LoadNetworkShM(TShMIn &ShMIn)
load network from shared memory for this network
Definition: network.cpp:2
TInt MxEId
Definition: network.h:2027
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1519
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2153
TStr GetStr() const
Definition: dt.h:678
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the network.
Definition: network.cpp:1891
int GetId() const
Definition: network.h:3160
void GetSAttrV(const TInt &Id, const TAttrType AttrType, TAttrPrV &AttrV) const
Get a list of all attributes of type AttrType for the given id Id.
Definition: attr.cpp:139
bool IsIntAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
Definition: network.cpp:1533
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
Definition: network.cpp:1472
bool IsIntVAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if IntV attr exists for edge EId and is an empty vector.
Definition: network.cpp:386
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2639
Definition: dt.h:1134
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2282
TEdge & GetEdge(const int &EId)
Definition: network.h:2007
int GetOutDeg() const
Definition: network.h:1759
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
Definition: network.cpp:1997
bool IsFltAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
Definition: network.cpp:1528
int GetDeg() const
Definition: network.h:3161
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3798
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2405
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: network.h:2302
bool EdgeAttrIsIntVDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int vector attr iterator.
Definition: network.cpp:412
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
Definition: network.cpp:1303
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
Definition: ds.h:1180
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
Definition: ds.h:932
int GetId() const
Definition: network.h:3729
bool IsIntAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Int attr exists for node NId and has default value.
Definition: network.cpp:190
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1867
int DelAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
Definition: network.h:2771
Definition: ds.h:32
int AddIntVAttrE(const TStr &attr, TBool UseDense=true)
Adds a new IntV edge attribute to the hashmap.
Definition: network.cpp:1362
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2474
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2249
TIntV InNIdV
Definition: network.h:3722
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the network.
Definition: network.cpp:2391
THash< TStr, TStr > StrDefaultsE
Definition: network.h:2036
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2466
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: network.h:2023
int GetEdges() const
Returns the number of edges in the graph.
Definition: network.h:2576
void GetKeyV(TVec< TKey > &KeyV) const
Definition: hash.h:484
Undirected network.
Definition: network.h:3145
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:1661
int GetOutEId(const int &EdgeN) const
Definition: network.h:1761
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge str attr iterator.
Definition: network.cpp:418
int GetEdges() const
Returns the number of edges in the network.
Definition: network.cpp:1881
Definition: dt.h:412
int AddStrAttrDatE(const TEdgeI &EdgeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2685
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
Definition: ds.h:1323
void Pack()
Reduces vector capacity (frees memory) to match its size.
Definition: ds.h:1057
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.cpp:2445
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
Fills OutWeights with the outgoing weight from each node.
Definition: network.cpp:1520
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
Definition: network.cpp:1649
bool IsAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if attr exists for node NId and has default value.
Definition: network.cpp:182
TVec< TFltV > VecOfFltVecsN
Definition: network.h:2040
int GetInDeg() const
Definition: network.h:1758
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
Definition: network.cpp:2763
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2780
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2062
int GetId() const
Definition: network.h:1756
TVec< THash< TInt, TIntV > > VecOfIntHashVecsN
Definition: network.h:2042
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
TVec< TInt > TIntV
Definition: ds.h:1594
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2290
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2146
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
Gets Vector for the Flt Attribute attr.
Definition: network.cpp:1145
int GetSAttrId(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Given the attribute name Name, get the attribute id.
Definition: attr.cpp:224
Definition: bd.h:196
THash< TStr, TInt > IntDefaultsN
Definition: network.h:2035
#define AssertR(Cond, Reason)
Definition: bd.h:258
TIntV OutNIdV
Definition: network.h:3722
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2298
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int attr iterator.
Definition: network.cpp:214
bool IsIntVAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if IntV attr exists for node NId and is an empty vector.
Definition: network.cpp:194
THash< TInt, TNode > NodeH
Definition: network.h:2028
int AppendIntVAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
Definition: network.h:2698
static PDirNet New()
Static constructor that returns a pointer to the network. Call: PDirNet Graph = TDirNet::New().
Definition: network.h:3855
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.cpp:2300
TIntV InEIdV
Definition: network.h:1749
TFlt GetFltAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a float node attr specified by node iterator NodeI and the attr index...
Definition: network.h:2730
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: network.h:2300
TVec< TVec< TIntV > > VecOfIntVecVecsN
Definition: network.h:2041
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
Definition: network.cpp:1342
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
Definition: network.cpp:2500
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2304
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
Definition: network.h:2017
int GetInEId(const int &EdgeN) const
Definition: network.h:1760
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
Definition: network.cpp:2772
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2446
int GetIdVSAttrE(const TStr &AttrName, TIntV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
Definition: network.cpp:1775
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:2013
void Load(TSIn &SIn)
Load attribute from input stream.
Definition: attr.h:25
int GetInNId(const int &NodeN) const
Definition: network.h:3733
char * CStr()
Definition: dt.h:476
THashIter NodeHI
Definition: network.h:1795
bool IsKey(const TKey &Key) const
Definition: hash.h:258
int AddAttributes(const int NId)
Definition: network.cpp:468
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:2118
Definition: dt.h:971
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:2176
int DelSAttrDatE(const TInt &EId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with id EId.
Definition: network.cpp:1753
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
Definition: network.cpp:2265
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
Definition: network.cpp:2631
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2747
bool IsStrAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
Definition: network.cpp:1538
int AddEdgeUnchecked(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the network.
Definition: network.cpp:1902
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
Definition: network.h:2768
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:1627
int GetOutDeg() const
Definition: network.h:3732
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
static PDirNet GetSmallGraph()
Returns a small network on 5 nodes and 6 edges.
Definition: network.cpp:2517
THashIter NodeHI
Definition: network.h:3754
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2654
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr (same as GetAttrIndE for compatibility...
Definition: network.cpp:1221
TStr GetStrAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a string node attr specified by node iterator NodeI and the attr index...
Definition: network.h:2725
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2609
int AddEdgeUnchecked(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the network.
Definition: network.cpp:2400
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3181
THash< TStr, TBool > KeyToDenseN
KeyToDense[N|E]: Key->(True if Vec, False if Hash)
Definition: network.h:2033
void Pack()
Definition: hash.h:289
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.cpp:1802
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
Definition: network.cpp:765
int AddSAttr(const TStr &Name, const TAttrType &AttrType, TInt &AttrIdX)
Adds a mapping for an attribute with name Name and type AttrType.
Definition: attr.cpp:210
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Definition: network.cpp:1399
static const double Mn
Definition: dt.h:1387
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:1657
TFlt GetFltAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a float edge attr specified by edge iterator EdgeI and the attr index...
Definition: network.h:2758
TInt GetIntAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of an int edge attr specified by edge iterator EdgeI and the attr index.
Definition: network.h:2753
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2134
TIter GetI(const TKey &Key) const
Definition: hash.h:220
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
Definition: network.cpp:1322