SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
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 // Attribute Node Edge Network
3 bool TNEANet::HasFlag(const TGraphFlag& Flag) const {
4  return HasGraphFlag(TNEANet::TNet, Flag);
5 }
6 
7 bool TNEANet::TNodeI::IsInNId(const int& NId) const {
8  const TNode& Node = NodeHI.GetDat();
9  for (int edge = 0; edge < Node.GetInDeg(); edge++) {
10  if (NId == Graph->GetEdge(Node.GetInEId(edge)).GetSrcNId())
11  return true;
12  }
13  return false;
14 }
15 
16 bool TNEANet::TNodeI::IsOutNId(const int& NId) const {
17  const TNode& Node = NodeHI.GetDat();
18  for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
19  if (NId == Graph->GetEdge(Node.GetOutEId(edge)).GetDstNId())
20  return true;
21  }
22  return false;
23 }
24 
25 void TNEANet::AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
26  Names = TVec<TStr>();
27  while (!NodeHI.IsEnd()) {
28  if (!NodeAttrIsDeleted(NId, NodeHI)) {
29  Names.Add(NodeHI.GetKey());
30  }
31  NodeHI++;
32  }
33 }
34 
35 void TNEANet::AttrValueNI(const TInt& NId , TStrIntPrH::TIter NodeHI, TStrV& Values) const {
36  Values = TVec<TStr>();
37  while (!NodeHI.IsEnd()) {
38  if (!NodeAttrIsDeleted(NId, NodeHI)) {
39  Values.Add(GetNodeAttrValue(NId, NodeHI));
40  }
41  NodeHI++;
42  }
43 }
44 
45 void TNEANet::IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
46  Names = TVec<TStr>();
47  while (!NodeHI.IsEnd()) {
48  if (NodeHI.GetDat().Val1 == IntType && !NodeAttrIsIntDeleted(NId, NodeHI)) {
49  Names.Add(NodeHI.GetKey());
50  }
51  NodeHI++;
52  }
53 }
54 
55 void TNEANet::IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const {
56  Values = TVec<TInt>();
57  while (!NodeHI.IsEnd()) {
58  if (NodeHI.GetDat().Val1 == IntType && !NodeAttrIsIntDeleted(NId, NodeHI)) {
59  TInt val = this->VecOfIntVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NodeH.GetKeyId(NId));
60  Values.Add(val);
61  }
62  NodeHI++;
63  }
64 }
65 
66 void TNEANet::StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
67  Names = TVec<TStr>();
68  while (!NodeHI.IsEnd()) {
69  if (NodeHI.GetDat().Val1 == StrType && !NodeAttrIsStrDeleted(NId, NodeHI)) {
70  Names.Add(NodeHI.GetKey());
71  }
72  NodeHI++;
73  }
74 }
75 
76 void TNEANet::StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const {
77  Values = TVec<TStr>();
78  while (!NodeHI.IsEnd()) {
79  if (NodeHI.GetDat().Val1 == StrType && !NodeAttrIsStrDeleted(NId, NodeHI)) {
80  TStr val = this->VecOfStrVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NodeH.GetKeyId(NId));
81  Values.Add(val);
82  }
83  NodeHI++;
84  }
85 }
86 
87 void TNEANet::FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
88  Names = TVec<TStr>();
89  while (!NodeHI.IsEnd()) {
90  if (NodeHI.GetDat().Val1 == FltType && !NodeAttrIsFltDeleted(NId, NodeHI)) {
91  Names.Add(NodeHI.GetKey());
92  }
93  NodeHI++;
94  }
95 }
96 
97 void TNEANet::FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const {
98  Values = TVec<TFlt>();
99  while (!NodeHI.IsEnd()) {
100  if (NodeHI.GetDat().Val1 == FltType && !NodeAttrIsFltDeleted(NId, NodeHI)) {
101  TFlt val = (this->VecOfFltVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NodeH.GetKeyId(NId)));
102  Values.Add(val);
103  }
104  NodeHI++;
105  }
106 }
107 
108 bool TNEANet::NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
109  bool IntDel = NodeAttrIsIntDeleted(NId, NodeHI);
110  bool StrDel = NodeAttrIsStrDeleted(NId, NodeHI);
111  bool FltDel = NodeAttrIsFltDeleted(NId, NodeHI);
112  return IntDel || StrDel || FltDel;
113 }
114 
115 bool TNEANet::NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
116  return (NodeHI.GetDat().Val1 == IntType &&
117  GetIntAttrDefaultN(NodeHI.GetKey()) == this->VecOfIntVecsN.GetVal(
118  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
119 }
120 
121 bool TNEANet::NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
122  return (NodeHI.GetDat().Val1 == StrType &&
123  GetStrAttrDefaultN(NodeHI.GetKey()) == this->VecOfStrVecsN.GetVal(
124  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
125 }
126 
127 bool TNEANet::NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
128  return (NodeHI.GetDat().Val1 == FltType &&
129  GetFltAttrDefaultN(NodeHI.GetKey()) == this->VecOfFltVecsN.GetVal(
130  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId)));
131 }
132 
133 TStr TNEANet::GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
134  if (NodeHI.GetDat().Val1 == IntType) {
135  return (this->VecOfIntVecsN.GetVal(
136  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId))).GetStr();
137  } else if(NodeHI.GetDat().Val1 == StrType) {
138  return this->VecOfStrVecsN.GetVal(
139  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId));
140  } else if (NodeHI.GetDat().Val1 == FltType) {
141  return (this->VecOfFltVecsN.GetVal(
142  this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NodeH.GetKeyId(NId))).GetStr();
143  }
144  return TStr::GetNullStr();
145 }
146 
147 void TNEANet::AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
148  Names = TVec<TStr>();
149  while (!EdgeHI.IsEnd()) {
150  if (!EdgeAttrIsDeleted(EId, EdgeHI)) {
151  Names.Add(EdgeHI.GetKey());
152  }
153  EdgeHI++;
154  }
155 }
156 
157 void TNEANet::AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const {
158  Values = TVec<TStr>();
159  while (!EdgeHI.IsEnd()) {
160  if (!EdgeAttrIsDeleted(EId, EdgeHI)) {
161  Values.Add(GetNodeAttrValue(EId, EdgeHI));
162  }
163  EdgeHI++;
164  }
165 }
166 
167 void TNEANet::IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
168  Names = TVec<TStr>();
169  while (!EdgeHI.IsEnd()) {
170  if (EdgeHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, EdgeHI)) {
171  Names.Add(EdgeHI.GetKey());
172  }
173  EdgeHI++;
174  }
175 }
176 
177 void TNEANet::IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const {
178  Values = TVec<TInt>();
179  while (!EdgeHI.IsEnd()) {
180  if (EdgeHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, EdgeHI)) {
181  TInt val = (this->VecOfIntVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId));
182  Values.Add(val);
183  }
184  EdgeHI++;
185  }
186 }
187 
188 void TNEANet::StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
189  Names = TVec<TStr>();
190  while (!EdgeHI.IsEnd()) {
191  if (EdgeHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, EdgeHI)) {
192  Names.Add(EdgeHI.GetKey());
193  }
194  EdgeHI++;
195  }
196 }
197 
198 void TNEANet::StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const {
199  Values = TVec<TStr>();
200  while (!EdgeHI.IsEnd()) {
201  if (EdgeHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, EdgeHI)) {
202  TStr val = this->VecOfStrVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId);
203  Values.Add(val);
204  }
205  EdgeHI++;
206  }
207 }
208 
209 void TNEANet::FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
210  Names = TVec<TStr>();
211  while (!EdgeHI.IsEnd()) {
212  if (EdgeHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, EdgeHI)) {
213  Names.Add(EdgeHI.GetKey());
214  }
215  EdgeHI++;
216  }
217 }
218 
219 void TNEANet::FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const {
220  Values = TVec<TFlt>();
221  while (!EdgeHI.IsEnd()) {
222  if (EdgeHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, EdgeHI)) {
223  TFlt val = (this->VecOfFltVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId));
224  Values.Add(val);
225  }
226  EdgeHI++;
227  }
228 }
229 
230 bool TNEANet::EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
231  bool IntDel = EdgeAttrIsIntDeleted(EId, EdgeHI);
232  bool StrDel = EdgeAttrIsStrDeleted(EId, EdgeHI);
233  bool FltDel = EdgeAttrIsFltDeleted(EId, EdgeHI);
234  return IntDel || StrDel || FltDel;
235 }
236 
237 bool TNEANet::EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
238  return (EdgeHI.GetDat().Val1 == IntType &&
239  GetIntAttrDefaultE(EdgeHI.GetKey()) == this->VecOfIntVecsE.GetVal(
240  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
241 }
242 
243 bool TNEANet::EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
244  return (EdgeHI.GetDat().Val1 == StrType &&
245  GetStrAttrDefaultE(EdgeHI.GetKey()) == this->VecOfStrVecsE.GetVal(
246  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
247 }
248 
249 bool TNEANet::EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
250  return (EdgeHI.GetDat().Val1 == FltType &&
251  GetFltAttrDefaultE(EdgeHI.GetKey()) == this->VecOfFltVecsE.GetVal(
252  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId)));
253 }
254 
255 TStr TNEANet::GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
256  if (EdgeHI.GetDat().Val1 == IntType) {
257  return (this->VecOfIntVecsE.GetVal(
258  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId))).GetStr();
259  } else if(EdgeHI.GetDat().Val1 == StrType) {
260  return this->VecOfStrVecsE.GetVal(
261  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId));
262  } else if (EdgeHI.GetDat().Val1 == FltType) {
263  return (this->VecOfFltVecsE.GetVal(
264  this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EdgeH.GetKeyId(EId))).GetStr();
265  }
266  return TStr::GetNullStr();
267 }
268 
269 int TNEANet::AddNode(int NId) {
270  int i;
271  if (NId == -1) {
272  NId = MxNId; MxNId++;
273  } else {
274  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
275  MxNId = TMath::Mx(NId+1, MxNId());
276  }
277  // update attribute columns
278  NodeH.AddDat(NId, TNode(NId));
279  for (i = 0; i < VecOfIntVecsN.Len(); i++) {
280  TVec<TInt>& IntVec = VecOfIntVecsN[i];
281  IntVec.Ins(NodeH.GetKeyId(NId), TInt::Mn);
282  }
283  TVec<TStr> DefIntVec = TVec<TStr>();
284  IntDefaultsN.GetKeyV(DefIntVec);
285  for (i = 0; i < DefIntVec.Len(); i++) {
286  TStr attr = DefIntVec[i];
287  TVec<TInt>& IntVec = VecOfIntVecsN[KeyToIndexTypeN.GetDat(DefIntVec[i]).Val2];
288  IntVec[NodeH.GetKeyId(NId)] = GetIntAttrDefaultN(attr);
289  }
290  for (i = 0; i < VecOfStrVecsN.Len(); i++) {
291  TVec<TStr>& StrVec = VecOfStrVecsN[i];
292  StrVec.Ins(NodeH.GetKeyId(NId), TStr::GetNullStr());
293  }
294  TVec<TStr> DefStrVec = TVec<TStr>();
295  IntDefaultsN.GetKeyV(DefStrVec);
296  for (i = 0; i < DefStrVec.Len(); i++) {
297  TStr attr = DefStrVec[i];
298  TVec<TStr>& StrVec = VecOfStrVecsN[KeyToIndexTypeN.GetDat(DefStrVec[i]).Val2];
299  StrVec[NodeH.GetKeyId(NId)] = GetStrAttrDefaultN(attr);
300  }
301  for (i = 0; i < VecOfFltVecsN.Len(); i++) {
302  TVec<TFlt>& FltVec = VecOfFltVecsN[i];
303  FltVec.Ins(NodeH.GetKeyId(NId), TFlt::Mn);
304  }
305  TVec<TStr> DefFltVec = TVec<TStr>();
306  FltDefaultsN.GetKeyV(DefFltVec);
307  for (i = 0; i < DefFltVec.Len(); i++) {
308  TStr attr = DefFltVec[i];
309  TVec<TFlt>& FltVec = VecOfFltVecsN[KeyToIndexTypeN.GetDat(DefFltVec[i]).Val2];
310  FltVec[NodeH.GetKeyId(NId)] = GetFltAttrDefaultN(attr);
311  }
312  return NId;
313 }
314 
315 void TNEANet::DelNode(const int& NId) {
316  int i;
317 
318  const TNode& Node = GetNode(NId);
319  for (int out = 0; out < Node.GetOutDeg(); out++) {
320  const int EId = Node.GetOutEId(out);
321  const TEdge& Edge = GetEdge(EId);
322  IAssert(Edge.GetSrcNId() == NId);
323  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
324  // Delete from Edge Attributes
325  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
326  TVec<TInt>& IntVec = VecOfIntVecsE[i];
327  IntVec[EdgeH.GetKeyId(EId)] = TInt::Mn;
328  }
329  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
330  TVec<TStr>& StrVec = VecOfStrVecsE[i];
331  StrVec[EdgeH.GetKeyId(EId)] = TStr::GetNullStr();
332  }
333  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
334  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
335  FltVec[EdgeH.GetKeyId(EId)] = TFlt::Mn;
336  }
337  EdgeH.DelKey(EId);
338  }
339  for (int in = 0; in < Node.GetInDeg(); in++) {
340  const int EId = Node.GetInEId(in);
341  const TEdge& Edge = GetEdge(EId);
342  IAssert(Edge.GetDstNId() == NId);
343  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
344  // Delete from Edge Attributes
345  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
346  TVec<TInt>& IntVec = VecOfIntVecsE[i];
347  IntVec[EdgeH.GetKeyId(EId)] = TInt::Mn;
348  }
349  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
350  TVec<TStr>& StrVec = VecOfStrVecsE[i];
351  StrVec[EdgeH.GetKeyId(EId)] = TStr::GetNullStr();
352  }
353  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
354  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
355  FltVec[EdgeH.GetKeyId(EId)] = TFlt::Mn;
356  }
357  EdgeH.DelKey(EId);
358  }
359 
360  for (i = 0; i < VecOfIntVecsN.Len(); i++) {
361  TVec<TInt>& IntVec = VecOfIntVecsN[i];
362  IntVec[NodeH.GetKeyId(NId)] = TInt::Mn;
363  }
364  for (i = 0; i < VecOfStrVecsN.Len(); i++) {
365  TVec<TStr>& StrVec = VecOfStrVecsN[i];
366  StrVec[NodeH.GetKeyId(NId)] = TStr::GetNullStr();
367  }
368  for (i = 0; i < VecOfFltVecsN.Len(); i++) {
369  TVec<TFlt>& FltVec = VecOfFltVecsN[i];
370  FltVec[NodeH.GetKeyId(NId)] = TFlt::Mn;
371  }
372  NodeH.DelKey(NId);
373 }
374 
375 int TNEANet::AddEdge(const int& SrcNId, const int& DstNId, int EId) {
376  int i;
377 
378  if (EId == -1) { EId = MxEId; MxEId++; }
379  else { MxEId = TMath::Mx(EId+1, MxEId()); }
380  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
381  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
382  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
383  GetNode(SrcNId).OutEIdV.AddSorted(EId);
384  GetNode(DstNId).InEIdV.AddSorted(EId);
385 
386  // update attribute columns
387  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
388  TVec<TInt>& IntVec = VecOfIntVecsE[i];
389  IntVec.Ins(EdgeH.GetKeyId(EId), TInt::Mn);
390  }
391  TVec<TStr> DefIntVec = TVec<TStr>();
392  IntDefaultsE.GetKeyV(DefIntVec);
393  for (i = 0; i < DefIntVec.Len(); i++) {
394  TStr attr = DefIntVec[i];
395  TVec<TInt>& IntVec = VecOfIntVecsE[KeyToIndexTypeE.GetDat(DefIntVec[i]).Val2];
396  IntVec[EdgeH.GetKeyId(EId)] = GetIntAttrDefaultE(attr);
397  }
398 
399  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
400  TVec<TStr>& StrVec = VecOfStrVecsE[i];
401  StrVec.Ins(EdgeH.GetKeyId(EId), TStr::GetNullStr());
402  }
403  TVec<TStr> DefStrVec = TVec<TStr>();
404  IntDefaultsE.GetKeyV(DefStrVec);
405  for (i = 0; i < DefStrVec.Len(); i++) {
406  TStr attr = DefStrVec[i];
407  TVec<TStr>& StrVec = VecOfStrVecsE[KeyToIndexTypeE.GetDat(DefStrVec[i]).Val2];
408  StrVec[EdgeH.GetKeyId(EId)] = GetStrAttrDefaultE(attr);
409  }
410 
411  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
412  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
413  FltVec.Ins(EdgeH.GetKeyId(EId), TFlt::Mn);
414  }
415  TVec<TStr> DefFltVec = TVec<TStr>();
416  FltDefaultsE.GetKeyV(DefFltVec);
417  for (i = 0; i < DefFltVec.Len(); i++) {
418  TStr attr = DefFltVec[i];
419  TVec<TFlt>& FltVec = VecOfFltVecsE[KeyToIndexTypeE.GetDat(DefFltVec[i]).Val2];
420  FltVec[NodeH.GetKeyId(EId)] = GetFltAttrDefaultE(attr);
421  }
422  return EId;
423 }
424 
425 void TNEANet::DelEdge(const int& EId) {
426  int i;
427 
428  IAssert(IsEdge(EId));
429  const int SrcNId = GetEdge(EId).GetSrcNId();
430  const int DstNId = GetEdge(EId).GetDstNId();
431  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
432  GetNode(DstNId).InEIdV.DelIfIn(EId);
433  EdgeH.DelKey(EId);
434 
435  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
436  TVec<TInt>& IntVec = VecOfIntVecsE[i];
437  IntVec.Ins(EdgeH.GetKeyId(EId), TInt::Mn);
438  }
439  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
440  TVec<TStr>& StrVec = VecOfStrVecsE[i];
441  StrVec.Ins(EdgeH.GetKeyId(EId), TStr::GetNullStr());
442  }
443  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
444  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
445  FltVec.Ins(EdgeH.GetKeyId(EId), TFlt::Mn);
446  }
447 }
448 
449 // delete all edges between the two nodes
450 void TNEANet::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
451  int EId = 0;
452  bool Edge = IsEdge(SrcNId, DstNId, EId, IsDir);
453  IAssert(Edge); // there is at least one edge
454  while (Edge) {
455  DelEdge(EId);
456  Edge = IsEdge(SrcNId, DstNId, EId, IsDir);
457  }
458 }
459 
460 bool TNEANet::IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir) const {
461  const TNode& SrcNode = GetNode(SrcNId);
462  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
463  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
464  if (DstNId == Edge.GetDstNId()) {
465  EId = Edge.GetId();
466  return true;
467  }
468  }
469  if (! IsDir) {
470  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
471  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
472  if (DstNId == Edge.GetSrcNId()) {
473  EId = Edge.GetId();
474  return true;
475  }
476  }
477  }
478  return false;
479 }
480 
481 void TNEANet::GetNIdV(TIntV& NIdV) const {
482  NIdV.Gen(GetNodes(), 0);
483  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
484  NIdV.Add(NodeH.GetKey(N));
485  }
486 }
487 
488 void TNEANet::GetEIdV(TIntV& EIdV) const {
489  EIdV.Gen(GetEdges(), 0);
490  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
491  EIdV.Add(EdgeH.GetKey(E));
492  }
493 }
494 
495 void TNEANet::Defrag(const bool& OnlyNodeLinks) {
496  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid); ) {
497  TNode& Node = NodeH[kid];
498  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
499  }
500  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
501  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
502 }
503 
504 bool TNEANet::IsOk(const bool& ThrowExcept) const {
505  bool RetVal = true;
506  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
507  const TNode& Node = NodeH[N];
508  if (! Node.OutEIdV.IsSorted()) {
509  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
510  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
511  }
512  if (! Node.InEIdV.IsSorted()) {
513  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
514  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
515  }
516  // check out-edge ids
517  int prevEId = -1;
518  for (int e = 0; e < Node.GetOutDeg(); e++) {
519  if (! IsEdge(Node.GetOutEId(e))) {
520  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
521  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
522  }
523  if (e > 0 && prevEId == Node.GetOutEId(e)) {
524  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
525  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
526  }
527  prevEId = Node.GetOutEId(e);
528  }
529  // check in-edge ids
530  prevEId = -1;
531  for (int e = 0; e < Node.GetInDeg(); e++) {
532  if (! IsEdge(Node.GetInEId(e))) {
533  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
534  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
535  }
536  if (e > 0 && prevEId == Node.GetInEId(e)) {
537  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
538  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
539  }
540  prevEId = Node.GetInEId(e);
541  }
542  }
543  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
544  const TEdge& Edge = EdgeH[E];
545  if (! IsNode(Edge.GetSrcNId())) {
546  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
547  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
548  }
549  if (! IsNode(Edge.GetDstNId())) {
550  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
551  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
552  }
553  }
554  return RetVal;
555 }
556 
557 void TNEANet::Dump(FILE *OutF) const {
558  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
559  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
560  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
561  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
562  fprintf(OutF, " %*d]\n", NodePlaces, NodeI.GetId());
563  // load node attributes
564  TIntV IntAttrN;
565  IntAttrValueNI(NodeI.GetId(), IntAttrN);
566  fprintf(OutF, " nai[%d]", IntAttrN.Len());
567  for (int i = 0; i < IntAttrN.Len(); i++) {
568  fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
569  TStrV StrAttrN;
570  StrAttrValueNI(NodeI.GetId(), StrAttrN);
571  fprintf(OutF, " nas[%d]", StrAttrN.Len());
572  for (int i = 0; i < StrAttrN.Len(); i++) {
573  fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
574  TFltV FltAttrN;
575  FltAttrValueNI(NodeI.GetId(), FltAttrN);
576  fprintf(OutF, " naf[%d]", FltAttrN.Len());
577  for (int i = 0; i < FltAttrN.Len(); i++) {
578  fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }
579 
580  fprintf(OutF, " in[%d]", NodeI.GetInDeg());
581  for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
582  fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
583  fprintf(OutF, "\n");
584  fprintf(OutF, " out[%d]", NodeI.GetOutDeg());
585  for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
586  fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
587  fprintf(OutF, "\n");
588  }
589  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
590  fprintf(OutF, " %*d] %*d -> %*d\n", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
591 
592  // load edge attributes
593  TIntV IntAttrE;
594  IntAttrValueEI(EdgeI.GetId(), IntAttrE);
595  fprintf(OutF, " eai[%d]", IntAttrE.Len());
596  for (int i = 0; i < IntAttrE.Len(); i++) {
597  fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]()); }
598  TStrV StrAttrE;
599  StrAttrValueEI(EdgeI.GetId(), StrAttrE);
600  fprintf(OutF, " eas[%d]", StrAttrE.Len());
601  for (int i = 0; i < StrAttrE.Len(); i++) {
602  fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]()); }
603  TFltV FltAttrE;
604  FltAttrValueEI(EdgeI.GetId(), FltAttrE);
605  fprintf(OutF, " eaf[%d]", FltAttrE.Len());
606  for (int i = 0; i < FltAttrE.Len(); i++) {
607  fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]()); }
608  }
609  fprintf(OutF, "\n");
610 }
611 
612 // Attribute related function
613 
614 int TNEANet::AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr) {
615  int i;
616  TInt CurrLen;
617  if (!IsNode(NId)) {
618  // AddNode(NId);
619  return -1;
620  }
621  if (KeyToIndexTypeN.IsKey(attr)) {
623  NewVec[NodeH.GetKeyId(NId)] = value;
624  } else {
625  CurrLen = VecOfIntVecsN.Len();
626  KeyToIndexTypeN.AddDat(attr, TIntPr(IntType, CurrLen));
627  TVec<TInt> NewVec = TVec<TInt>();
628  for (i = 0; i < MxNId; i++) {
629  NewVec.Ins(i, GetIntAttrDefaultN(attr));
630  }
631  NewVec[NodeH.GetKeyId(NId)] = value;
632  VecOfIntVecsN.Add(NewVec);
633  }
634  return 0;
635 }
636 
637 int TNEANet::AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr) {
638  int i;
639  TInt CurrLen;
640  if (!IsNode(NId)) {
641  // AddNode(NId);
642  return -1;
643  }
644  if (KeyToIndexTypeN.IsKey(attr)) {
646  NewVec[NodeH.GetKeyId(NId)] = value;
647  } else {
648  CurrLen = VecOfStrVecsN.Len();
649  KeyToIndexTypeN.AddDat(attr, TIntPr(StrType, CurrLen));
650  TVec<TStr> NewVec = TVec<TStr>();
651  for (i = 0; i < MxNId; i++) {
652  NewVec.Ins(i, GetStrAttrDefaultN(attr));
653  }
654  NewVec[NodeH.GetKeyId(NId)] = value;
655  VecOfStrVecsN.Add(NewVec);
656  }
657  return 0;
658 }
659 
660 int TNEANet::AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr) {
661  int i;
662  TInt CurrLen;
663 
664  if (!IsNode(NId)) {
665  // AddNode(NId);
666  return -1;
667  }
668  if (KeyToIndexTypeN.IsKey(attr)) {
670  NewVec[NodeH.GetKeyId(NId)] = value;
671  } else {
672  CurrLen = VecOfFltVecsN.Len();
673  KeyToIndexTypeN.AddDat(attr, TIntPr(FltType, CurrLen));
674  TVec<TFlt> NewVec = TVec<TFlt>();
675  for (i = 0; i < MxNId; i++) {
676  NewVec.Ins(i, GetFltAttrDefaultN(attr));
677  }
678  NewVec[NodeH.GetKeyId(NId)] = value;
679  VecOfFltVecsN.Add(NewVec);
680  }
681  return 0;
682 }
683 
684 int TNEANet::AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr) {
685  int i;
686  TInt CurrLen;
687  if (!IsEdge(EId)) {
688  //AddEdge(EId);
689  return -1;
690  }
691  if (KeyToIndexTypeE.IsKey(attr)) {
693  NewVec[EdgeH.GetKeyId(EId)] = value;
694  } else {
695  CurrLen = VecOfIntVecsE.Len();
696  KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
697  TVec<TInt> NewVec = TVec<TInt>();
698  for (i = 0; i < MxEId; i++) {
699  NewVec.Ins(i, GetIntAttrDefaultE(attr));
700  }
701  NewVec[EdgeH.GetKeyId(EId)] = value;
702  VecOfIntVecsE.Add(NewVec);
703  }
704  return 0;
705 }
706 
707 int TNEANet::AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr) {
708  int i;
709  TInt CurrLen;
710  if (!IsEdge(EId)) {
711  //AddEdge(EId);
712  return -1;
713  }
714  if (KeyToIndexTypeE.IsKey(attr)) {
716  NewVec[EdgeH.GetKeyId(EId)] = value;
717  } else {
718  CurrLen = VecOfStrVecsE.Len();
719  KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
720  TVec<TStr> NewVec = TVec<TStr>();
721  for (i = 0; i < MxEId; i++) {
722  NewVec.Ins(i, GetStrAttrDefaultE(attr));
723  }
724  NewVec[EdgeH.GetKeyId(EId)] = value;
725  VecOfStrVecsE.Add(NewVec);
726  }
727  return 0;
728 }
729 
730 int TNEANet::AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr) {
731  int i;
732  TInt CurrLen;
733 
734  if (!IsEdge(EId)) {
735  //AddEdge(EId);
736  return -1;
737  }
738  if (KeyToIndexTypeE.IsKey(attr)) {
740  NewVec[EdgeH.GetKeyId(EId)] = value;
741  } else {
742  CurrLen = VecOfFltVecsE.Len();
743  KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
744  TVec<TFlt> NewVec = TVec<TFlt>();
745  for (i = 0; i < MxEId; i++) {
746  NewVec.Ins(i, GetFltAttrDefaultE(attr));
747  }
748  NewVec[EdgeH.GetKeyId(EId)] = value;
749  VecOfFltVecsE.Add(NewVec);
750  }
751  return 0;
752 }
753 
754 TInt TNEANet::GetIntAttrDatN(const int& NId, const TStr& attr) {
756 }
757 
758 TInt TNEANet::GetIntAttrIndDatN(const int& NId, const int& index) {
759  return VecOfIntVecsN[index][NodeH.GetKeyId(NId)];
760 }
761 
762 int TNEANet::GetIntAttrIndN(const TStr& attr) {
763  return KeyToIndexTypeN.GetDat(attr).Val2.Val;
764 }
765 
766 TStr TNEANet::GetStrAttrDatN(const int& NId, const TStr& attr) {
768 }
769 
770 TFlt TNEANet::GetFltAttrDatN(const int& NId, const TStr& attr) {
772 }
773 
774 TInt TNEANet::GetIntAttrDatE(const int& EId, const TStr& attr) {
776 }
777 
778 TInt TNEANet::GetIntAttrIndDatE(const int& EId, const int& index) {
779  return VecOfIntVecsE[index][EdgeH.GetKeyId(EId)];
780 }
781 
782 int TNEANet::GetIntAttrIndE(const TStr& attr) {
783  return KeyToIndexTypeE.GetDat(attr).Val2.Val;
784 }
785 
786 TStr TNEANet::GetStrAttrDatE(const int& EId, const TStr& attr) {
788 }
789 
790 TFlt TNEANet::GetFltAttrDatE(const int& EId, const TStr& attr) {
792 }
793 
794 int TNEANet::DelAttrDatN(const int& NId, const TStr& attr) {
795  TInt vecType = KeyToIndexTypeN(attr).Val1;
796  if (vecType == IntType) {
798  } else if (vecType == StrType) {
800  } else if (vecType == FltType) {
802  } else {
803  return -1;
804  }
805  return 0;
806 }
807 
808 int TNEANet::DelAttrDatE(const int& EId, const TStr& attr) {
809  // TODO(nkhadke): add error checking
810  TInt vecType = KeyToIndexTypeE(attr).Val1;
811  if (vecType == IntType) {
813  } else if (vecType == StrType) {
815  } else if (vecType == FltType) {
817  } else {
818  return -1;
819  }
820  return 0;
821 }
822 
823 int TNEANet::AddIntAttrN(const TStr& attr, TInt defaultValue){
824  int i;
825  TInt CurrLen;
826  TVec<TInt> NewVec;
827  CurrLen = VecOfIntVecsN.Len();
828  KeyToIndexTypeN.AddDat(attr, TIntPr(IntType, CurrLen));
829  NewVec = TVec<TInt>();
830  for (i = 0; i < MxNId; i++) {
831  NewVec.Ins(i, defaultValue);
832  }
833  VecOfIntVecsN.Add(NewVec);
834  if (!IntDefaultsN.IsKey(attr)) {
835  IntDefaultsN.AddDat(attr, defaultValue);
836  } else {
837  return -1;
838  }
839  return 0;
840 }
841 
842 int TNEANet::AddStrAttrN(const TStr& attr, TStr defaultValue) {
843  int i;
844  TInt CurrLen;
845  TVec<TStr> NewVec;
846  CurrLen = VecOfStrVecsN.Len();
847  KeyToIndexTypeN.AddDat(attr, TIntPr(StrType, CurrLen));
848  NewVec = TVec<TStr>();
849  for (i = 0; i < MxNId; i++) {
850  NewVec.Ins(i, defaultValue);
851  }
852  VecOfStrVecsN.Add(NewVec);
853  if (!StrDefaultsN.IsKey(attr)) {
854  StrDefaultsN.AddDat(attr, defaultValue);
855  } else {
856  return -1;
857  }
858  return 0;
859 }
860 
861 int TNEANet::AddFltAttrN(const TStr& attr, TFlt defaultValue) {
862  // TODO(nkhadke): add error checking
863  int i;
864  TInt CurrLen;
865  TVec<TFlt> NewVec;
866  CurrLen = VecOfStrVecsN.Len();
867  KeyToIndexTypeN.AddDat(attr, TIntPr(FltType, CurrLen));
868  NewVec = TVec<TFlt>();
869  for (i = 0; i < MxNId; i++) {
870  NewVec.Ins(i, defaultValue);
871  }
872  VecOfFltVecsN.Add(NewVec);
873  if (!FltDefaultsN.IsKey(attr)) {
874  FltDefaultsN.AddDat(attr, defaultValue);
875  } else {
876  return -1;
877  }
878  return 0;
879 }
880 
881 int TNEANet::AddIntAttrE(const TStr& attr, TInt defaultValue){
882  // TODO(nkhadke): add error checking
883  int i;
884  TInt CurrLen;
885  TVec<TInt> NewVec;
886  CurrLen = VecOfIntVecsE.Len();
887  KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
888  NewVec = TVec<TInt>();
889  for (i = 0; i < MxEId; i++) {
890  NewVec.Ins(i, defaultValue);
891  }
892  VecOfIntVecsE.Add(NewVec);
893  if (!IntDefaultsE.IsKey(attr)) {
894  IntDefaultsE.AddDat(attr, defaultValue);
895  } else {
896  return -1;
897  }
898  return 0;
899 }
900 
901 int TNEANet::AddStrAttrE(const TStr& attr, TStr defaultValue) {
902  int i;
903  TInt CurrLen;
904  TVec<TStr> NewVec;
905  CurrLen = VecOfStrVecsE.Len();
906  KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
907  NewVec = TVec<TStr>();
908  for (i = 0; i < MxEId; i++) {
909  NewVec.Ins(i, defaultValue);
910  }
911  VecOfStrVecsE.Add(NewVec);
912  if (!StrDefaultsE.IsKey(attr)) {
913  StrDefaultsE.AddDat(attr, defaultValue);
914  } else {
915  return -1;
916  }
917  return 0;
918 }
919 
920 int TNEANet::AddFltAttrE(const TStr& attr, TFlt defaultValue) {
921  int i;
922  TInt CurrLen;
923  TVec<TFlt> NewVec;
924  CurrLen = VecOfStrVecsE.Len();
925  KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
926  NewVec = TVec<TFlt>();
927  for (i = 0; i < MxEId; i++) {
928  NewVec.Ins(i, defaultValue);
929  }
930  VecOfFltVecsE.Add(NewVec);
931  if (!FltDefaultsE.IsKey(attr)) {
932  FltDefaultsE.AddDat(attr, defaultValue);
933  } else {
934  return -1;
935  }
936  return 0;
937 }
938 
939 int TNEANet::DelAttrN(const TStr& attr) {
940  TInt vecType = KeyToIndexTypeN(attr).Val1;
941  if (vecType == IntType) {
943  if (IntDefaultsN.IsKey(attr)) {
944  IntDefaultsN.DelKey(attr);
945  }
946  } else if (vecType == StrType) {
948  if (StrDefaultsN.IsKey(attr)) {
949  StrDefaultsN.DelKey(attr);
950  }
951  } else if (vecType == FltType) {
953  if (FltDefaultsN.IsKey(attr)) {
954  FltDefaultsN.DelKey(attr);
955  }
956  } else {
957  return -1;
958  }
959  KeyToIndexTypeN.DelKey(attr);
960  return 0;
961 }
962 
963 int TNEANet::DelAttrE(const TStr& attr) {
964  TInt vecType = KeyToIndexTypeE(attr).Val1;
965  if (vecType == IntType) {
967  if (IntDefaultsE.IsKey(attr)) {
968  IntDefaultsE.DelKey(attr);
969  }
970  } else if (vecType == StrType) {
972  if (StrDefaultsE.IsKey(attr)) {
973  StrDefaultsE.DelKey(attr);
974  }
975  } else if (vecType == FltType) {
977  if (FltDefaultsE.IsKey(attr)) {
978  FltDefaultsE.DelKey(attr);
979  }
980  } else {
981  return -1;
982  }
983  KeyToIndexTypeE.DelKey(attr);
984  return 0;
985 }
986 
987 // Return a small graph on 5 nodes and 6 edges.
989  PNEANet Net = TNEANet::New();
990  for (int i = 0; i < 5; i++) { Net->AddNode(i); }
991  Net->AddEdge(0,1); Net->AddEdge(0,2);
992  Net->AddEdge(0,3); Net->AddEdge(0,4);
993  Net->AddEdge(1,2); Net->AddEdge(1,2);
994  return Net;
995 }
996 
#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:481
TVec< TIntV > VecOfIntVecsN
Definition: network.h:1837
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
int AddIntAttrDatE(const TEdgeI &EdgeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2142
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1115
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.cpp:7
int GetId() const
Definition: network.h:1622
int GetNodes() const
Returns the number of nodes in the graph.
Definition: network.h:1890
bool IsKeyIdEqKeyN() const
Definition: hash.h:191
#define IAssertR(Cond, Reason)
Definition: bd.h:265
int GetSrcNId() const
Definition: network.h:1623
int AddStrAttrDatN(const TNodeI &NodeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2131
THash< TStr, TFlt > FltDefaultsE
Definition: network.h:1836
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: network.cpp:255
int DelAttrDatN(const TNodeI &NodeId, const TStr &attr)
Deletes the node attribute for NodeId.
Definition: network.h:2189
TVec< TStrV > VecOfStrVecsE
Definition: network.h:1838
TStr GetStrAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: network.h:2176
THash< TStr, TInt > IntDefaultsE
Definition: network.h:1834
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by str attr.
Definition: network.cpp:762
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: network.cpp:121
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
Definition: network.cpp:939
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: network.cpp:108
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: network.h:1976
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TInt GetIntAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2156
int AddFltAttrDatN(const TNodeI &NodeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2136
TNode & GetNode(const int &NId)
Definition: network.h:1808
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:1959
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:1967
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: network.cpp:249
TInt GetIntAttrDefaultE(const TStr &attribute) const
Get Int edge attribute val. If not a proper attr, return default.
Definition: network.h:1820
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: network.cpp:230
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
const TNEANet * Graph
Definition: network.h:1632
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: network.cpp:237
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
Definition: network.cpp:963
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:1963
TStrIntPrH KeyToIndexTypeE
Definition: network.h:1832
TInt GetIntAttrIndDatN(const TNodeI &NodeId, const int &index)
Gets the value of node int attr specified by the attr index.
Definition: network.h:2169
void DelEdge(const int &EId)
Deletes an edge with edge ID EId from the graph.
Definition: network.cpp:425
THash< TStr, TFlt > FltDefaultsN
Definition: network.h:1836
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: network.h:2068
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:1988
TInt MxNId
Definition: network.h:1828
TIntV OutEIdV
Definition: network.h:1595
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1628
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:1947
TVec< TIntV > VecOfIntVecsE
Definition: network.h:1837
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:1951
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: network.cpp:269
TInt GetIntAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: network.h:2173
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
Definition: network.cpp:315
int AddStrAttrDatE(const TEdgeI &EdgeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2147
const TKey & GetKey() const
Definition: hash.h:71
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1027
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
void Defrag()
Definition: hash.h:509
Definition: dt.h:1289
TVec< TStrV > VecOfStrVecsN
Definition: network.h:1838
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
Definition: network.cpp:488
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
Definition: network.cpp:557
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: network.cpp:127
THash< TInt, TEdge > EdgeH
Definition: network.h:1830
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.cpp:16
void DelKey(const TKey &Key)
Definition: hash.h:358
static const int Mn
Definition: dt.h:1045
int AddIntAttrDatN(const TNodeI &NodeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2126
TVec< TFltV > VecOfFltVecsE
Definition: network.h:1839
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:1832
const TDat & GetDat() const
Definition: hash.h:72
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:1996
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:38
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
Definition: hash.h:69
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2004
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
Definition: network.cpp:3
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
Definition: network.cpp:823
TStr GetStrAttrDefaultE(const TStr &attribute) const
Get Str edge attribute val. If not a proper attr, return default.
Definition: network.h:1822
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:375
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
THash< TStr, TStr > StrDefaultsN
Definition: network.h:1835
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
Definition: network.h:1943
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
Definition: network.cpp:901
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
Definition: network.h:2076
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
Definition: network.cpp:504
int FFirstKeyId() const
Definition: hash.h:232
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
Definition: network.h:2078
int GetDstNId() const
Definition: network.h:1624
TStr GetStrAttrDefaultN(const TStr &attribute) const
Get Str node attribute val. If not a proper attr, return default.
Definition: network.h:1816
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: network.cpp:133
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:1980
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:1971
Directed multigraph with node edge attributes.
Definition: network.h:1587
TInt MxEId
Definition: network.h:1828
int AddFltAttrDatE(const TEdgeI &EdgeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2152
TInt GetIntAttrIndDatE(const TEdgeI &EdgeId, const int &index)
Gets the value of edge int attr specified by the attr index.
Definition: network.h:2185
TStr GetStr() const
Definition: dt.h:679
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
Definition: network.cpp:988
Definition: dt.h:1041
TEdge & GetEdge(const int &EId)
Definition: network.h:1810
int GetOutDeg() const
Definition: network.h:1605
int GetKeyId(const TKey &Key) const
Definition: hash.h:420
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:1955
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: network.h:1910
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
Definition: network.cpp:842
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
Definition: ds.h:1086
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1699
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2000
THash< TStr, TStr > StrDefaultsE
Definition: network.h:1835
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:1992
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Get Flt edge attribute val. If not a proper attr, return default.
Definition: network.h:1824
int GetEdges() const
Returns the number of edges in the graph.
Definition: network.h:2049
void GetKeyV(TVec< TKey > &KeyV) const
Definition: hash.h:438
int GetOutEId(const int &EdgeN) const
Definition: network.h:1607
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: network.cpp:243
Definition: dt.h:412
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:1223
void Pack()
The vector reduces its capacity (frees memory) to match its size.
Definition: ds.h:987
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
int DelAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Deletes the edge attribute for NodeId.
Definition: network.h:2192
TVec< TFltV > VecOfFltVecsN
Definition: network.h:1839
int GetInDeg() const
Definition: network.h:1604
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
int GetId() const
Definition: network.h:1602
TVal2 Val2
Definition: ds.h:35
Definition: bd.h:196
THash< TStr, TInt > IntDefaultsN
Definition: network.h:1834
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1906
TFlt GetFltAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2163
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: network.cpp:115
THash< TInt, TNode > NodeH
Definition: network.h:1829
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TIntV InEIdV
Definition: network.h:1595
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: network.h:1908
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
Definition: network.cpp:881
TFlt GetFltAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: network.h:2179
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Get Flt node attribute val. If not a proper attr, return default.
Definition: network.h:1818
int GetInEId(const int &EdgeN) const
Definition: network.h:1606
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:1984
TInt GetIntAttrDefaultN(const TStr &attribute) const
Get Int node attribute val. If not a proper attr, return default.
Definition: network.h:1814
char * CStr()
Definition: dt.h:476
THashIter NodeHI
Definition: network.h:1631
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:1876
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by str attr.
Definition: network.cpp:782
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
Definition: network.cpp:495
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Definition: network.cpp:920
static const double Mn
Definition: dt.h:1293
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
Definition: network.cpp:861
TStr GetStrAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2160