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.h
Go to the documentation of this file.
1 #ifndef NETWORK_H
2 #define NETWORK_H
3 
5 // Node Data
6 // TNodeData has to implement the following methods:
7 // class TNodeData {
8 // public:
9 // TNodeData() { }
10 // TNodeData(TSIn& SIn) { }
11 // void Save(TSOut& SOut) const { }
12 // };
13 
14 //#//////////////////////////////////////////////
16 template <class TNodeData>
17 class TNodeNet {
18 public:
19  typedef TNodeData TNodeDat;
21  typedef TPt<TNet> PNet;
22 public:
23  class TNode {
24  private:
26  TNodeData NodeDat;
28  public:
29  TNode() : Id(-1), NodeDat(), InNIdV(), OutNIdV() { }
30  TNode(const int& NId) : Id(NId), NodeDat(), InNIdV(), OutNIdV() { }
31  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), NodeDat(NodeData), InNIdV(), OutNIdV() { }
32  TNode(const TNode& Node) : Id(Node.Id), NodeDat(Node.NodeDat), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
33  TNode(TSIn& SIn) : Id(SIn), NodeDat(SIn), InNIdV(SIn), OutNIdV(SIn) { }
34  void Save(TSOut& SOut) const { Id.Save(SOut); NodeDat.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
35  int GetId() const { return Id; }
36  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
37  int GetInDeg() const { return InNIdV.Len(); }
38  int GetOutDeg() const { return OutNIdV.Len(); }
39  const TNodeData& GetDat() const { return NodeDat; }
40  TNodeData& GetDat() { return NodeDat; }
41  int GetInNId(const int& NodeN) const { return InNIdV[NodeN]; }
42  int GetOutNId(const int& NodeN) const { return OutNIdV[NodeN]; }
43  int GetNbrNId(const int& NodeN) const { return NodeN<GetOutDeg() ? GetOutNId(NodeN):GetInNId(NodeN-GetOutDeg()); }
44  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId) != -1; }
45  bool IsOutNId(const int& NId) const { return OutNIdV.SearchBin(NId) != -1; }
46  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
47  void LoadShM(TShMIn& MStream) {
48  Id = TInt(MStream);
49  NodeDat = TNodeData(MStream);
50  InNIdV.LoadShM(MStream);
51  OutNIdV.LoadShM(MStream);
52  }
53  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
54  friend class TNodeNet<TNodeData>;
55  };
56 
58  class TNodeI {
59  private:
63  public:
64  TNodeI() : NodeHI(), Net(NULL) { }
65  TNodeI(const THashIter& NodeHIter, const TNodeNet* NetPt) : NodeHI(NodeHIter), Net((TNodeNet *) NetPt) { }
66  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
67  TNodeI& operator = (const TNodeI& NodeI) { NodeHI=NodeI.NodeHI; Net=NodeI.Net; return *this; }
69  TNodeI& operator++ (int) { NodeHI++; return *this; }
70  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
71  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
72 
74  int GetId() const { return NodeHI.GetDat().GetId(); }
76  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
78  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
80  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
82 
84  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
86 
88  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
90 
92  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
94  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
96  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
98  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
99  const TNodeData& operator () () const { return NodeHI.GetDat().NodeDat; }
100  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
101  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
102  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
103  const TNodeData& GetInNDat(const int& NodeN) const { return Net->GetNDat(GetInNId(NodeN)); }
104  TNodeData& GetInNDat(const int& NodeN) { return Net->GetNDat(GetInNId(NodeN)); }
105  const TNodeData& GetOutNDat(const int& NodeN) const { return Net->GetNDat(GetOutNId(NodeN)); }
106  TNodeData& GetOutNDat(const int& NodeN) { return Net->GetNDat(GetOutNId(NodeN)); }
107  const TNodeData& GetNbrNDat(const int& NodeN) const { return Net->GetNDat(GetNbrNId(NodeN)); }
108  TNodeData& GetNbrNDat(const int& NodeN) { return Net->GetNDat(GetNbrNId(NodeN)); }
109  friend class TNodeNet<TNodeData>;
110  };
111 
113  class TEdgeI {
114  private:
116  int CurEdge;
117  public:
118  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
119  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
120  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
121  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
124  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
125  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
126  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
128  int GetId() const { return -1; }
130  int GetSrcNId() const { return CurNode.GetId(); }
132  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
133  const TNodeData& GetSrcNDat() const { return CurNode.GetDat(); }
134  TNodeData& GetDstNDat() { return CurNode.GetOutNDat(CurEdge); }
135  friend class TNodeNet<TNodeData>;
136  };
137 
138 protected:
139  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
140 
141 protected:
145 
146 private:
147  class TNodeFunctor {
148  public:
150  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
151  };
152 private:
153  void LoadNetworkShM(TShMIn& ShMIn) {
154  MxNId = TInt(ShMIn);
155  TNodeFunctor f;
156  NodeH.LoadShM(ShMIn, f);
157  }
158 
159 public:
160  TNodeNet() : CRef(), MxNId(0), NodeH() { }
162  explicit TNodeNet(const int& Nodes, const int& Edges) : MxNId(0) { Reserve(Nodes, Edges); }
163  TNodeNet(const TNodeNet& NodeNet) : MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
165  TNodeNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn) { }
166  virtual ~TNodeNet() { }
168  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
170  static PNet New() { return PNet(new TNodeNet()); }
172  static PNet Load(TSIn& SIn) { return PNet(new TNodeNet(SIn)); }
174 
178  static PNet LoadShM(TShMIn& ShMIn) {
179  TNodeNet* Network = new TNodeNet();
180  Network->LoadNetworkShM(ShMIn);
181  return PNet(Network);
182  }
184  bool HasFlag(const TGraphFlag& Flag) const;
185  TNodeNet& operator = (const TNodeNet& NodeNet) {
186  if (this!=&NodeNet) { NodeH=NodeNet.NodeH; MxNId=NodeNet.MxNId; } return *this; }
187  // nodes
189  int GetNodes() const { return NodeH.Len(); }
191 
195  int AddNode(int NId = -1);
197 
201  int AddNodeUnchecked(int NId = -1);
203 
207  int AddNode(int NId, const TNodeData& NodeDat);
209  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
211 
213  virtual void DelNode(const int& NId);
215  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
217  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
219  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
221  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
223  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
225  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
227  void SetNDat(const int& NId, const TNodeData& NodeDat);
229  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
231  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
233  int GetMxNId() const { return MxNId; }
234 
235  // edges
237  int GetEdges() const;
239 
245  int AddEdge(const int& SrcNId, const int& DstNId);
247  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
249 
253  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
255  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
257  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }
259  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
261  TEdgeI GetEI(const int& EId) const;
263  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
264 
266  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
268  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
270  void GetNIdV(TIntV& NIdV) const;
271 
273  bool Empty() const { return GetNodes()==0; }
275  void Clr(const bool& DoDel=true, const bool& ResetDat=true) {
276  MxNId = 0; NodeH.Clr(DoDel, -1, ResetDat); }
278  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
280  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
282  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
284 
289  void Defrag(const bool& OnlyNodeLinks=false);
291 
294  bool IsOk(const bool& ThrowExcept=true) const;
295 
296  friend class TPt<TNodeNet<TNodeData> >;
297 };
298 
299 // set flags
300 namespace TSnap {
301 template <class TNodeData> struct IsDirected<TNodeNet<TNodeData> > { enum { Val = 1 }; };
302 template <class TNodeData> struct IsNodeDat<TNodeNet<TNodeData> > { enum { Val = 1 }; };
303 }
304 
305 template <class TNodeData>
306 bool TNodeNet<TNodeData>::HasFlag(const TGraphFlag& Flag) const {
307  return HasGraphFlag(typename TNet, Flag);
308 }
309 
310 template <class TNodeData>
312  if (NId == -1) {
313  NId = MxNId; MxNId++;
314  } else {
315  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
316  MxNId = TMath::Mx(NId+1, MxNId());
317  }
318  NodeH.AddDat(NId, TNode(NId));
319  return NId;
320 }
321 
322 template <class TNodeData>
324  if (NId == -1) {
325  NId = MxNId; MxNId++;
326  } else {
327  if (IsNode(NId)) { return -1;}
328  MxNId = TMath::Mx(NId+1, MxNId());
329  }
330  NodeH.AddDat(NId, TNode(NId));
331  return NId;
332 }
333 
334 template <class TNodeData>
335 int TNodeNet<TNodeData>::AddNode(int NId, const TNodeData& NodeDat) {
336  if (NId == -1) {
337  NId = MxNId; MxNId++;
338  } else {
339  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
340  MxNId = TMath::Mx(NId+1, MxNId());
341  }
342  NodeH.AddDat(NId, TNode(NId, NodeDat));
343  return NId;
344 }
345 
346 template <class TNodeData>
347 void TNodeNet<TNodeData>::DelNode(const int& NId) {
348  { TNode& Node = GetNode(NId);
349  for (int e = 0; e < Node.GetOutDeg(); e++) {
350  const int nbr = Node.GetOutNId(e);
351  if (nbr == NId) { continue; }
352  TNode& N = GetNode(nbr);
353  int n = N.InNIdV.SearchBin(NId);
354  if (n!= -1) { N.InNIdV.Del(n); }
355  }
356  for (int e = 0; e < Node.GetInDeg(); e++) {
357  const int nbr = Node.GetInNId(e);
358  if (nbr == NId) { continue; }
359  TNode& N = GetNode(nbr);
360  int n = N.OutNIdV.SearchBin(NId);
361  if (n!= -1) { N.OutNIdV.Del(n); }
362  } }
363  NodeH.DelKey(NId);
364 }
365 
366 template <class TNodeData>
367 void TNodeNet<TNodeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
368  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
369  NodeH.GetDat(NId).NodeDat = NodeDat;
370 }
371 
372 template <class TNodeData>
374  int edges=0;
375  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
376  edges+=NodeH[N].GetOutDeg(); }
377  return edges;
378 }
379 
380 template <class TNodeData>
381 int TNodeNet<TNodeData>::AddEdge(const int& SrcNId, const int& DstNId) {
382  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
383  if (IsEdge(SrcNId, DstNId)) { return -2; }
384  GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
385  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
386  return -1; // no edge id
387 }
388 
389 template <class TNodeData>
390 void TNodeNet<TNodeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
391  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
392  GetNode(SrcNId).OutNIdV.DelIfIn(DstNId);
393  GetNode(DstNId).InNIdV.DelIfIn(SrcNId);
394  if (! IsDir) {
395  GetNode(DstNId).OutNIdV.DelIfIn(SrcNId);
396  GetNode(SrcNId).InNIdV.DelIfIn(DstNId);
397  }
398 }
399 
400 template <class TNodeData>
401 bool TNodeNet<TNodeData>::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
402  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
403  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
404  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
405 }
406 
407 template <class TNodeData>
409  NIdV.Reserve(GetNodes(), 0);
410  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
411  NIdV.Add(NodeH.GetKey(N)); }
412 }
413 
414 template <class TNodeData>
415 typename TNodeNet<TNodeData>::TEdgeI TNodeNet<TNodeData>::GetEI(const int& SrcNId, const int& DstNId) const {
416  const TNodeI SrcNI = GetNI(SrcNId);
417  const int NodeN = SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
418  if (NodeN == -1) { return EndEI(); }
419  return TEdgeI(SrcNI, EndNI(), NodeN);
420 }
421 
422 template <class TNodeData>
423 void TNodeNet<TNodeData>::Defrag(const bool& OnlyNodeLinks) {
424  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
425  TNode& Node = NodeH[n];
426  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
427  }
428  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
429  NodeH.Defrag(); }
430 }
431 
432 template <class TNodeData>
433 bool TNodeNet<TNodeData>::IsOk(const bool& ThrowExcept) const {
434  bool RetVal = true;
435  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
436  const TNode& Node = NodeH[N];
437  if (! Node.OutNIdV.IsSorted()) {
438  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
439  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
440  }
441  if (! Node.InNIdV.IsSorted()) {
442  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
443  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
444  }
445  // check out-edges
446  int prevNId = -1;
447  for (int e = 0; e < Node.GetOutDeg(); e++) {
448  if (! IsNode(Node.GetOutNId(e))) {
449  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
450  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
451  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
452  }
453  if (e > 0 && prevNId == Node.GetOutNId(e)) {
454  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
455  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
456  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
457  }
458  prevNId = Node.GetOutNId(e);
459  }
460  // check in-edges
461  prevNId = -1;
462  for (int e = 0; e < Node.GetInDeg(); e++) {
463  if (! IsNode(Node.GetInNId(e))) {
464  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
465  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
466  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
467  }
468  if (e > 0 && prevNId == Node.GetInNId(e)) {
469  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
470  Node.GetId(), Node.GetId(), Node.GetInNId(e));
471  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
472  }
473  prevNId = Node.GetInNId(e);
474  }
475  }
476  return RetVal;
477 }
478 
480 // Common network types
487 
488 //#//////////////////////////////////////////////
490 template <class TNodeData, class TEdgeData>
492 public:
493  typedef TNodeData TNodeDat;
494  typedef TEdgeData TEdgeDat;
496  typedef TPt<TNet> PNet;
498 public:
499  class TNode {
500  private:
502  TNodeData NodeDat;
505  public:
506  TNode() : Id(-1), NodeDat(), InNIdV(), OutNIdV() { }
507  TNode(const int& NId) : Id(NId), NodeDat(), InNIdV(), OutNIdV() { }
508  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), NodeDat(NodeData), InNIdV(), OutNIdV() { }
509  TNode(const TNode& Node) : Id(Node.Id), NodeDat(Node.NodeDat), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
510  TNode(TSIn& SIn) : Id(SIn), NodeDat(SIn), InNIdV(SIn), OutNIdV(SIn) { }
511  void Save(TSOut& SOut) const { Id.Save(SOut); NodeDat.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
512  int GetId() const { return Id; }
513  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
514  int GetInDeg() const { return InNIdV.Len(); }
515  int GetOutDeg() const { return OutNIdV.Len(); }
516  const TNodeData& GetDat() const { return NodeDat; }
517  TNodeData& GetDat() { return NodeDat; }
518  int GetInNId(const int& EdgeN) const { return InNIdV[EdgeN]; }
519  int GetOutNId(const int& EdgeN) const { return OutNIdV[EdgeN].Val1; }
520  int GetNbrNId(const int& EdgeN) const { return EdgeN<GetOutDeg() ? GetOutNId(EdgeN):GetInNId(EdgeN-GetOutDeg()); }
521  TEdgeData& GetOutEDat(const int& EdgeN) { return OutNIdV[EdgeN].Val2; }
522  const TEdgeData& GetOutEDat(const int& EdgeN) const { return OutNIdV[EdgeN].Val2; }
523  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId)!=-1; }
524  bool IsOutNId(const int& NId) const { return TNodeEDatNet::GetNIdPos(OutNIdV, NId)!=-1; }
525  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
526  void LoadShM(TShMIn& MStream) {
527  Id = TInt(MStream);
528  NodeDat = TNodeData(MStream);
529  InNIdV.LoadShM(MStream);
530  OutNIdV.LoadShM(MStream);
531  }
532  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
533  friend class TNodeEDatNet<TNodeData, TEdgeData>;
534  };
535 
537  class TNodeI {
538  private:
542  public:
543  TNodeI() : NodeHI(), Net(NULL) { }
544  TNodeI(const THashIter& NodeHIter, const TNodeEDatNet* NetPt) : NodeHI(NodeHIter), Net((TNodeEDatNet *) NetPt) { }
545  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
546  TNodeI& operator = (const TNodeI& NodeI) { NodeHI=NodeI.NodeHI; Net=NodeI.Net; return *this; }
548  TNodeI& operator++ (int) { NodeHI++; return *this; }
549  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
550  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
551 
553  int GetId() const { return NodeHI.GetDat().GetId(); }
555  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
557  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
559  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
561 
563  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
565 
567  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
569 
571  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
573  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
575  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
577  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
578  // node data
579  const TNodeData& operator () () const { return NodeHI.GetDat().NodeDat; }
580  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
581  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
582  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
583  const TNodeData& GetOutNDat(const int& NodeN) const { return Net->GetNDat(GetOutNId(NodeN)); }
584  TNodeData& GetOutNDat(const int& NodeN) { return Net->GetNDat(GetOutNId(NodeN)); }
585  const TNodeData& GetInNDat(const int& NodeN) const { return Net->GetNDat(GetInNId(NodeN)); }
586  TNodeData& GetInNDat(const int& NodeN) { return Net->GetNDat(GetInNId(NodeN)); }
587  const TNodeData& GetNbrNDat(const int& NodeN) const { return Net->GetNDat(GetNbrNId(NodeN)); }
588  TNodeData& GetNbrNDat(const int& NodeN) { return Net->GetNDat(GetNbrNId(NodeN)); }
589  // edge data
590  TEdgeData& GetOutEDat(const int& EdgeN) { return NodeHI.GetDat().GetOutEDat(EdgeN); }
591  const TEdgeData& GetOutEDat(const int& EdgeN) const { return NodeHI.GetDat().GetOutEDat(EdgeN); }
592  TEdgeData& GetInEDat(const int& EdgeN) { return Net->GetEDat(GetInNId(EdgeN), GetId()); }
593  const TEdgeData& GetInEDat(const int& EdgeN) const { return Net->GetEDat(GetInNId(EdgeN), GetId()); }
594  TEdgeData& GetNbrEDat(const int& EdgeN) { return EdgeN<GetOutDeg() ? GetOutEDat(EdgeN) : GetInEDat(EdgeN-GetOutDeg()); }
595  const TEdgeData& GetNbrEDat(const int& EdgeN) const { return EdgeN<GetOutDeg() ? GetOutEDat(EdgeN) : GetInEDat(EdgeN-GetOutDeg()); }
596  friend class TNodeEDatNet<TNodeData, TEdgeData>;
597  };
598 
600  class TEdgeI {
601  private:
603  int CurEdge;
604  public:
605  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
606  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
607  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
608  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
611  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
612  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
613  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
615  int GetId() const { return -1; }
617  int GetSrcNId() const { return CurNode.GetId(); }
619  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
620  TEdgeData& operator () () { return CurNode.GetOutEDat(CurEdge); }
621  const TEdgeData& operator () () const { return CurNode.GetOutEDat(CurEdge); }
622  TEdgeData& GetDat() { return CurNode.GetOutEDat(CurEdge); }
623  const TEdgeData& GetDat() const { return CurNode.GetOutEDat(CurEdge); }
624  TNodeData& GetSrcNDat() { return CurNode(); }
625  const TNodeData& GetSrcNDat() const { return CurNode(); }
626  TNodeData& GetDstNDat() { return CurNode.GetOutNDat(CurEdge); }
627  const TNodeData& GetDstNDat() const { return CurNode.GetOutNDat(CurEdge); }
628  friend class TNodeEDatNet<TNodeData, TEdgeData>;
629  };
630 
631 protected:
632  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
633  static int GetNIdPos(const TVec<TPair<TInt, TEdgeData> >& NIdV, const int& NId);
634 protected:
638 private:
639  class TNodeFunctor {
640  public:
642  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
643  };
644 private:
645  void LoadNetworkShM(TShMIn& ShMIn) {
646  MxNId = TInt(ShMIn);
647  TNodeFunctor f;
648  NodeH.LoadShM(ShMIn, f);
649  }
650 public:
651  TNodeEDatNet() : CRef(), MxNId(0), NodeH() { }
653  explicit TNodeEDatNet(const int& Nodes, const int& Edges) : MxNId(0) { Reserve(Nodes, Edges); }
654  TNodeEDatNet(const TNodeEDatNet& NodeNet) : MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
656  TNodeEDatNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn) { }
657  virtual ~TNodeEDatNet() { }
659  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
661  static PNet New() { return PNet(new TNet()); }
663  static PNet Load(TSIn& SIn) { return PNet(new TNet(SIn)); }
665 
669  static PNet LoadShM(TShMIn& ShMIn) {
670  TNet* Network = new TNet();
671  Network->LoadNetworkShM(ShMIn);
672  return PNet(Network);
673  }
675  bool HasFlag(const TGraphFlag& Flag) const;
676  TNodeEDatNet& operator = (const TNodeEDatNet& NodeNet) { if (this!=&NodeNet) {
677  NodeH=NodeNet.NodeH; MxNId=NodeNet.MxNId; } return *this; }
678  // nodes
680  int GetNodes() const { return NodeH.Len(); }
682 
686  int AddNode(int NId = -1);
688 
692  int AddNodeUnchecked(int NId = -1);
694 
698  int AddNode(int NId, const TNodeData& NodeDat);
700  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
702 
704  void DelNode(const int& NId);
706  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
708  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
710  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
712  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
714  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
716  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
718  void SetNDat(const int& NId, const TNodeData& NodeDat);
720  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
722  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
724  int GetMxNId() const { return MxNId; }
725 
726  // edges
728  int GetEdges() const;
730 
736  int AddEdge(const int& SrcNId, const int& DstNId);
738 
744  int AddEdge(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat);
746  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI()); }
748 
752  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
754  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
756  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }
758  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
760  TEdgeI GetEI(const int& EId) const; // not supported
762  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
764  void SetEDat(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat);
766 
768  bool GetEDat(const int& SrcNId, const int& DstNId, TEdgeData& EdgeDat) const;
770  TEdgeData& GetEDat(const int& SrcNId, const int& DstNId);
772  const TEdgeData& GetEDat(const int& SrcNId, const int& DstNId) const;
774  void SetAllEDat(const TEdgeData& EdgeDat);
775 
777  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
779  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
781  void GetNIdV(TIntV& NIdV) const;
782 
784  bool Empty() const { return GetNodes()==0; }
786  void Clr(const bool& DoDel=true, const bool& ResetDat=true) {
787  MxNId = 0; NodeH.Clr(DoDel, -1, ResetDat); }
789  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
791  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
793  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
795 
800  void Defrag(const bool& OnlyNodeLinks=false);
802 
805  bool IsOk(const bool& ThrowExcept=true) const;
806 
807  friend class TPt<TNodeEDatNet<TNodeData, TEdgeData> >;
808 };
809 
810 // set flags
811 namespace TSnap {
812 template <class TNodeData, class TEdgeData> struct IsDirected<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
813 template <class TNodeData, class TEdgeData> struct IsNodeDat<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
814 template <class TNodeData, class TEdgeData> struct IsEdgeDat<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
815 }
816 
817 template <class TNodeData, class TEdgeData>
819  return HasGraphFlag(typename TNet, Flag);
820 }
821 
822 template <class TNodeData, class TEdgeData>
824  int LValN=0, RValN = NIdV.Len()-1;
825  while (RValN >= LValN) {
826  const int ValN = (LValN+RValN)/2;
827  const int CurNId = NIdV[ValN].Val1;
828  if (NId == CurNId) { return ValN; }
829  if (NId < CurNId) { RValN=ValN-1; }
830  else { LValN=ValN+1; }
831  }
832  return -1;
833 }
834 
835 template <class TNodeData, class TEdgeData>
837  if (NId == -1) {
838  NId = MxNId; MxNId++;
839  } else {
840  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
841  MxNId = TMath::Mx(NId+1, MxNId());
842  }
843  NodeH.AddDat(NId, TNode(NId));
844  return NId;
845 }
846 
847 template <class TNodeData, class TEdgeData>
849  if (NId == -1) {
850  NId = MxNId; MxNId++;
851  } else {
852  if (IsNode(NId)) { return -1;}
853  MxNId = TMath::Mx(NId+1, MxNId());
854  }
855  NodeH.AddDat(NId, TNode(NId));
856  return NId;
857 }
858 
859 template <class TNodeData, class TEdgeData>
860 int TNodeEDatNet<TNodeData, TEdgeData>::AddNode(int NId, const TNodeData& NodeDat) {
861  if (NId == -1) {
862  NId = MxNId; MxNId++;
863  } else {
864  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
865  MxNId = TMath::Mx(NId+1, MxNId());
866  }
867  NodeH.AddDat(NId, TNode(NId, NodeDat));
868  return NId;
869 }
870 
871 template <class TNodeData, class TEdgeData>
872 void TNodeEDatNet<TNodeData, TEdgeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
873  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
874  NodeH.GetDat(NId).NodeDat = NodeDat;
875 }
876 
877 template <class TNodeData, class TEdgeData>
879  const TNode& Node = GetNode(NId);
880  for (int out = 0; out < Node.GetOutDeg(); out++) {
881  const int nbr = Node.GetOutNId(out);
882  if (nbr == NId) { continue; }
883  TIntV& NIdV = GetNode(nbr).InNIdV;
884  const int pos = NIdV.SearchBin(NId);
885  if (pos != -1) { NIdV.Del(pos); }
886  }
887  for (int in = 0; in < Node.GetInDeg(); in++) {
888  const int nbr = Node.GetInNId(in);
889  if (nbr == NId) { continue; }
890  TNIdDatPrV& NIdDatV = GetNode(nbr).OutNIdV;
891  const int pos = GetNIdPos(NIdDatV, NId);
892  if (pos != -1) { NIdDatV.Del(pos); }
893  }
894  NodeH.DelKey(NId);
895 }
896 
897 template <class TNodeData, class TEdgeData>
899  int edges=0;
900  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
901  edges+=NodeH[N].GetOutDeg(); }
902  return edges;
903 }
904 
905 template <class TNodeData, class TEdgeData>
906 int TNodeEDatNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId) {
907  return AddEdge(SrcNId, DstNId, TEdgeData());
908 }
909 
910 template <class TNodeData, class TEdgeData>
911 int TNodeEDatNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat) {
912  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
913  //IAssert(! IsEdge(SrcNId, DstNId));
914  if (IsEdge(SrcNId, DstNId)) {
915  GetEDat(SrcNId, DstNId) = EdgeDat;
916  return -2;
917  }
918  GetNode(SrcNId).OutNIdV.AddSorted(TPair<TInt, TEdgeData>(DstNId, EdgeDat));
919  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
920  return -1; // no edge id
921 }
922 
923 template <class TNodeData, class TEdgeData>
924 void TNodeEDatNet<TNodeData, TEdgeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
925  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
926  int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId);
927  if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); }
928  pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId);
929  if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); }
930  if (! IsDir) {
931  pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId);
932  if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); }
933  pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId);
934  if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); }
935  }
936 }
937 
938 template <class TNodeData, class TEdgeData>
939 bool TNodeEDatNet<TNodeData, TEdgeData>::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
940  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
941  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
942  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
943 }
944 
945 template <class TNodeData, class TEdgeData>
946 void TNodeEDatNet<TNodeData, TEdgeData>::SetEDat(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat) {
947  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
948  IAssertR(IsEdge(SrcNId, DstNId), TStr::Fmt("Edge between %d and %d does not exist.", SrcNId, DstNId).CStr());
949  GetEDat(SrcNId, DstNId) = EdgeDat;
950 }
951 
952 template <class TNodeData, class TEdgeData>
953 bool TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId, TEdgeData& EdgeDat) const {
954  if (! IsEdge(SrcNId, DstNId)) { return false; }
955  const TNode& N = GetNode(SrcNId);
956  EdgeDat = N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
957  return true;
958 }
959 
960 template <class TNodeData, class TEdgeData>
961 TEdgeData& TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId) {
962  Assert(IsEdge(SrcNId, DstNId));
963  TNode& N = GetNode(SrcNId);
964  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
965 }
966 
967 template <class TNodeData, class TEdgeData>
968 const TEdgeData& TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId) const {
969  Assert(IsEdge(SrcNId, DstNId));
970  const TNode& N = GetNode(SrcNId);
971  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
972 }
973 
974 template <class TNodeData, class TEdgeData>
975 void TNodeEDatNet<TNodeData, TEdgeData>::SetAllEDat(const TEdgeData& EdgeDat) {
976  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
977  EI() = EdgeDat;
978  }
979 }
980 
981 template <class TNodeData, class TEdgeData>
982 typename TNodeEDatNet<TNodeData, TEdgeData>::TEdgeI TNodeEDatNet<TNodeData, TEdgeData>::GetEI(const int& SrcNId, const int& DstNId) const {
983  const TNodeI SrcNI = GetNI(SrcNId);
984  int NodeN = -1;
985  //SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
986  const TNIdDatPrV& NIdDatV = SrcNI.NodeHI.GetDat().OutNIdV;
987  int LValN=0, RValN=NIdDatV.Len()-1;
988  while (RValN>=LValN){
989  int ValN=(LValN+RValN)/2;
990  if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN; break; }
991  if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;} else {LValN=ValN+1;}
992  }
993  if (NodeN == -1) { return EndEI(); }
994  else { return TEdgeI(SrcNI, EndNI(), NodeN); }
995 }
996 
997 template <class TNodeData, class TEdgeData>
999  NIdV.Reserve(GetNodes(), 0);
1000  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1001  NIdV.Add(NodeH.GetKey(N)); }
1002 }
1003 
1004 template <class TNodeData, class TEdgeData>
1005 void TNodeEDatNet<TNodeData, TEdgeData>::Defrag(const bool& OnlyNodeLinks) {
1006  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n);) {
1007  TNode& Node = NodeH[n];
1008  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
1009  }
1010  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
1011  NodeH.Defrag();
1012  }
1013 }
1014 
1015 template <class TNodeData, class TEdgeData>
1016 bool TNodeEDatNet<TNodeData, TEdgeData>::IsOk(const bool& ThrowExcept) const {
1017  bool RetVal = true;
1018  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1019  const TNode& Node = NodeH[N];
1020  if (! Node.OutNIdV.IsSorted()) {
1021  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
1022  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1023  }
1024  if (! Node.InNIdV.IsSorted()) {
1025  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
1026  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1027  }
1028  // check out-edges
1029  int prevNId = -1;
1030  for (int e = 0; e < Node.GetOutDeg(); e++) {
1031  if (! IsNode(Node.GetOutNId(e))) {
1032  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
1033  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
1034  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1035  }
1036  if (e > 0 && prevNId == Node.GetOutNId(e)) {
1037  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
1038  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
1039  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1040  }
1041  prevNId = Node.GetOutNId(e);
1042  }
1043  // check in-edges
1044  prevNId = -1;
1045  for (int e = 0; e < Node.GetInDeg(); e++) {
1046  if (! IsNode(Node.GetInNId(e))) {
1047  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
1048  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
1049  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1050  }
1051  if (e > 0 && prevNId == Node.GetInNId(e)) {
1052  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
1053  Node.GetId(), Node.GetId(), Node.GetInNId(e));
1054  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1055  }
1056  prevNId = Node.GetInNId(e);
1057  }
1058  }
1059  return RetVal;
1060 }
1061 
1063 // Common network types
1070 
1071 //#//////////////////////////////////////////////
1073 template <class TNodeData, class TEdgeData>
1075 public:
1076  typedef TNodeData TNodeDat;
1077  typedef TEdgeData TEdgeDat;
1079  typedef TPt<TNet> PNet;
1080 public:
1081  class TNode {
1082  private:
1085  TNodeData NodeDat;
1086  public:
1087  TNode() : Id(-1), InEIdV(), OutEIdV(), NodeDat() { }
1088  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV(), NodeDat() { }
1089  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), InEIdV(), OutEIdV(), NodeDat(NodeData) { }
1090  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV), NodeDat(Node.NodeDat) { }
1091  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn), NodeDat(SIn) { }
1092  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); NodeDat.Save(SOut); }
1093  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
1094  int GetId() const { return Id; }
1095  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
1096  int GetInDeg() const { return InEIdV.Len(); }
1097  int GetOutDeg() const { return OutEIdV.Len(); }
1098  const TNodeData& GetDat() const { return NodeDat; }
1099  TNodeData& GetDat() { return NodeDat; }
1100  int GetInEId(const int& NodeN) const { return InEIdV[NodeN]; }
1101  int GetOutEId(const int& NodeN) const { return OutEIdV[NodeN]; }
1102  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1103  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
1104  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
1105  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
1106  void LoadShM(TShMIn& MStream) {
1107  Id = TInt(MStream);
1108  InEIdV.LoadShM(MStream);
1109  OutEIdV.LoadShM(MStream);
1110  NodeDat = TNodeData(MStream);
1111  }
1112  friend class TNodeEdgeNet<TNodeData, TEdgeData>;
1113  };
1114 
1115  class TEdge {
1116  private:
1118  TEdgeData EdgeDat;
1119  public:
1120  TEdge() : Id(-1), SrcNId(-1), DstNId(-1), EdgeDat() { }
1121  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId), EdgeDat() { }
1122  TEdge(const int& EId, const int& SourceNId, const int& DestNId, const TEdgeData& EdgeData) : Id(EId), SrcNId(SourceNId), DstNId(DestNId), EdgeDat(EdgeData) { }
1123  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId), EdgeDat(Edge.EdgeDat) { }
1124  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn), EdgeDat(SIn) { }
1125  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); EdgeDat.Save(SOut); }
1126  bool operator < (const TEdge& Edge) const { return EdgeDat < Edge.EdgeDat; }
1127  int GetId() const { return Id; }
1128  int GetSrcNId() const { return SrcNId; }
1129  int GetDstNId() const { return DstNId; }
1130  void Load(TSIn& InStream) {
1131  Id = TInt(InStream);
1132  SrcNId = TInt(InStream);
1133  DstNId = TInt(InStream);
1134  EdgeDat = TEdgeData(InStream);
1135 
1136  }
1137  const TEdgeData& GetDat() const { return EdgeDat; }
1138  TEdgeData& GetDat() { return EdgeDat; }
1139  friend class TNodeEdgeNet;
1140  };
1141 
1143  class TNodeI {
1144  private:
1148  public:
1149  TNodeI() : NodeHI(), Net(NULL) { }
1150  TNodeI(const THashIter& NodeHIter, const TNodeEdgeNet* NetPt) : NodeHI(NodeHIter), Net((TNodeEdgeNet *)NetPt) { }
1151  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
1152  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Net=NodeI.Net; return *this; }
1154  TNodeI& operator++ (int) { NodeHI++; return *this; }
1155  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
1156  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
1158  int GetId() const { return NodeHI.GetDat().GetId(); }
1160  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
1162  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
1164  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
1166 
1168  int GetInNId(const int& EdgeN) const { return Net->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1170 
1172  int GetOutNId(const int& EdgeN) const { return Net->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1174 
1176  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Net->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN));
1177  return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
1179  bool IsInNId(const int& NId) const;
1181  bool IsOutNId(const int& NId) const;
1183  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
1184  // node data
1185  const TNodeData& operator () () const { return NodeHI.GetDat().GetDat(); }
1186  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
1187  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
1188  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
1189  const TNodeData& GetInNDat(const int& EdgeN) const { return Net->GetNDat(GetInNId(EdgeN)); }
1190  TNodeData& GetInNDat(const int& EdgeN) { return Net->GetNDat(GetInNId(EdgeN)); }
1191  const TNodeData& GetOutNDat(const int& EdgeN) const { return Net->GetNDat(GetOutNId(EdgeN)); }
1192  TNodeData& GetOutNDat(const int& EdgeN) { return Net->GetNDat(GetOutNId(EdgeN)); }
1193  const TNodeData& GetNbrNDat(const int& EdgeN) const { return Net->GetNDat(GetNbrNId(EdgeN)); }
1194  TNodeData& GetNbrNDat(const int& EdgeN) { return Net->GetNDat(GetNbrNId(EdgeN)); }
1195  // edges
1197  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
1199  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
1201  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
1203  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
1205  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
1207  bool IsNbrEId(const int& EId) const { return NodeHI.GetDat().IsNbrEId(EId); }
1208  // edge data
1209  TEdgeDat& GetInEDat(const int& EdgeN) { return Net->GetEDat(GetInEId(EdgeN)); }
1210  const TEdgeDat& GetInEDat(const int& EdgeN) const { return Net->GetEDat(GetInEId(EdgeN)); }
1211  TEdgeDat& GetOutEDat(const int& EdgeN) { return Net->GetEDat(GetOutEId(EdgeN)); }
1212  const TEdgeDat& GetOutEDat(const int& EdgeN) const { return Net->GetEDat(GetOutEId(EdgeN)); }
1213  TEdgeDat& GetNbrEDat(const int& EdgeN) { return Net->GetEDat(GetNbrEId(EdgeN)); }
1214  const TEdgeDat& GetNbrEDat(const int& EdgeN) const { return Net->GetEDat(GetNbrEId(EdgeN)); }
1215  friend class TNodeEdgeNet;
1216  };
1217 
1219  class TEdgeI {
1220  private:
1224  public:
1225  TEdgeI() : EdgeHI(), Net(NULL) { }
1226  TEdgeI(const THashIter& EdgeHIter, const TNodeEdgeNet *NetPt) : EdgeHI(EdgeHIter), Net((TNodeEdgeNet *) NetPt) { }
1227  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Net(EdgeI.Net) { }
1228  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Net=EdgeI.Net; } return *this; }
1229  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
1230  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
1231  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
1233  int GetId() const { return EdgeHI.GetDat().GetId(); }
1235  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
1237  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
1238  const TEdgeData& operator () () const { return EdgeHI.GetDat().GetDat(); }
1239  TEdgeData& operator () () { return EdgeHI.GetDat().GetDat(); }
1240  const TEdgeData& GetDat() const { return EdgeHI.GetDat().GetDat(); }
1241  TEdgeData& GetDat() { return EdgeHI.GetDat().GetDat(); }
1242  const TNodeData& GetSrcNDat() const { return Net->GetNDat(GetSrcNId()); }
1243  TNodeData& GetSrcNDat() { return Net->GetNDat(GetSrcNId()); }
1244  const TNodeData& GetDstNDat() const { return Net->GetNDat(GetDstNId()); }
1245  TNodeData& GetDstNDat() { return Net->GetNDat(GetDstNId()); }
1246  friend class TNodeEdgeNet;
1247  };
1248 
1249 private:
1250  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
1251  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
1252  const TNode& GetNodeKId(const int& NodeKeyId) const { return NodeH[NodeKeyId]; }
1253  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
1254  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
1255  const TEdge& GetEdgeKId(const int& EdgeKeyId) const { return EdgeH[EdgeKeyId]; }
1256 protected:
1261 private:
1263  public:
1265  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
1266  };
1267 private:
1268  void LoadNetworkShM(TShMIn& ShMIn) {
1269  MxNId = TInt(ShMIn);
1270  MxEId = TInt(ShMIn);
1271  LoadTNodeFunctor fn;
1272  NodeH.LoadShM(ShMIn, fn);
1273  EdgeH.LoadShM(ShMIn);
1274  }
1275 public:
1276  TNodeEdgeNet() : CRef(), MxNId(0), MxEId(0) { }
1278  explicit TNodeEdgeNet(const int& Nodes, const int& Edges) : CRef(), MxNId(0), MxEId(0) { Reserve(Nodes, Edges); }
1279  TNodeEdgeNet(const TNodeEdgeNet& Net) : MxNId(Net.MxNId), MxEId(Net.MxEId), NodeH(Net.NodeH), EdgeH(Net.EdgeH) { }
1281  TNodeEdgeNet(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn) { }
1282  virtual ~TNodeEdgeNet() { }
1284  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut); }
1286 
1288  static PNet New() { return PNet(new TNet()); }
1290  static PNet Load(TSIn& SIn) { return PNet(new TNet(SIn)); }
1292 
1296  static PNet LoadShM(TShMIn& ShMIn) {
1297  TNet* Network = new TNet();
1298  Network->LoadNetworkShM(ShMIn);
1299  return PNet(Network);
1300  }
1302  bool HasFlag(const TGraphFlag& Flag) const;
1304  if (this!=&Net) { NodeH=Net.NodeH; EdgeH=Net.EdgeH; MxNId=Net.MxNId; MxEId=Net.MxEId; } return *this; }
1305  // nodes
1307  int GetNodes() const { return NodeH.Len(); }
1309 
1313  int AddNode(int NId = -1);
1315 
1319  int AddNodeUnchecked(int NId = -1);
1321 
1325  int AddNode(int NId, const TNodeData& NodeDat);
1327  friend class TCrossNet;
1328  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
1330 
1332  void DelNode(const int& NId);
1334  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
1336  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
1338  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
1340  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
1342  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
1344  void SetNDat(const int& NId, const TNodeData& NodeDat);
1346  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
1348  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
1350  int GetMxNId() const { return MxNId; }
1351 
1352  // edges
1354  int GetEdges() const { return EdgeH.Len(); }
1356  int GetUniqEdges(const bool& IsDir=true) const;
1358 
1363  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
1365 
1370  int AddEdge(const int& SrcNId, const int& DstNId, int EId, const TEdgeData& EdgeDat);
1372  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId(), EdgeI.GetDat()); }
1374  void DelEdge(const int& EId);
1376 
1380  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
1382  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
1384  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
1386  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
1387  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
1389  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
1391  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
1393  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
1395  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
1397  void SetEDat(const int& EId, const TEdgeData& EdgeDat);
1399  TEdgeData& GetEDat(const int& EId) { return EdgeH.GetDat(EId).EdgeDat; }
1401  const TEdgeData& GetEDat(const int& EId) const { return EdgeH.GetDat(EId).EdgeDat; }
1403  void SetAllEDat(const TEdgeData& EdgeDat);
1404 
1406  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
1408  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
1410  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
1412  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
1414  void GetNIdV(TIntV& NIdV) const;
1416  void GetEIdV(TIntV& EIdV) const;
1417 
1419  bool Empty() const { return GetNodes()==0; }
1421  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr(); }
1423  void Reserve(const int& Nodes, const int& Edges) {
1424  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
1426  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
1428  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
1430  void SortEIdById(const bool& Asc=true) { EdgeH.SortByKey(Asc); }
1432  void SortEIdByDat(const bool& Asc=true) { EdgeH.SortByDat(Asc); }
1434 
1439  void Defrag(const bool& OnlyNodeLinks=false);
1441 
1444  bool IsOk(const bool& ThrowExcept=true) const;
1445 
1446  friend class TPt<TNodeEdgeNet<TNodeData, TEdgeData> >;
1447 };
1448 
1449 // set flags
1450 namespace TSnap {
1451 template <class TNodeData, class TEdgeData> struct IsMultiGraph<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1452 template <class TNodeData, class TEdgeData> struct IsDirected<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1453 template <class TNodeData, class TEdgeData> struct IsNodeDat<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1454 template <class TNodeData, class TEdgeData> struct IsEdgeDat<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1455 }
1456 
1457 template <class TNodeData, class TEdgeData>
1459  return HasGraphFlag(typename TNet, Flag);
1460 }
1461 
1462 template <class TNodeData, class TEdgeData>
1464  const TNode& Node = NodeHI.GetDat();
1465  for (int edge = 0; edge < Node.GetInDeg(); edge++) {
1466  if (NId == Net->GetEdge(Node.GetInEId(edge)).GetSrcNId())
1467  return true;
1468  }
1469  return false;
1470 }
1471 
1472 template <class TNodeData, class TEdgeData>
1474  const TNode& Node = NodeHI.GetDat();
1475  for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
1476  if (NId == Net->GetEdge(Node.GetOutEId(edge)).GetDstNId())
1477  return true;
1478  }
1479  return false;
1480 }
1481 
1482 template <class TNodeData, class TEdgeData>
1484  if (NId == -1) {
1485  NId = MxNId; MxNId++;
1486  } else {
1487  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1488  MxNId = TMath::Mx(NId+1, MxNId());
1489  }
1490  NodeH.AddDat(NId, TNode(NId));
1491  return NId;
1492 }
1493 
1494 template <class TNodeData, class TEdgeData>
1496  if (NId == -1) {
1497  NId = MxNId; MxNId++;
1498  } else {
1499  if (IsNode(NId)) { return -1;}
1500  MxNId = TMath::Mx(NId+1, MxNId());
1501  }
1502  NodeH.AddDat(NId, TNode(NId));
1503  return NId;
1504 }
1505 
1506 template <class TNodeData, class TEdgeData>
1507 int TNodeEdgeNet<TNodeData, TEdgeData>::AddNode(int NId, const TNodeData& NodeDat) {
1508  if (NId == -1) {
1509  NId = MxNId; MxNId++;
1510  } else {
1511  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1512  MxNId = TMath::Mx(NId+1, MxNId());
1513  }
1514  NodeH.AddDat(NId, TNode(NId, NodeDat));
1515  return NId;
1516 }
1517 
1518 template <class TNodeData, class TEdgeData>
1520  const TNode& Node = GetNode(NId);
1521  for (int out = 0; out < Node.GetOutDeg(); out++) {
1522  const int EId = Node.GetOutEId(out);
1523  const TEdge& Edge = GetEdge(EId);
1524  IAssert(Edge.GetSrcNId() == NId);
1525  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
1526  EdgeH.DelKey(EId);
1527  }
1528  for (int in = 0; in < Node.GetInDeg(); in++) {
1529  const int EId = Node.GetInEId(in);
1530  const TEdge& Edge = GetEdge(EId);
1531  IAssert(Edge.GetDstNId() == NId);
1532  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
1533  EdgeH.DelKey(EId);
1534  }
1535  NodeH.DelKey(NId);
1536 }
1537 
1538 template <class TNodeData, class TEdgeData>
1539 void TNodeEdgeNet<TNodeData, TEdgeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
1540  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
1541  NodeH.GetDat(NId).NodeDat = NodeDat;
1542 }
1543 
1544 template <class TNodeData, class TEdgeData>
1546  TIntPrSet UniqESet(GetEdges());
1547  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1548  const int Src = EI.GetSrcNId();
1549  const int Dst = EI.GetDstNId();
1550  if (IsDir) { UniqESet.AddKey(TIntPr(Src, Dst)); }
1551  else { UniqESet.AddKey(TIntPr(TMath::Mn(Src, Dst), TMath::Mx(Src, Dst))); }
1552  }
1553  return UniqESet.Len();
1554 }
1555 
1556 template <class TNodeData, class TEdgeData>
1557 int TNodeEdgeNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, int EId) {
1558  if (EId == -1) { EId = MxEId; MxEId++; }
1559  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1560  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1561  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1562  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
1563  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1564  GetNode(DstNId).InEIdV.AddSorted(EId);
1565  return EId;
1566 }
1567 
1568 template <class TNodeData, class TEdgeData>
1569 int TNodeEdgeNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, int EId, const TEdgeData& EdgeDat) {
1570  if (EId == -1) { EId = MxEId; MxEId++; }
1571  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1572  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1573  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1574  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId, EdgeDat));
1575  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1576  GetNode(DstNId).InEIdV.AddSorted(EId);
1577  return EId;
1578 }
1579 
1580 template <class TNodeData, class TEdgeData>
1582  IAssert(IsEdge(EId));
1583  const int SrcNId = GetEdge(EId).GetSrcNId();
1584  const int DstNId = GetEdge(EId).GetDstNId();
1585  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1586  GetNode(DstNId).InEIdV.DelIfIn(EId);
1587  EdgeH.DelKey(EId);
1588 }
1589 
1590 template <class TNodeData, class TEdgeData>
1591 void TNodeEdgeNet<TNodeData, TEdgeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
1592  int EId;
1593  IAssert(IsEdge(SrcNId, DstNId, EId, IsDir));
1594  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1595  GetNode(DstNId).InEIdV.DelIfIn(EId);
1596  EdgeH.DelKey(EId);
1597 }
1598 
1599 template <class TNodeData, class TEdgeData>
1600 bool TNodeEdgeNet<TNodeData, TEdgeData>::IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir) const {
1601  if (! IsNode(SrcNId)) { return false; }
1602  if (! IsNode(DstNId)) { return false; }
1603  const TNode& SrcNode = GetNode(SrcNId);
1604  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
1605  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
1606  if (DstNId == Edge.GetDstNId()) {
1607  EId = Edge.GetId(); return true; }
1608  }
1609  if (! IsDir) {
1610  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
1611  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
1612  if (DstNId == Edge.GetSrcNId()) {
1613  EId = Edge.GetId(); return true; }
1614  }
1615  }
1616  return false;
1617 }
1618 
1619 template <class TNodeData, class TEdgeData>
1620 void TNodeEdgeNet<TNodeData, TEdgeData>::SetEDat(const int& EId, const TEdgeData& EdgeDat) {
1621  IAssertR(IsEdge(EId), TStr::Fmt("EdgeId %d does not exist.", EId).CStr());
1622  GetEI(EId).GetDat() = EdgeDat;
1623 }
1624 
1625 template <class TNodeData, class TEdgeData>
1626 void TNodeEdgeNet<TNodeData, TEdgeData>::SetAllEDat(const TEdgeData& EdgeDat) {
1627  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1628  EI() = EdgeDat;
1629  }
1630 }
1631 
1632 
1633 template <class TNodeData, class TEdgeData>
1635  NIdV.Gen(GetNodes(), 0);
1636  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
1637  NIdV.Add(NodeH.GetKey(N));
1638  }
1639 }
1640 
1641 template <class TNodeData, class TEdgeData>
1643  EIdV.Gen(GetEdges(), 0);
1644  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E);) {
1645  EIdV.Add(EdgeH.GetKey(E));
1646  }
1647 }
1648 
1649 template <class TNodeData, class TEdgeData>
1650 void TNodeEdgeNet<TNodeData, TEdgeData>::Defrag(const bool& OnlyNodeLinks) {
1651  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid);) {
1652  TNode& Node = NodeH[kid];
1653  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
1654  }
1655  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
1656  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
1657 }
1658 
1659 template <class TNodeData, class TEdgeData>
1660 bool TNodeEdgeNet<TNodeData, TEdgeData>::IsOk(const bool& ThrowExcept) const {
1661  bool RetVal = true;
1662  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1663  const TNode& Node = NodeH[N];
1664  if (! Node.OutEIdV.IsSorted()) {
1665  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
1666  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1667  }
1668  if (! Node.InEIdV.IsSorted()) {
1669  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
1670  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1671  }
1672  // check out-edge ids
1673  int prevEId = -1;
1674  for (int e = 0; e < Node.GetOutDeg(); e++) {
1675  if (! IsEdge(Node.GetOutEId(e))) {
1676  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
1677  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1678  }
1679  if (e > 0 && prevEId == Node.GetOutEId(e)) {
1680  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
1681  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1682  }
1683  prevEId = Node.GetOutEId(e);
1684  }
1685  // check in-edge ids
1686  prevEId = -1;
1687  for (int e = 0; e < Node.GetInDeg(); e++) {
1688  if (! IsEdge(Node.GetInEId(e))) {
1689  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
1690  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1691  }
1692  if (e > 0 && prevEId == Node.GetInEId(e)) {
1693  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
1694  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1695  }
1696  prevEId = Node.GetInEId(e);
1697  }
1698  }
1699  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
1700  const TEdge& Edge = EdgeH[E];
1701  if (! IsNode(Edge.GetSrcNId())) {
1702  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
1703  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1704  }
1705  if (! IsNode(Edge.GetDstNId())) {
1706  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
1707  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1708  }
1709  }
1710  return RetVal;
1711 }
1712 
1714 // Common Node-Edge Network Types
1719 
1720 class TNEANet;
1722 typedef TPt<TNEANet> PNEANet;
1723 
1724 //#//////////////////////////////////////////////
1726 
1741 class TNEANet {
1742 public:
1743  typedef TNEANet TNet;
1745 public:
1746  class TNode {
1747  private:
1749  TIntV InEIdV, OutEIdV;
1750  public:
1751  TNode() : Id(-1), InEIdV(), OutEIdV() { }
1752  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
1753  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
1754  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn) { }
1755  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); }
1756  int GetId() const { return Id; }
1757  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
1758  int GetInDeg() const { return InEIdV.Len(); }
1759  int GetOutDeg() const { return OutEIdV.Len(); }
1760  int GetInEId(const int& EdgeN) const { return InEIdV[EdgeN]; }
1761  int GetOutEId(const int& EdgeN) const { return OutEIdV[EdgeN]; }
1762  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1763  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
1764  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
1765  void LoadShM(TShMIn& MStream) {
1766  Id = TInt(MStream);
1767  InEIdV.LoadShM(MStream);
1768  OutEIdV.LoadShM(MStream);
1769  }
1770  friend class TNEANet;
1771  };
1772  class TEdge {
1773  private:
1774  TInt Id, SrcNId, DstNId;
1775  public:
1776  TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
1777  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
1778  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
1779  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn) { }
1780  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
1781  int GetId() const { return Id; }
1782  int GetSrcNId() const { return SrcNId; }
1783  int GetDstNId() const { return DstNId; }
1784  void Load(TSIn& InStream) {
1785  Id = TInt(InStream);
1786  SrcNId = TInt(InStream);
1787  DstNId = TInt(InStream);
1788  }
1789  friend class TNEANet;
1790  };
1792  class TNodeI {
1793  protected:
1796  const TNEANet *Graph;
1797  public:
1798  TNodeI() : NodeHI(), Graph(NULL) { }
1799  TNodeI(const THashIter& NodeHIter, const TNEANet* GraphPt) : NodeHI(NodeHIter), Graph(GraphPt) { }
1800  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Graph(NodeI.Graph) { }
1801  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Graph=NodeI.Graph; return *this; }
1803  TNodeI& operator++ (int) { NodeHI++; return *this; }
1804  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
1805  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
1807  int GetId() const { return NodeHI.GetDat().GetId(); }
1809  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
1811  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
1813  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
1815 
1817  int GetInNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1819 
1821  int GetOutNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1823 
1825  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Graph->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN)); return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
1827  bool IsInNId(const int& NId) const;
1829  bool IsOutNId(const int& NId) const;
1831  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
1833  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
1835  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
1837  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
1839  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
1841  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
1843  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
1845  void GetAttrNames(TStrV& Names) const { Graph->AttrNameNI(GetId(), Names); }
1847  void GetAttrVal(TStrV& Val) const { Graph->AttrValueNI(GetId(), Val); }
1849  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameNI(GetId(), Names); }
1851  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueNI(GetId(), Val); }
1853  void GetIntVAttrNames(TStrV& Names) const { Graph->IntVAttrNameNI(GetId(), Names); }
1855  void GetIntVAttrVal(TVec<TIntV>& Val) const { Graph->IntVAttrValueNI(GetId(), Val); }
1857  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameNI(GetId(), Names); }
1859  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueNI(GetId(), Val); }
1861  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameNI(GetId(), Names); }
1863  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueNI(GetId(), Val); }
1864  friend class TNEANet;
1865  };
1867  class TEdgeI {
1868  private:
1871  const TNEANet *Graph;
1872  public:
1873  TEdgeI() : EdgeHI(), Graph(NULL) { }
1874  TEdgeI(const THashIter& EdgeHIter, const TNEANet *GraphPt) : EdgeHI(EdgeHIter), Graph(GraphPt) { }
1875  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Graph(EdgeI.Graph) { }
1876  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Graph=EdgeI.Graph; } return *this; }
1878  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
1879  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
1880  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
1882  int GetId() const { return EdgeHI.GetDat().GetId(); }
1884  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
1886  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
1888  void GetAttrNames(TStrV& Names) const { Graph->AttrNameEI(GetId(), Names); }
1890  void GetAttrVal(TStrV& Val) const { Graph->AttrValueEI(GetId(), Val); }
1892  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameEI(GetId(), Names); }
1894  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueEI(GetId(), Val); }
1896  void GetIntVAttrNames(TStrV& Names) const { Graph->IntVAttrNameEI(GetId(), Names); }
1898  void GetIntVAttrVal(TVec<TIntV>& Val) const { Graph->IntVAttrValueEI(GetId(), Val); }
1900  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameEI(GetId(), Names); }
1902  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueEI(GetId(), Val); }
1904  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameEI(GetId(), Names); }
1906  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueEI(GetId(), Val); }
1907  friend class TNEANet;
1908  };
1909 
1911  class TAIntI {
1912  private:
1915  bool isNode;
1917  const TNEANet *Graph;
1918  public:
1919  TAIntI() : HI(), attr(), Graph(NULL) { }
1920  TAIntI(const TIntVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1921  TAIntI(const TAIntI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1922  TAIntI& operator = (const TAIntI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1923  bool operator < (const TAIntI& I) const { return HI < I.HI; }
1924  bool operator == (const TAIntI& I) const { return HI == I.HI; }
1926  TInt GetDat() const { return HI[0]; }
1928  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetIntAttrDefaultN(attr) : GetDat() == Graph->GetIntAttrDefaultE(attr); };
1929  TAIntI& operator++(int) { HI++; return *this; }
1930  friend class TNEANet;
1931  };
1932 
1933  class TAIntVI {
1934  private:
1937  bool IsDense;
1940  bool isNode;
1942  const TNEANet *Graph;
1943  public:
1944  TAIntVI() : HI(), IsDense(), HHI(), attr(), Graph(NULL) { }
1945  TAIntVI(const TIntVVecIter& HIter, const TIntHVecIter& HHIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt, bool is_dense) : HI(HIter), IsDense(is_dense), HHI(HHIter), attr(), Graph(GraphPt) {
1946  isNode = !isEdgeIter; attr = attribute;
1947  }
1948  TAIntVI(const TAIntVI& I) : HI(I.HI), IsDense(I.IsDense), HHI(I.HHI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1949  TAIntVI& operator = (const TAIntVI& I) { HI = I.HI; HHI = I.HHI, Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1950  bool operator < (const TAIntVI& I) const { return HI == I.HI ? HHI < I.HHI : HI < I.HI; }
1951  bool operator == (const TAIntVI& I) const { return HI == I.HI && HHI == I.HHI; }
1953  TIntV GetDat() const { return IsDense? HI[0] : HHI.GetDat(); }
1954  TAIntVI& operator++(int) { if (IsDense) {HI++;} else {HHI++;} return *this; }
1955  friend class TNEANet;
1956  };
1957 
1959  class TAStrI {
1960  private:
1963  bool isNode;
1965  const TNEANet *Graph;
1966  public:
1967  TAStrI() : HI(), attr(), Graph(NULL) { }
1968  TAStrI(const TStrVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1969  TAStrI(const TAStrI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1970  TAStrI& operator = (const TAStrI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1971  bool operator < (const TAStrI& I) const { return HI < I.HI; }
1972  bool operator == (const TAStrI& I) const { return HI == I.HI; }
1974  TStr GetDat() const { return HI[0]; }
1976  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetStrAttrDefaultN(attr) : GetDat() == Graph->GetStrAttrDefaultE(attr); };
1977  TAStrI& operator++(int) { HI++; return *this; }
1978  friend class TNEANet;
1979  };
1980 
1982  class TAFltI {
1983  private:
1986  bool isNode;
1988  const TNEANet *Graph;
1989  public:
1990  TAFltI() : HI(), attr(), Graph(NULL) { }
1991  TAFltI(const TFltVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1992  TAFltI(const TAFltI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1993  TAFltI& operator = (const TAFltI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1994  bool operator < (const TAFltI& I) const { return HI < I.HI; }
1995  bool operator == (const TAFltI& I) const { return HI == I.HI; }
1997  TFlt GetDat() const { return HI[0]; }
1999  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetFltAttrDefaultN(attr) : GetDat() == Graph->GetFltAttrDefaultE(attr); };
2000  TAFltI& operator++(int) { HI++; return *this; }
2001  friend class TNEANet;
2002  };
2003 
2004 protected:
2005  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
2006  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
2007  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
2008  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
2009  int AddAttributes(const int NId);
2010 
2011 protected:
2013  TInt GetIntAttrDefaultN(const TStr& attribute) const { return IntDefaultsN.IsKey(attribute) ? IntDefaultsN.GetDat(attribute) : (TInt) TInt::Mn; }
2015  TStr GetStrAttrDefaultN(const TStr& attribute) const { return StrDefaultsN.IsKey(attribute) ? StrDefaultsN.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
2017  TFlt GetFltAttrDefaultN(const TStr& attribute) const { return FltDefaultsN.IsKey(attribute) ? FltDefaultsN.GetDat(attribute) : (TFlt) TFlt::Mn; }
2019  TInt GetIntAttrDefaultE(const TStr& attribute) const { return IntDefaultsE.IsKey(attribute) ? IntDefaultsE.GetDat(attribute) : (TInt) TInt::Mn; }
2021  TStr GetStrAttrDefaultE(const TStr& attribute) const { return StrDefaultsE.IsKey(attribute) ? StrDefaultsE.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
2023  TFlt GetFltAttrDefaultE(const TStr& attribute) const { return FltDefaultsE.IsKey(attribute) ? FltDefaultsE.GetDat(attribute) : (TFlt) TFlt::Mn; }
2024 public:
2026 protected:
2034 
2044 
2047 private:
2049  public:
2051  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
2052  };
2054  public:
2056  template<typename TElem>
2057  void operator() (TVec<TElem>* n, TShMIn& ShMIn) {
2058  n->LoadShM(ShMIn);
2059  }
2060  };
2062  public:
2064  template<typename TElem>
2065  void operator() (TVec<TVec<TElem> >* n, TShMIn& ShMIn) {
2066  LoadVecFunctor f;
2067  n->LoadShM(ShMIn, f);
2068  }
2069  };
2070 
2072  public:
2074  template<typename TElem>
2075  void operator() (THash<TInt, TVec<TElem> >* n, TShMIn& ShMIn) {
2076  LoadVecFunctor f;
2077  n->LoadShM(ShMIn, f);
2078  }
2079  };
2080 
2081 protected:
2083  TInt CheckDenseOrSparseN(const TStr& attr) const {
2084  if (!KeyToDenseN.IsKey(attr)) return -1;
2085  if (KeyToDenseN.GetDat(attr)) return 1;
2086  return 0;
2087  }
2088 
2089  TInt CheckDenseOrSparseE(const TStr& attr) const {
2090  if (!KeyToDenseE.IsKey(attr)) return -1;
2091  if (KeyToDenseE.GetDat(attr)) return 1;
2092  return 0;
2093  }
2094 
2095 
2096 public:
2097  TNEANet() : CRef(), MxNId(0), MxEId(0), NodeH(), EdgeH(),
2098  KeyToIndexTypeN(), KeyToIndexTypeE(), KeyToDenseN(), KeyToDenseE(), IntDefaultsN(), IntDefaultsE(),
2099  StrDefaultsN(), StrDefaultsE(), FltDefaultsN(), FltDefaultsE(),
2100  VecOfIntVecsN(), VecOfIntVecsE(), VecOfStrVecsN(), VecOfStrVecsE(),
2101  VecOfFltVecsN(), VecOfFltVecsE(), VecOfIntVecVecsN(), VecOfIntVecVecsE(),
2102  VecOfIntHashVecsN(), VecOfIntHashVecsE(), SAttrN(), SAttrE(){ }
2104  explicit TNEANet(const int& Nodes, const int& Edges) : CRef(),
2105  MxNId(0), MxEId(0), NodeH(), EdgeH(), KeyToIndexTypeN(), KeyToIndexTypeE(), KeyToDenseN(), KeyToDenseE(),
2106  IntDefaultsN(), IntDefaultsE(), StrDefaultsN(), StrDefaultsE(),
2107  FltDefaultsN(), FltDefaultsE(), VecOfIntVecsN(), VecOfIntVecsE(),
2108  VecOfStrVecsN(), VecOfStrVecsE(), VecOfFltVecsN(), VecOfFltVecsE(), VecOfIntVecVecsN(), VecOfIntVecVecsE(),
2109  VecOfIntHashVecsN(), VecOfIntHashVecsE(), SAttrN(), SAttrE()
2110  { Reserve(Nodes, Edges); }
2111  TNEANet(const TNEANet& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
2112  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(), KeyToIndexTypeE(), KeyToDenseN(), KeyToDenseE(),
2113  IntDefaultsN(), IntDefaultsE(), StrDefaultsN(), StrDefaultsE(),
2114  FltDefaultsN(), FltDefaultsE(), VecOfIntVecsN(), VecOfIntVecsE(),
2115  VecOfStrVecsN(), VecOfStrVecsE(), VecOfFltVecsN(), VecOfFltVecsE(), VecOfIntVecVecsN(), VecOfIntVecVecsE(),
2116  VecOfIntHashVecsN(), VecOfIntHashVecsE(), SAttrN(), SAttrE() { }
2118  TNEANet(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn),
2119  KeyToIndexTypeN(SIn), KeyToIndexTypeE(SIn), KeyToDenseN(SIn), KeyToDenseE(SIn), IntDefaultsN(SIn), IntDefaultsE(SIn),
2120  StrDefaultsN(SIn), StrDefaultsE(SIn), FltDefaultsN(SIn), FltDefaultsE(SIn),
2121  VecOfIntVecsN(SIn), VecOfIntVecsE(SIn), VecOfStrVecsN(SIn),VecOfStrVecsE(SIn),
2122  VecOfFltVecsN(SIn), VecOfFltVecsE(SIn), VecOfIntVecVecsN(SIn), VecOfIntVecVecsE(SIn), VecOfIntHashVecsN(SIn), VecOfIntHashVecsE(SIn),
2123  SAttrN(SIn), SAttrE(SIn) { }
2124 protected:
2125  TNEANet(const TNEANet& Graph, bool modeSubGraph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
2126  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(), KeyToIndexTypeE(Graph.KeyToIndexTypeE), KeyToDenseN(), KeyToDenseE(Graph.KeyToDenseE),
2127  IntDefaultsN(Graph.IntDefaultsN), IntDefaultsE(Graph.IntDefaultsE), StrDefaultsN(Graph.StrDefaultsN), StrDefaultsE(Graph.StrDefaultsE),
2128  FltDefaultsN(Graph.FltDefaultsN), FltDefaultsE(Graph.FltDefaultsE), VecOfIntVecsN(Graph.VecOfIntVecsN), VecOfIntVecsE(Graph.VecOfIntVecsE),
2129  VecOfStrVecsN(Graph.VecOfStrVecsN), VecOfStrVecsE(Graph.VecOfStrVecsE), VecOfFltVecsN(Graph.VecOfFltVecsN), VecOfFltVecsE(Graph.VecOfFltVecsE),
2130  VecOfIntVecVecsN(), VecOfIntVecVecsE(Graph.VecOfIntVecVecsE), VecOfIntHashVecsN(), VecOfIntHashVecsE(Graph.VecOfIntHashVecsE) { }
2131  TNEANet(bool copyAll, const TNEANet& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
2132  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(Graph.KeyToIndexTypeN), KeyToIndexTypeE(Graph.KeyToIndexTypeE), KeyToDenseN(Graph.KeyToDenseN), KeyToDenseE(Graph.KeyToDenseE),
2133  IntDefaultsN(Graph.IntDefaultsN), IntDefaultsE(Graph.IntDefaultsE), StrDefaultsN(Graph.StrDefaultsN), StrDefaultsE(Graph.StrDefaultsE),
2134  FltDefaultsN(Graph.FltDefaultsN), FltDefaultsE(Graph.FltDefaultsE), VecOfIntVecsN(Graph.VecOfIntVecsN), VecOfIntVecsE(Graph.VecOfIntVecsE),
2135  VecOfStrVecsN(Graph.VecOfStrVecsN), VecOfStrVecsE(Graph.VecOfStrVecsE), VecOfFltVecsN(Graph.VecOfFltVecsN), VecOfFltVecsE(Graph.VecOfFltVecsE),
2136  VecOfIntVecVecsN(Graph.VecOfIntVecVecsN), VecOfIntVecVecsE(Graph.VecOfIntVecVecsE), VecOfIntHashVecsN(Graph.VecOfIntHashVecsN), VecOfIntHashVecsE(Graph.VecOfIntHashVecsE), SAttrN(Graph.SAttrN), SAttrE(Graph.SAttrE) { }
2137  // virtual ~TNEANet() { }
2138 public:
2140  void Save(TSOut& SOut) const {
2141  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
2142  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
2143  KeyToDenseN.Save(SOut); KeyToDenseE.Save(SOut);
2144  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
2145  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
2146  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
2147  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
2148  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
2149  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut);
2150  VecOfIntVecVecsN.Save(SOut); VecOfIntVecVecsE.Save(SOut);
2151  VecOfIntHashVecsN.Save(SOut); VecOfIntHashVecsE.Save(SOut);
2152  SAttrN.Save(SOut); SAttrE.Save(SOut); }
2154  void Save_V1(TSOut& SOut) const {
2155  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
2156  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
2157  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
2158  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
2159  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
2160  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
2161  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
2162  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut); }
2164  void Save_V2(TSOut& SOut) const {
2165  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
2166  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
2167  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
2168  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
2169  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
2170  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
2171  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
2172  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut);
2173  VecOfIntVecVecsN.Save(SOut); VecOfIntVecVecsE.Save(SOut);
2174  SAttrN.Save(SOut); SAttrE.Save(SOut); }
2176  static PNEANet New() { return PNEANet(new TNEANet()); }
2178 
2180  static PNEANet New(const int& Nodes, const int& Edges) { return PNEANet(new TNEANet(Nodes, Edges)); }
2182  static PNEANet Load(TSIn& SIn) { return PNEANet(new TNEANet(SIn)); }
2184  static PNEANet Load_V1(TSIn& SIn) {
2185  PNEANet Graph = PNEANet(new TNEANet());
2186  Graph->MxNId.Load(SIn); Graph->MxEId.Load(SIn);
2187  Graph->NodeH.Load(SIn); Graph->EdgeH.Load(SIn);
2188  Graph->KeyToIndexTypeN.Load(SIn); Graph->KeyToIndexTypeE.Load(SIn);
2189  Graph->IntDefaultsN.Load(SIn); Graph->IntDefaultsE.Load(SIn);
2190  Graph->StrDefaultsN.Load(SIn); Graph->StrDefaultsE.Load(SIn);
2191  Graph->FltDefaultsN.Load(SIn); Graph->FltDefaultsE.Load(SIn);
2192  Graph->VecOfIntVecsN.Load(SIn); Graph->VecOfIntVecsE.Load(SIn);
2193  Graph->VecOfStrVecsN.Load(SIn); Graph->VecOfStrVecsE.Load(SIn);
2194  Graph->VecOfFltVecsN.Load(SIn); Graph->VecOfFltVecsE.Load(SIn);
2195  return Graph;
2196  }
2197 
2199  static PNEANet Load_V2(TSIn& SIn) {
2200  PNEANet Graph = PNEANet(new TNEANet());
2201  Graph->MxNId.Load(SIn); Graph->MxEId.Load(SIn);
2202  Graph->NodeH.Load(SIn); Graph->EdgeH.Load(SIn);
2203  Graph->KeyToIndexTypeN.Load(SIn); Graph->KeyToIndexTypeE.Load(SIn);
2204  Graph->IntDefaultsN.Load(SIn); Graph->IntDefaultsE.Load(SIn);
2205  Graph->StrDefaultsN.Load(SIn); Graph->StrDefaultsE.Load(SIn);
2206  Graph->FltDefaultsN.Load(SIn); Graph->FltDefaultsE.Load(SIn);
2207  Graph->VecOfIntVecsN.Load(SIn); Graph->VecOfIntVecsE.Load(SIn);
2208  Graph->VecOfStrVecsN.Load(SIn); Graph->VecOfStrVecsE.Load(SIn);
2209  Graph->VecOfFltVecsN.Load(SIn); Graph->VecOfFltVecsE.Load(SIn);
2210  Graph->VecOfIntVecVecsN.Load(SIn); Graph->VecOfIntVecVecsE.Load(SIn);
2211  Graph->SAttrN.Load(SIn); Graph->SAttrE.Load(SIn);
2212  return Graph;
2213  }
2214 
2216  void LoadNetworkShM(TShMIn& ShMIn);
2218 
2222  static PNEANet LoadShM(TShMIn& ShMIn) {
2223  TNEANet* Network = new TNEANet();
2224  Network->LoadNetworkShM(ShMIn);
2225  return PNEANet(Network);
2226  }
2227 
2229  TInt VecLength = VecOfIntVecVecsN.Len();
2231  if (VecLength != 0) {
2232  VecOfIntHashVecsN = TVec<THash<TInt, TIntV> >(VecLength);
2233  for (iter = KeyToIndexTypeN.BegI(); !iter.IsEnd(); iter=iter.Next()) {
2234  if (iter.GetDat().Val1 == IntVType) {
2235  TStr attribute = iter.GetKey();
2236  TInt index = iter.GetDat().Val2();
2237  for (int i=0; i<VecOfIntVecVecsN[index].Len(); i++) {
2238  if(VecOfIntVecVecsN[index][i].Len() > 0) {
2239  VecOfIntHashVecsN[index].AddDat(TInt(i), VecOfIntVecVecsN[index][i]);
2240  }
2241  }
2242  KeyToDenseN.AddDat(attribute, TBool(false));
2243  }
2244  }
2245  }
2246  VecOfIntVecVecsN.Clr();
2247 
2248  VecLength = VecOfIntVecVecsE.Len();
2249  if (VecLength != 0) {
2250  VecOfIntHashVecsE = TVec<THash<TInt, TIntV> >(VecLength);
2251  for (iter = KeyToIndexTypeE.BegI(); !iter.IsEnd(); iter=iter.Next()) {
2252  if (iter.GetDat().Val1 == IntVType) {
2253  TStr attribute = iter.GetKey();
2254  TInt index = iter.GetDat().Val2();
2255  for (int i=0; i<VecOfIntVecVecsE[index].Len(); i++) {
2256  if(VecOfIntVecVecsE[index][i].Len() > 0) {
2257  VecOfIntHashVecsE[index].AddDat(TInt(i), VecOfIntVecVecsE[index][i]);
2258  }
2259  }
2260  KeyToDenseE.AddDat(attribute, TBool(false));
2261  }
2262  }
2263  }
2264  VecOfIntVecVecsE.Clr();
2265  }
2266 
2267 
2269  bool HasFlag(const TGraphFlag& Flag) const;
2270 
2271  TNEANet& operator = (const TNEANet& Graph) { if (this!=&Graph) {
2272  MxNId=Graph.MxNId; MxEId=Graph.MxEId; NodeH=Graph.NodeH; EdgeH=Graph.EdgeH; }
2273  return *this; }
2274 
2276  int GetNodes() const { return NodeH.Len(); }
2278 
2282  int AddNode(int NId = -1);
2284 
2288  int AddNodeUnchecked(int NId = -1);
2290  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId()); }
2292 
2294  virtual void DelNode(const int& NId);
2296  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
2298  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
2300  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
2302  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
2304  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
2306  TAIntI BegNAIntI(const TStr& attr) const {
2307  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2309  TAIntI EndNAIntI(const TStr& attr) const {
2310  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2312  TAIntI GetNAIntI(const TStr& attr, const int& NId) const {
2313  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2314 
2316  TAIntVI BegNAIntVI(const TStr& attr) const {
2317  TVec<TIntV>::TIter HI = NULL;
2319  TInt location = CheckDenseOrSparseN(attr);
2320  TBool IsDense = true;
2321  if (location != -1) {
2322  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2323  if (location == 1) {
2324  HI = VecOfIntVecVecsN[index].BegI();
2325  } else {
2326  IsDense = false;
2327  HHI = VecOfIntHashVecsN[index].BegI();
2328  }
2329  }
2330  return TAIntVI(HI, HHI, attr, false, this, IsDense);
2331  }
2333  TAIntVI EndNAIntVI(const TStr& attr) const {
2334  TVec<TIntV>::TIter HI = NULL;
2336  TInt location = CheckDenseOrSparseN(attr);
2337  TBool IsDense = true;
2338  if (location != -1) {
2339  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2340  if (location == 1) {
2341  HI = VecOfIntVecVecsN[index].EndI();
2342  } else {
2343  IsDense = false;
2344  HHI = VecOfIntHashVecsN[index].EndI();
2345  }
2346  }
2347  return TAIntVI(HI, HHI, attr, false, this, IsDense);
2348  }
2349 
2350 
2352  TAIntVI GetNAIntVI(const TStr& attr, const int& NId) const {
2353  TVec<TIntV>::TIter HI = NULL;
2355  TInt location = CheckDenseOrSparseN(attr);
2356  TBool IsDense = true;
2357  if (location != -1) {
2358  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2359  if (location == 1) {
2360  HI = VecOfIntVecVecsN[index].GetI(NodeH.GetKeyId(NId));
2361  } else {
2362  IsDense = false;
2363  HHI = VecOfIntHashVecsN[index].GetI(NodeH.GetKeyId(NId));
2364  }
2365  }
2366  return TAIntVI(HI, HHI, attr, false, this, IsDense);
2367  }
2368 
2369 
2370 
2372  TAStrI BegNAStrI(const TStr& attr) const {
2373 
2374  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2376  TAStrI EndNAStrI(const TStr& attr) const {
2377  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2379  TAStrI GetNAStrI(const TStr& attr, const int& NId) const {
2380  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2382  TAFltI BegNAFltI(const TStr& attr) const {
2383  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2385  TAFltI EndNAFltI(const TStr& attr) const {
2386  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2388  TAFltI GetNAFltI(const TStr& attr, const int& NId) const {
2389  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2390 
2392  void AttrNameNI(const TInt& NId, TStrV& Names) const {
2393  AttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2394  void AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2396  void AttrValueNI(const TInt& NId, TStrV& Values) const {
2397  AttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2398  void AttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
2399 
2401  void IntAttrNameNI(const TInt& NId, TStrV& Names) const {
2402  IntAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2403  void IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2405  void IntAttrValueNI(const TInt& NId, TIntV& Values) const {
2406  IntAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2407  void IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const;
2408 
2409 
2411  void IntVAttrNameNI(const TInt& NId, TStrV& Names) const {
2412  IntVAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2413  void IntVAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2415  void IntVAttrValueNI(const TInt& NId, TVec<TIntV>& Values) const {
2416  IntVAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2417  void IntVAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TVec<TIntV>& Values) const;
2418 
2419 
2421  void StrAttrNameNI(const TInt& NId, TStrV& Names) const {
2422  StrAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2423  void StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2425  void StrAttrValueNI(const TInt& NId, TStrV& Values) const {
2426  StrAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2427  void StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
2429  void FltAttrNameNI(const TInt& NId, TStrV& Names) const {
2430  FltAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2431  void FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2433  void FltAttrValueNI(const TInt& NId, TFltV& Values) const {
2434  FltAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2435  void FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const;
2436 
2438  void AttrNameEI(const TInt& EId, TStrV& Names) const {
2439  AttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2440  void AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2442  void AttrValueEI(const TInt& EId, TStrV& Values) const {
2443  AttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2444  void AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
2446  void IntAttrNameEI(const TInt& EId, TStrV& Names) const {
2447  IntAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2448  void IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2450  void IntAttrValueEI(const TInt& EId, TIntV& Values) const {
2451  IntAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2452  void IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const;
2453 
2454 
2456  void IntVAttrNameEI(const TInt& EId, TStrV& Names) const {
2457  IntVAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2458  void IntVAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2460  void IntVAttrValueEI(const TInt& EId, TVec<TIntV>& Values) const {
2461  IntVAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2462  void IntVAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TVec<TIntV>& Values) const;
2463 
2464 
2466  void StrAttrNameEI(const TInt& EId, TStrV& Names) const {
2467  StrAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2468  void StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2470  void StrAttrValueEI(const TInt& EId, TStrV& Values) const {
2471  StrAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2472  void StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
2474  void FltAttrNameEI(const TInt& EId, TStrV& Names) const {
2475  FltAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2476  void FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2478  void FltAttrValueEI(const TInt& EId, TFltV& Values) const {
2479  FltAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2480  void FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const;
2481 
2483  TAIntI BegEAIntI(const TStr& attr) const {
2484  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2485  }
2487  TAIntI EndEAIntI(const TStr& attr) const {
2488  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2489  }
2491  TAIntI GetEAIntI(const TStr& attr, const int& EId) const {
2492  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2493  }
2494 
2496  TAIntVI BegEAIntVI(const TStr& attr) const {
2497  TVec<TIntV>::TIter HI = NULL;
2499  TInt location = CheckDenseOrSparseE(attr);
2500  TBool IsDense = true;
2501  if (location != -1) {
2502  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2503  if (location == 1) {
2504  HI = VecOfIntVecVecsE[index].BegI();
2505  } else {
2506  IsDense = false;
2507  HHI = VecOfIntHashVecsE[index].BegI();
2508  }
2509  }
2510  return TAIntVI(HI, HHI, attr, true, this, IsDense);
2511  }
2513  TAIntVI EndEAIntVI(const TStr& attr) const {
2514  TVec<TIntV>::TIter HI = NULL;
2516  TInt location = CheckDenseOrSparseE(attr);
2517  TBool IsDense = true;
2518  if (location != -1) {
2519  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2520  if (location == 1) {
2521  HI = VecOfIntVecVecsE[index].EndI();
2522  } else {
2523  IsDense = false;
2524  HHI = VecOfIntHashVecsE[index].EndI();
2525  }
2526  }
2527  return TAIntVI(HI, HHI, attr, true, this, IsDense);
2528  }
2530  TAIntVI GetEAIntVI(const TStr& attr, const int& EId) const {
2531  TVec<TIntV>::TIter HI = NULL;
2533  TInt location = CheckDenseOrSparseE(attr);
2534  TBool IsDense = true;
2535  if (location != -1) {
2536  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2537  if (location == 1) {
2538  HI = VecOfIntVecVecsE[index].GetI(EdgeH.GetKeyId(EId));
2539  } else {
2540  IsDense = false;
2541  HHI = VecOfIntHashVecsE[index].GetI(EdgeH.GetKeyId(EId));
2542  }
2543  }
2544  return TAIntVI(HI, HHI, attr, true, this, IsDense);
2545  }
2546 
2548  TAStrI BegEAStrI(const TStr& attr) const {
2549  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this); }
2551  TAStrI EndEAStrI(const TStr& attr) const {
2552  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2553  }
2555  TAStrI GetEAStrI(const TStr& attr, const int& EId) const {
2556  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2557  }
2559  TAFltI BegEAFltI(const TStr& attr) const {
2560  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2561  }
2563  TAFltI EndEAFltI(const TStr& attr) const {
2564  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2565  }
2567  TAFltI GetEAFltI(const TStr& attr, const int& EId) const {
2568  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2569  }
2571  int GetMxNId() const { return MxNId; }
2573  int GetMxEId() const { return MxEId; }
2574 
2576  int GetEdges() const { return EdgeH.Len(); }
2578 
2583  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
2585  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId()); }
2587  void DelEdge(const int& EId);
2589 
2593  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
2595  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
2597  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
2599  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
2601  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
2603  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
2605  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
2607  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
2609  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
2610 
2612  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
2614  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
2616  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
2618  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
2620  void GetNIdV(TIntV& NIdV) const;
2622  void GetEIdV(TIntV& EIdV) const;
2623 
2625  bool Empty() const { return GetNodes()==0; }
2627  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr();
2628  KeyToIndexTypeN.Clr(); KeyToIndexTypeE.Clr(); IntDefaultsN.Clr(); IntDefaultsE.Clr();
2629  StrDefaultsN.Clr(); StrDefaultsE.Clr(); FltDefaultsN.Clr(); FltDefaultsE.Clr();
2630  VecOfIntVecsN.Clr(); VecOfIntVecsE.Clr(); VecOfStrVecsN.Clr(); VecOfStrVecsE.Clr();
2631  VecOfFltVecsN.Clr(); VecOfFltVecsE.Clr(); VecOfIntVecVecsN.Clr(); VecOfIntVecVecsE.Clr();
2632  SAttrN.Clr(); SAttrE.Clr();}
2634  void Reserve(const int& Nodes, const int& Edges) {
2635  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
2637 
2642  void Defrag(const bool& OnlyNodeLinks=false);
2644 
2647  bool IsOk(const bool& ThrowExcept=true) const;
2649  void Dump(FILE *OutF=stdout) const;
2650 
2652 
2654  int AddIntAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return AddIntAttrDatN(NodeI.GetId(), value, attr); }
2655  int AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2657 
2659  int AddStrAttrDatN(const TNodeI& NodeI, const TStr& value, const TStr& attr) { return AddStrAttrDatN(NodeI.GetId(), value, attr); }
2660  int AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr);
2662 
2664  int AddFltAttrDatN(const TNodeI& NodeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatN(NodeI.GetId(), value, attr); }
2665  int AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr);
2667 
2669  int AddIntVAttrDatN(const TNodeI& NodeI, const TIntV& value, const TStr& attr) { return AddIntVAttrDatN(NodeI.GetId(), value, attr); }
2670  int AddIntVAttrDatN(const int& NId, const TIntV& value, const TStr& attr, TBool UseDense=true);
2672  int AppendIntVAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return AppendIntVAttrDatN(NodeI.GetId(), value, attr); }
2673  int AppendIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr, TBool UseDense=true);
2675  int DelFromIntVAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return DelFromIntVAttrDatN(NodeI.GetId(), value, attr); }
2676  int DelFromIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2678 
2680  int AddIntAttrDatE(const TEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AddIntAttrDatE(EdgeI.GetId(), value, attr); }
2681  int AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr);
2683 
2685  int AddStrAttrDatE(const TEdgeI& EdgeI, const TStr& value, const TStr& attr) { return AddStrAttrDatE(EdgeI.GetId(), value, attr); }
2686  int AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr);
2688 
2690  int AddFltAttrDatE(const TEdgeI& EdgeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatE(EdgeI.GetId(), value, attr); }
2691  int AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr);
2693 
2695  int AddIntVAttrDatE(const TEdgeI& EdgeI, const TIntV& value, const TStr& attr) { return AddIntVAttrDatE(EdgeI.GetId(), value, attr); }
2696  int AddIntVAttrDatE(const int& EId, const TIntV& value, const TStr& attr, TBool UseDense=true);
2698  int AppendIntVAttrDatE(const TEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AppendIntVAttrDatE(EdgeI.GetId(), value, attr); }
2699  int AppendIntVAttrDatE(const int& EId, const TInt& value, const TStr& attr, TBool UseDense=true);
2701  TInt GetIntAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetIntAttrDatN(NodeI.GetId(), attr); }
2702  TInt GetIntAttrDatN(const int& NId, const TStr& attr);
2703 
2705  TStr GetStrAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetStrAttrDatN(NodeI.GetId(), attr); }
2706  TStr GetStrAttrDatN(const int& NId, const TStr& attr);
2708  TFlt GetFltAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetFltAttrDatN(NodeI.GetId(), attr); }
2709  TFlt GetFltAttrDatN(const int& NId, const TStr& attr);
2711  TIntV GetIntVAttrDatN(const TNodeI& NodeI, const TStr& attr) const { return GetIntVAttrDatN(NodeI.GetId(), attr); }
2712  TIntV GetIntVAttrDatN(const int& NId, const TStr& attr) const;
2713 
2715  int GetIntAttrIndN(const TStr& attr);
2717  int GetAttrIndN(const TStr& attr);
2718 
2720  TInt GetIntAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetIntAttrIndDatN(NodeI.GetId(), index); }
2722  TInt GetIntAttrIndDatN(const int& NId, const int& index);
2723 
2725  TStr GetStrAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetStrAttrIndDatN(NodeI.GetId(), index); }
2727  TStr GetStrAttrIndDatN(const int& NId, const int& index);
2728 
2730  TFlt GetFltAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetFltAttrIndDatN(NodeI.GetId(), index); }
2732  TFlt GetFltAttrIndDatN(const int& NId, const int& index);
2733 
2735  TInt GetIntAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetIntAttrDatE(EdgeI.GetId(), attr); }
2736  TInt GetIntAttrDatE(const int& EId, const TStr& attr);
2738  TStr GetStrAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetStrAttrDatE(EdgeI.GetId(), attr); }
2739  TStr GetStrAttrDatE(const int& EId, const TStr& attr);
2741  TFlt GetFltAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetFltAttrDatE(EdgeI.GetId(), attr); }
2742  TFlt GetFltAttrDatE(const int& EId, const TStr& attr);
2744  TIntV GetIntVAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetIntVAttrDatE(EdgeI.GetId(), attr); }
2745  TIntV GetIntVAttrDatE(const int& EId, const TStr& attr);
2746 
2748  int GetIntAttrIndE(const TStr& attr);
2750  int GetAttrIndE(const TStr& attr);
2751 
2753  TInt GetIntAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetIntAttrIndDatE(EdgeI.GetId(), index); }
2755  TInt GetIntAttrIndDatE(const int& EId, const int& index);
2756 
2758  TFlt GetFltAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetFltAttrIndDatE(EdgeI.GetId(), index); }
2760  TFlt GetFltAttrIndDatE(const int& EId, const int& index);
2761 
2763  TStr GetStrAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetStrAttrIndDatE(EdgeI.GetId(), index); }
2765  TStr GetStrAttrIndDatE(const int& EId, const int& index);
2766 
2768  int DelAttrDatN(const TNodeI& NodeI, const TStr& attr) { return DelAttrDatN(NodeI.GetId(), attr); }
2769  int DelAttrDatN(const int& NId, const TStr& attr);
2771  int DelAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return DelAttrDatE(EdgeI.GetId(), attr); }
2772  int DelAttrDatE(const int& EId, const TStr& attr);
2773 
2775  int AddIntAttrN(const TStr& attr, TInt defaultValue=TInt::Mn);
2777  int AddStrAttrN(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
2779  int AddFltAttrN(const TStr& attr, TFlt defaultValue=TFlt::Mn);
2781  int AddIntVAttrN(const TStr& attr, TBool UseDense=true);
2782 
2784  int AddIntAttrE(const TStr& attr, TInt defaultValue=TInt::Mn);
2786  int AddStrAttrE(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
2788  int AddFltAttrE(const TStr& attr, TFlt defaultValue=TFlt::Mn);
2790  int AddIntVAttrE(const TStr& attr, TBool UseDense=true);
2791 
2793  int DelAttrN(const TStr& attr);
2795  int DelAttrE(const TStr& attr);
2796 
2798  bool IsAttrDeletedN(const int& NId, const TStr& attr) const;
2800  bool IsIntAttrDeletedN(const int& NId, const TStr& attr) const;
2802  bool IsIntVAttrDeletedN(const int& NId, const TStr& attr) const;
2804  bool IsStrAttrDeletedN(const int& NId, const TStr& attr) const;
2806  bool IsFltAttrDeletedN(const int& NId, const TStr& attr) const;
2807 
2809  bool NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2811  bool NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2813  bool NodeAttrIsIntVDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2815  bool NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2817  bool NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2818 
2820  bool IsAttrDeletedE(const int& EId, const TStr& attr) const;
2822  bool IsIntAttrDeletedE(const int& EId, const TStr& attr) const;
2824  bool IsIntVAttrDeletedE(const int& EId, const TStr& attr) const;
2826  bool IsStrAttrDeletedE(const int& EId, const TStr& attr) const;
2828  bool IsFltAttrDeletedE(const int& EId, const TStr& attr) const;
2829 
2831  bool EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2833  bool EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2835  bool EdgeAttrIsIntVDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2837  bool EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2839  bool EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2840 
2842  TStr GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2844  TStr GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2845 
2847  TFlt GetWeightOutEdges(const TNodeI& NI, const TStr& attr);
2849  bool IsFltAttrE(const TStr& attr);
2851  bool IsIntAttrE(const TStr& attr);
2853  bool IsStrAttrE(const TStr& attr);
2855  TVec<TFlt>& GetFltAttrVecE(const TStr& attr);
2857  int GetFltKeyIdE(const int& EId);
2858 
2860  void GetWeightOutEdgesV(TFltV& OutWeights, const TFltV& AttrVal) ;
2862  void GetAttrNNames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const;
2864  void GetAttrENames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const;
2865 
2866 
2868  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
2870  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
2871 
2873  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
2874  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
2875  }
2877  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
2878  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
2879  }
2880 
2882  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
2884  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
2885 
2887  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
2888  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
2889  }
2891  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
2892  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
2893  }
2894 
2896  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
2898  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
2899 
2901  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
2902  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
2903  }
2905  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
2906  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
2907  }
2908 
2910  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
2912  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
2913 
2915  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
2916  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
2917  }
2919  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
2920  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
2921  }
2922 
2924  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
2926  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
2927 
2929  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
2930  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
2931  }
2933  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
2934  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
2935  }
2936 
2938  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
2940  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
2941 
2943  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
2944  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
2945  }
2947  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
2948  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
2949  }
2950 
2952  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
2954  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
2955 
2957  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
2958  return DelSAttrDatN(NodeI.GetId(), AttrName);
2959  }
2961  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
2962  return DelSAttrDatN(NodeI.GetId(), AttrId);
2963  }
2964 
2966  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
2968  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
2969  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
2970  }
2971 
2973  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
2975  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
2976 
2978  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
2979 
2981  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
2983  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
2984 
2986  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TInt& Val);
2988  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TInt& Val);
2989 
2991  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
2992  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
2993  }
2995  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
2996  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
2997  }
2998 
3000  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TFlt& Val);
3002  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TFlt& Val);
3003 
3005  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
3006  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
3007  }
3009  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
3010  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
3011  }
3012 
3014  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TStr& Val);
3016  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TStr& Val);
3017 
3019  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
3020  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
3021  }
3023  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
3024  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
3025  }
3026 
3028  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TInt& ValX) const;
3030  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TInt& ValX) const;
3031 
3033  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
3034  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
3035  }
3037  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
3038  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
3039  }
3040 
3042  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TFlt& ValX) const;
3044  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TFlt& ValX) const;
3045 
3047  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
3048  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
3049  }
3051  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
3052  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
3053  }
3054 
3056  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TStr& ValX) const;
3058  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TStr& ValX) const;
3059 
3061  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
3062  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
3063  }
3065  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
3066  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
3067  }
3068 
3070  int DelSAttrDatE(const TInt& EId, const TStr& AttrName);
3072  int DelSAttrDatE(const TInt& EId, const TInt& AttrId);
3073 
3075  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
3076  return DelSAttrDatE(EdgeI.GetId(), AttrName);
3077  }
3079  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
3080  return DelSAttrDatE(EdgeI.GetId(), AttrId);
3081  }
3083  int GetSAttrVE(const TInt& EId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3085  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3086  return GetSAttrVE(EdgeI.GetId(), AttrType, AttrV);
3087  }
3088 
3090  int GetIdVSAttrE(const TStr& AttrName, TIntV& IdV) const;
3092  int GetIdVSAttrE(const TInt& AttrId, TIntV& IdV) const;
3093 
3095  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3096 
3098  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3100  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3101 
3103 
3107  static PNEANet GetSmallGraph();
3108  friend class TPt<TNEANet>;
3109 };
3110 
3111 // set flags
3112 namespace TSnap {
3113 template <> struct IsMultiGraph<TNEANet> { enum { Val = 1 }; };
3114 template <> struct IsDirected<TNEANet> { enum { Val = 1 }; };
3115 }
3116 
3117  //#//////////////////////////////////////////////
3119 
3121 
3123 typedef TPt<TUndirNet> PUndirNet;
3124 
3125 //#//////////////////////////////////////////////
3127 class TDirNet;
3128 
3130 typedef TPt<TDirNet> PDirNet;
3131 
3132 //#//////////////////////////////////////////////
3134 
3145 class TUndirNet {
3146 public:
3147  typedef TUndirNet TNet;
3149 public:
3150  class TNode {
3151  private:
3154  public:
3155  TNode() : Id(-1), NIdV() { }
3156  TNode(const int& NId) : Id(NId), NIdV() { }
3157  TNode(const TNode& Node) : Id(Node.Id), NIdV(Node.NIdV) { }
3158  TNode(TSIn& SIn) : Id(SIn), NIdV(SIn) { }
3159  void Save(TSOut& SOut) const { Id.Save(SOut); NIdV.Save(SOut); }
3160  int GetId() const { return Id; }
3161  int GetDeg() const { return NIdV.Len(); }
3162  int GetInDeg() const { return GetDeg(); }
3163  int GetOutDeg() const { return GetDeg(); }
3164  int GetInNId(const int& NodeN) const { return GetNbrNId(NodeN); }
3165  int GetOutNId(const int& NodeN) const { return GetNbrNId(NodeN); }
3166  int GetNbrNId(const int& NodeN) const { return NIdV[NodeN]; }
3167  bool IsNbrNId(const int& NId) const { return NIdV.SearchBin(NId)!=-1; }
3168  bool IsInNId(const int& NId) const { return IsNbrNId(NId); }
3169  bool IsOutNId(const int& NId) const { return IsNbrNId(NId); }
3170  void PackOutNIdV() { NIdV.Pack(); }
3171  void PackNIdV() { NIdV.Pack(); }
3172  void SortNIdV() { NIdV.Sort();}
3173  void LoadShM(TShMIn& MStream) {
3174  Id = TInt(MStream);
3175  NIdV.LoadShM(MStream);
3176  }
3177  friend class TUndirNet;
3178  friend class TUndirNetMtx;
3179  };
3181  class TNodeI {
3182  private:
3185  public:
3186  TNodeI() : NodeHI() { }
3187  TNodeI(const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
3188  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI) { }
3189  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; return *this; }
3190 
3192  TNodeI& operator++ (int) { NodeHI++; return *this; }
3194  TNodeI& operator-- (int) { NodeHI--; return *this; }
3195 
3196 
3197  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
3198  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
3199 
3201  int GetId() const { return NodeHI.GetDat().GetId(); }
3203  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
3205  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
3207  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
3209  void SortNIdV() { NodeHI.GetDat().SortNIdV(); }
3211 
3214  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
3216 
3219  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
3221 
3224  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
3226  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
3228  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
3230  bool IsNbrNId(const int& NId) const { return NodeHI.GetDat().IsNbrNId(NId); }
3231  friend class TUndirNet;
3232  };
3234  class TEdgeI {
3235  private:
3236  TNodeI CurNode, EndNode;
3237  int CurEdge;
3238  public:
3239  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
3240  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
3241  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
3242  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
3244  TEdgeI& operator++ (int) { do { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++; while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } } while (CurNode < EndNode && GetSrcNId()>GetDstNId()); return *this; }
3245  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
3246  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
3248  int GetId() const { return -1; }
3250  int GetSrcNId() const { return CurNode.GetId(); }
3252  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
3253  friend class TUndirNet;
3254  };
3255 private:
3259 
3262 private:
3263  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
3264  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
3265  TIntPr OrderEdgeNodes(const int& SrcNId, const int& DstNId) const;
3266 private:
3268  public:
3270  void operator() (TNode* n, TShMIn& ShMIn) {n->LoadShM(ShMIn);}
3271  };
3272 private:
3273  void LoadNetworkShM(TShMIn& ShMIn) {
3274  MxNId = TInt(ShMIn);
3275  NEdges = TInt(ShMIn);
3276  LoadTNodeFunctor NodeFn;
3277  NodeH.LoadShM(ShMIn, NodeFn);
3278  SAttrN.Load(ShMIn);
3279  SAttrE = TAttrPair(ShMIn);
3280  }
3281 public:
3282  TUndirNet() : CRef(), MxNId(0), NEdges(0), NodeH(), SAttrN(), SAttrE() { }
3284  explicit TUndirNet(const int& Nodes, const int& Edges) : MxNId(0), NEdges(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
3285  TUndirNet(const TUndirNet& Graph) : MxNId(Graph.MxNId), NEdges(Graph.NEdges), NodeH(Graph.NodeH),
3286  SAttrN(), SAttrE() { }
3288  TUndirNet(TSIn& SIn) : MxNId(SIn), NEdges(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
3290  void Save(TSOut& SOut) const { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut);
3291  SAttrN.Save(SOut); SAttrE.Save(SOut); }
3293  void Save_V1(TSOut& SOut) const { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut); }
3295  static PUndirNet New() { return new TUndirNet(); }
3297 
3299  static PUndirNet New(const int& Nodes, const int& Edges) { return new TUndirNet(Nodes, Edges); }
3301  static PUndirNet Load(TSIn& SIn) { return PUndirNet(new TUndirNet(SIn)); }
3303  static PUndirNet Load_V1(TSIn& SIn) { PUndirNet Graph = PUndirNet(new TUndirNet());
3304  Graph->MxNId.Load(SIn); Graph->NEdges.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
3305  }
3306 
3308 
3312  static PUndirNet LoadShM(TShMIn& ShMIn) {
3313  TUndirNet* Network = new TUndirNet();
3314  Network->LoadNetworkShM(ShMIn);
3315  return PUndirNet(Network);
3316  }
3317 
3319  bool HasFlag(const TGraphFlag& Flag) const;
3321  if (this!=&Graph) { MxNId=Graph.MxNId; NEdges=Graph.NEdges; NodeH=Graph.NodeH; } return *this; }
3322 
3324  int GetNodes() const { return NodeH.Len(); }
3326 
3330  int AddNode(int NId = -1);
3332 
3336  int AddNodeUnchecked(int NId = -1);
3338  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId()); }
3340 
3349  int AddNode(const int& NId, const TIntV& NbrNIdV);
3351 
3360  int AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& NIdVId);
3362 
3364  void DelNode(const int& NId);
3366  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
3368  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
3370  TNodeI BegNI() const { return TNodeI(NodeH.BegI()); }
3372  TNodeI EndNI() const { return TNodeI(NodeH.EndI()); }
3374  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId)); }
3376  int GetMxNId() const { return MxNId; }
3377 
3379  int GetEdges() const;
3381 
3387  int AddEdge(const int& SrcNId, const int& DstNId);
3389 
3396  int AddEdgeUnchecked(const int& SrcNId, const int& DstNId);
3398  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
3400 
3404  void DelEdge(const int& SrcNId, const int& DstNId);
3406  bool IsEdge(const int& SrcNId, const int& DstNId) const;
3408  TEdgeI BegEI() const { TNodeI NI = BegNI(); TEdgeI EI(NI, EndNI(), 0); if (GetNodes() != 0 && (NI.GetOutDeg()==0 || NI.GetId()>NI.GetOutNId(0))) { EI++; } return EI; }
3410  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
3412  TEdgeI GetEI(const int& EId) const;
3414 
3417  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
3418 
3420  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
3422  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
3424  void GetNIdV(TIntV& NIdV) const;
3425 
3427  bool Empty() const { return GetNodes()==0; }
3429  void Clr() { MxNId=0; NEdges=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
3431  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) NodeH.Gen(Nodes/2); }
3433  void ReserveNIdDeg(const int& NId, const int& Deg) { GetNode(NId).NIdV.Reserve(Deg); }
3435  void SortNodeAdjV() { for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { NI.SortNIdV();} }
3437 
3442  void Defrag(const bool& OnlyNodeLinks=false);
3444 
3447  bool IsOk(const bool& ThrowExcept=true) const;
3449  void Dump(FILE *OutF=stdout) const;
3451 
3457  static PUndirNet GetSmallGraph();
3458 
3460  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
3462  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
3463 
3465  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
3466  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3467  }
3469  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
3470  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3471  }
3472 
3474  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
3476  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
3477 
3479  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
3480  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3481  }
3483  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
3484  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3485  }
3486 
3488  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
3490  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
3491 
3493  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
3494  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3495  }
3497  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
3498  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3499  }
3500 
3502  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
3504  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
3505 
3507  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
3508  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3509  }
3511  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
3512  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3513  }
3514 
3516  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
3518  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
3519 
3521  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
3522  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3523  }
3525  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
3526  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3527  }
3528 
3530  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
3532  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
3533 
3535  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
3536  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3537  }
3539  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
3540  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3541  }
3542 
3544  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
3546  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
3547 
3549  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
3550  return DelSAttrDatN(NodeI.GetId(), AttrName);
3551  }
3553  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
3554  return DelSAttrDatN(NodeI.GetId(), AttrId);
3555  }
3556 
3558  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3560  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3561  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3562  }
3563 
3565  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
3567  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
3568 
3570  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3571 
3573  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3575  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3576 
3578  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val);
3580  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val);
3581 
3583  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
3584  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3585  }
3587  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
3588  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3589  }
3590 
3592  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val);
3594  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val);
3595 
3597  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
3598  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3599  }
3601  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
3602  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3603  }
3604 
3606  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val);
3608  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val);
3609 
3611  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
3612  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3613  }
3615  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
3616  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3617  }
3618 
3620  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& ValX) const;
3622  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& ValX) const;
3623 
3625  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
3626  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3627  }
3629  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
3630  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3631  }
3632 
3634  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& ValX) const;
3636  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& ValX) const;
3637 
3639  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
3640  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3641  }
3643  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
3644  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3645  }
3646 
3648  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& ValX) const;
3650  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& ValX) const;
3651 
3653  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
3654  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3655  }
3657  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
3658  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3659  }
3660 
3662  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName);
3664  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId);
3665 
3667  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
3668  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
3669  }
3671  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
3672  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
3673  }
3675  int GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3677  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3678  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
3679  }
3680 
3682  int GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const;
3684  int GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const;
3685 
3687  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3688 
3690  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3692  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3693 
3694  friend class TUndirNetMtx;
3695  friend class TPt<TUndirNet>;
3696 };
3697 
3698 //#//////////////////////////////////////////////
3700 
3714 class TDirNet {
3715 public:
3716  typedef TDirNet TNet;
3718 public:
3719  class TNode {
3720  private:
3722  TIntV InNIdV, OutNIdV;
3723  public:
3724  TNode() : Id(-1), InNIdV(), OutNIdV() { }
3725  TNode(const int& NId) : Id(NId), InNIdV(), OutNIdV() { }
3726  TNode(const TNode& Node) : Id(Node.Id), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
3727  TNode(TSIn& SIn) : Id(SIn), InNIdV(SIn), OutNIdV(SIn) { }
3728  void Save(TSOut& SOut) const { Id.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
3729  int GetId() const { return Id; }
3730  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
3731  int GetInDeg() const { return InNIdV.Len(); }
3732  int GetOutDeg() const { return OutNIdV.Len(); }
3733  int GetInNId(const int& NodeN) const { return InNIdV[NodeN]; }
3734  int GetOutNId(const int& NodeN) const { return OutNIdV[NodeN]; }
3735  int GetNbrNId(const int& NodeN) const { return NodeN<GetOutDeg()?GetOutNId(NodeN):GetInNId(NodeN-GetOutDeg()); }
3736  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId) != -1; }
3737  bool IsOutNId(const int& NId) const { return OutNIdV.SearchBin(NId) != -1; }
3738  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
3739  void PackOutNIdV() { OutNIdV.Pack(); }
3740  void PackNIdV() { InNIdV.Pack(); }
3741  void SortNIdV() { InNIdV.Sort(); OutNIdV.Sort();}
3742  void LoadShM(TShMIn& MStream) {
3743  Id = TInt(MStream);
3744  InNIdV.LoadShM(MStream);
3745  OutNIdV.LoadShM(MStream);
3746  }
3747  friend class TDirNet;
3748  friend class TDirNetMtx;
3749  };
3751  class TNodeI {
3752  private:
3755  public:
3756  TNodeI() : NodeHI() { }
3757  TNodeI(const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
3758  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI) { }
3759  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; return *this; }
3761  TNodeI& operator++ (int) { NodeHI++; return *this; }
3763  TNodeI& operator-- (int) { NodeHI--; return *this; }
3764 
3765  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
3766  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
3768  int GetId() const { return NodeHI.GetDat().GetId(); }
3770  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
3772  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
3774  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
3776  void SortNIdV() { NodeHI.GetDat().SortNIdV(); }
3778 
3780  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
3782 
3784  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
3786 
3788  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
3790  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
3792  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
3794  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
3795  friend class TDirNet;
3796  };
3798  class TEdgeI {
3799  private:
3800  TNodeI CurNode, EndNode;
3801  int CurEdge;
3802  public:
3803  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
3804  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
3805  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
3806  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
3808  TEdgeI& operator++ (int) { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
3809  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
3810  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
3811  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
3813  int GetId() const { return -1; }
3815  int GetSrcNId() const { return CurNode.GetId(); }
3817  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
3818  friend class TDirNet;
3819  };
3820 private:
3826 private:
3827  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
3828  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
3829 private:
3831  public:
3833  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
3834  };
3835 private:
3836  void LoadNetworkShM(TShMIn& ShMIn) {
3837  MxNId = TInt(ShMIn);
3838  TNodeFunctor f;
3839  NodeH.LoadShM(ShMIn, f);
3840  SAttrN.Load(ShMIn);
3841  SAttrE = TAttrPair(ShMIn);
3842  }
3843 public:
3844  TDirNet() : CRef(), MxNId(0), NodeH(), SAttrN(), SAttrE() { }
3846  explicit TDirNet(const int& Nodes, const int& Edges) : MxNId(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
3847  TDirNet(const TDirNet& Graph) : MxNId(Graph.MxNId), NodeH(Graph.NodeH), SAttrN(), SAttrE() { }
3849  TDirNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
3851  void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); SAttrN.Save(SOut); SAttrE.Save(SOut); }
3853  void Save_V1(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
3855  static PDirNet New() { return new TDirNet(); }
3857 
3859  static PDirNet New(const int& Nodes, const int& Edges) { return new TDirNet(Nodes, Edges); }
3861  static PDirNet Load(TSIn& SIn) { return PDirNet(new TDirNet(SIn)); }
3863  static PDirNet Load_V1(TSIn& SIn) { PDirNet Graph = PDirNet(new TDirNet());
3864  Graph->MxNId.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
3865  }
3867 
3871  static PDirNet LoadShM(TShMIn& ShMIn) {
3872  TDirNet* Network = new TDirNet();
3873  Network->LoadNetworkShM(ShMIn);
3874  return PDirNet(Network);
3875  }
3877  bool HasFlag(const TGraphFlag& Flag) const;
3878  TDirNet& operator = (const TDirNet& Graph) {
3879  if (this!=&Graph) { MxNId=Graph.MxNId; NodeH=Graph.NodeH; } return *this; }
3880 
3882  int GetNodes() const { return NodeH.Len(); }
3884 
3888  int AddNode(int NId = -1);
3890 
3894  int AddNodeUnchecked(int NId = -1);
3896  int AddNode(const TNodeI& NodeId) { return AddNode(NodeId.GetId()); }
3898 
3908  int AddNode(const int& NId, const TIntV& InNIdV, const TIntV& OutNIdV);
3910 
3919  int AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& SrcVId, const int& DstVId);
3921 
3923  void DelNode(const int& NId);
3925  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
3927  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
3929  TNodeI BegNI() const { return TNodeI(NodeH.BegI()); }
3931  TNodeI EndNI() const { return TNodeI(NodeH.EndI()); }
3933  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId)); }
3934  // GetNodeC() has been commented out. It was a quick shortcut, do not use.
3935  //const TNode& GetNodeC(const int& NId) const { return NodeH.GetDat(NId); }
3937  int GetMxNId() const { return MxNId; }
3938 
3940  int GetEdges() const;
3942 
3948  int AddEdge(const int& SrcNId, const int& DstNId);
3950 
3957  int AddEdgeUnchecked(const int& SrcNId, const int& DstNId);
3958  // Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
3959  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
3961 
3965  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
3967  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
3969  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0){NI++;} return TEdgeI(NI, EndNI()); }
3971  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
3973  TEdgeI GetEI(const int& EId) const; // not supported
3975  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
3976 
3978  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
3980  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
3982  void GetNIdV(TIntV& NIdV) const;
3983 
3985  bool Empty() const { return GetNodes()==0; }
3987  void Clr() { MxNId=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
3989  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
3991  void ReserveNIdInDeg(const int& NId, const int& InDeg) { GetNode(NId).InNIdV.Reserve(InDeg); }
3993  void ReserveNIdOutDeg(const int& NId, const int& OutDeg) { GetNode(NId).OutNIdV.Reserve(OutDeg); }
3995  void SortNodeAdjV() { for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { NI.SortNIdV();} }
3997 
4002  void Defrag(const bool& OnlyNodeLinks=false);
4004 
4007  bool IsOk(const bool& ThrowExcept=true) const;
4009  void Dump(FILE *OutF=stdout) const;
4011 
4015  static PDirNet GetSmallGraph();
4016 
4018  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
4020  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
4021 
4023  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
4024  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
4025  }
4027  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
4028  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
4029  }
4030 
4032  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
4034  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
4035 
4037  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
4038  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
4039  }
4041  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
4042  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
4043  }
4044 
4046  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
4048  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
4049 
4051  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
4052  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
4053  }
4055  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
4056  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
4057  }
4058 
4060  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
4062  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
4063 
4065  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
4066  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
4067  }
4069  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
4070  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
4071  }
4072 
4074  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
4076  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
4077 
4079  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
4080  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
4081  }
4083  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
4084  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
4085  }
4086 
4088  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
4090  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
4091 
4093  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
4094  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
4095  }
4097  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
4098  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
4099  }
4100 
4102  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
4104  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
4105 
4107  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
4108  return DelSAttrDatN(NodeI.GetId(), AttrName);
4109  }
4111  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
4112  return DelSAttrDatN(NodeI.GetId(), AttrId);
4113  }
4114 
4116  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
4118  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
4119  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
4120  }
4121 
4123  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
4125  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
4126 
4128  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
4129 
4131  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
4133  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
4134 
4136  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val);
4138  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val);
4139 
4141  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
4142  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
4143  }
4145  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
4146  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
4147  }
4148 
4150  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val);
4152  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val);
4153 
4155  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
4156  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
4157  }
4159  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
4160  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
4161  }
4162 
4164  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val);
4166  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val);
4167 
4169  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
4170  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
4171  }
4173  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
4174  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
4175  }
4176 
4178  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& ValX) const;
4180  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& ValX) const;
4181 
4183  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
4184  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
4185  }
4187  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
4188  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
4189  }
4190 
4192  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& ValX) const;
4194  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& ValX) const;
4195 
4197  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
4198  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
4199  }
4201  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
4202  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
4203  }
4204 
4206  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& ValX) const;
4208  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& ValX) const;
4209 
4211  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
4212  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
4213  }
4215  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
4216  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
4217  }
4218 
4220  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName);
4222  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId);
4223 
4225  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
4226  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
4227  }
4229  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
4230  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
4231  }
4233  int GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const;
4235  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
4236  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
4237  }
4238 
4240  int GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const;
4242  int GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const;
4243 
4245  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
4246 
4248  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
4250  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
4251 
4252  friend class TPt<TDirNet>;
4253  friend class TDirNetMtx;
4254 };
4255 
4256 // set flags
4257 namespace TSnap {
4258 template <> struct IsDirected<TDirNet> { enum { Val = 1 }; };
4259 }
4260 #endif // NETWORK_H
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.h:1495
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
Definition: network.h:4235
int GetNbrEId(const int &EdgeN) const
Definition: network.h:1102
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
Definition: network.h:247
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:3971
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:708
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:1268
Definition: bd.h:440
TEdgeDat & GetOutEDat(const int &EdgeN)
Definition: network.h:1211
#define IAssert(Cond)
Definition: bd.h:262
static int GetNIdPos(const TVec< TPair< TInt, TEdgeData > > &NIdV, const int &NId)
Definition: network.h:823
TVec< TIntV > VecOfIntVecsN
Definition: network.h:2038
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:2873
TNEANet(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
Definition: network.h:2118
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:1831
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:4197
TInt MxEId
Definition: network.h:1258
TNodeData TNodeDat
Definition: network.h:1076
TEdgeI(const THashIter &EdgeHIter, const TNodeEdgeNet *NetPt)
Definition: network.h:1226
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:548
THash< TStr, TBool > KeyToDenseE
Definition: network.h:2033
TNodeNet(const TNodeNet &NodeNet)
Definition: network.h:163
TEdgeI & operator++(int)
Definition: network.h:1229
TNodeI(const THashIter &NodeHIter, const TNodeNet *NetPt)
Definition: network.h:65
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TNodeData & GetDat()
Definition: network.h:517
Tests (at compile time) if the graph is a network with data on nodes.
Definition: gbase.h:32
TEdge(const TEdge &Edge)
Definition: network.h:1123
void IntVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2411
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:4225
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3989
TNodeData & GetOutNDat(const int &EdgeN)
Definition: network.h:1192
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1928
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2701
bool IsOutNId(const int &NId) const
Definition: network.h:45
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:3521
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
Definition: network.h:2612
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1212
int GetDeg() const
Returns degree of the current node.
Definition: network.h:3203
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:1421
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:595
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: network.h:1197
const TNodeData & GetInNDat(const int &EdgeN) const
Definition: network.h:1189
int GetId() const
Definition: network.h:1781
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: network.h:1201
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
Definition: network.h:3295
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2276
TPt< TIntNEDNet > PIntNEDNet
Definition: network.h:1065
const TEdgeDat & GetOutEDat(const int &EdgeN) const
Definition: network.h:1212
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:4069
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:1539
bool IsKeyIdEqKeyN() const
Definition: hash.h:233
TPt< TIntFltNEDNet > PIntFltNEDNet
Definition: network.h:1067
void SortEIdByDat(const bool &Asc=true)
Sorts edges by edge data.
Definition: network.h:1432
void LoadShM(TShMIn &MStream)
Definition: network.h:3173
THash< TInt, TNode >::TIter THashIter
Definition: network.h:3753
#define IAssertR(Cond, Reason)
Definition: bd.h:265
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Definition: network.h:1172
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:153
int GetSrcNId() const
Definition: network.h:1782
TNodeData TNodeDat
Definition: network.h:19
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
TNode(TSIn &SIn)
Definition: network.h:1091
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
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:659
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:3587
int GetDeg() const
Returns degree of the current node.
Definition: network.h:76
int AddFltAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2690
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:3228
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:1089
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Definition: network.h:1821
int GetDeg() const
Definition: network.h:36
TDirNet(const TDirNet &Graph)
Definition: network.h:3847
TNode & GetNode(const int &NId)
Definition: network.h:139
TAStrI GetNAStrI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2379
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
Definition: network.h:3853
THash< TInt, TNode > NodeH
Definition: network.h:3258
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:1813
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:119
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:3507
enum TAttrType_ TAttrType
Types for tables, sparse and dense attributes.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:1389
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:1348
const TNodeData & GetDat() const
Definition: network.h:516
TNode(TSIn &SIn)
Definition: network.h:3158
TVec< TStrV > VecOfStrVecsE
Definition: network.h:2039
TCRef CRef
Definition: network.h:635
THash< TStr, TInt > IntDefaultsE
Definition: network.h:2035
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: network.h:1168
void Save(TSOut &SOut) const
Definition: network.h:1092
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:4083
TNodeEDatNet & operator=(const TNodeEDatNet &NodeNet)
Definition: network.h:676
TCRef CRef
Definition: network.h:3821
const TNodeData & operator()() const
Definition: network.h:579
void Save(TSOut &SOut) const
Definition: network.h:1755
void Save_V1(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Available for backwards compatibility. ...
Definition: network.h:2154
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
Definition: network.h:700
TNode(const TNode &Node)
Definition: network.h:3157
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3927
TNode & GetNode(const int &NId)
Definition: network.h:3827
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:3813
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:4211
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:563
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
Definition: network.h:1372
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the network is undirecte...
Definition: network.h:3207
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:3079
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:4079
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:1426
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:273
int GetInNId(const int &NodeN) const
Definition: network.h:41
int GetInNId(const int &NodeN) const
Definition: network.h:3164
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1423
TEdgeI GetEI(const int &EId) const
Returns an iterator referring to edge with edge ID EId.
Definition: network.h:2607
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:878
TNodeData & GetDat()
Definition: network.h:1188
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:2991
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:898
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.h:390
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
Definition: network.h:2585
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:3511
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:125
Definition: dt.h:11
void SortNIdV()
Sorts the adjacency lists of the current node.
Definition: network.h:3776
TAFltI & operator++(int)
Definition: network.h:2000
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
Definition: network.h:225
Definition: attr.h:98
bool IsNbrEId(const int &EId) const
Definition: network.h:1105
TEdgeI(const THashIter &EdgeHIter, const TNEANet *GraphPt)
Definition: network.h:1874
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.h:848
TPt< TStrIntNEDNet > PStrIntNEDNet
Definition: network.h:1069
THash< TInt, TNode >::TIter THashIter
Definition: network.h:539
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:720
int AddEdge(const TEdgeI &EdgeI)
Definition: network.h:3959
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
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:758
THashIter EdgeHI
Definition: network.h:1222
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 GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
Definition: network.h:3677
int GetOutNId(const int &NodeN) const
Definition: network.h:3734
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:282
TNodeData & GetOutNDat(const int &NodeN)
Definition: network.h:106
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:3224
TStrVecIter HI
Definition: network.h:1962
void GetNIdV(TIntV &NIdV) const
Returns a vector of all node IDs in the network.
Definition: network.h:1634
const TNodeData & GetDat() const
Definition: network.h:39
int GetId() const
Returns ID of the current node.
Definition: network.h:3201
void Save(TSOut &SOut) const
Definition: dt.h:1150
static PNEANet Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:2182
TEdgeData & GetInEDat(const int &EdgeN)
Definition: network.h:592
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:4215
TNode & GetNode(const int &NId)
Definition: network.h:2005
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:1338
int AddNode(const TNodeI &NodeI)
Definition: network.h:1328
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2421
TNodeI(const TNodeI &NodeI)
Definition: network.h:1800
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:3583
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:706
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2429
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: network.h:1839
TNodeI(const THashIter &NodeHIter, const TNodeEdgeNet *NetPt)
Definition: network.h:1150
TPt< TUndirNet > PNet
Definition: network.h:3148
void IntVAttrValueEI(const TInt &EId, TVec< TIntV > &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2460
bool operator<(const TNodeI &NodeI) const
Definition: network.h:1155
void SortNodeAdjV()
Sorts the adjacency lists of each node.
Definition: network.h:3435
void ReserveNIdInDeg(const int &NId, const int &InDeg)
Reserves memory for node ID NId having InDeg in-edges.
Definition: network.h:3991
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:836
Directed network.
Definition: network.h:3714
TAttrPair SAttrE
Definition: network.h:3825
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:3290
bool IsOutNId(const int &NId) const
Definition: network.h:524
virtual ~TNodeEDatNet()
Definition: network.h:657
void PackOutNIdV()
Definition: network.h:3739
const TNodeData & GetOutNDat(const int &EdgeN) const
Definition: network.h:1191
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: network.h:2019
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:98
TNodeData & GetDat()
Definition: network.h:40
TInt CheckDenseOrSparseE(const TStr &attr) const
Definition: network.h:2089
TNodeI(const TNodeI &NodeI)
Definition: network.h:545
TNodeEdgeNet< TFlt, TFlt > TFltNENet
Definition: network.h:1717
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the graph.
Definition: network.h:2597
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: network.h:2741
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:612
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:3241
TNodeEDatNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:653
bool IsInNId(const int &NId) const
Definition: network.h:3736
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1794
TNodeData & GetDat()
Definition: network.h:1099
TPt< TIntNENet > PIntNENet
Definition: network.h:1716
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.h:924
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:3657
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:4145
Tests (at compile time) if the graph is directed.
Definition: gbase.h:28
const TNEANet * Graph
Definition: network.h:1871
int AddIntVAttrDatE(const TEdgeI &EdgeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2695
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: network.h:1817
TIter BegI() const
Definition: hash.h:213
TPt< TFltNNet > PFltNNet
Definition: network.h:484
bool operator<(const TNodeI &NodeI) const
Definition: network.h:70
const TEdge & GetEdgeKId(const int &EdgeKeyId) const
Definition: network.h:1255
const TNode & GetNode(const int &NId) const
Definition: network.h:1251
static PUndirNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:3312
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:4159
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:3794
TPt< TDirNet > PNet
Definition: network.h:3717
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:573
void LoadShM(TShMIn &MStream)
Definition: network.h:526
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:3772
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:1408
TNode(const TNode &Node)
Definition: network.h:509
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: network.h:1906
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:607
const TNEANet * Graph
Definition: network.h:1796
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:3792
int GetDeg() const
Definition: network.h:1095
void SetEDat(const int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat)
Sets edge data for the edge between nodes SrcNId and DstNId in the network.
Definition: network.h:946
bool operator<(const TNode &Node) const
Definition: network.h:1093
void Save(TSOut &SOut) const
Definition: hash.h:183
virtual ~TNodeEdgeNet()
Definition: network.h:1282
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:1350
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1336
TEdge(const int &EId, const int &SourceNId, const int &DestNId, const TEdgeData &EdgeData)
Definition: network.h:1122
TNodeEdgeNet(const TNodeEdgeNet &Net)
Definition: network.h:1279
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2425
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNod...
Definition: network.h:170
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
const TNodeData & GetInNDat(const int &NodeN) const
Definition: network.h:103
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:1307
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:1154
TStrIntPrH KeyToIndexTypeE
Definition: network.h:2031
const TNodeData & GetInNDat(const int &NodeN) const
Definition: network.h:585
TEdgeData & GetOutEDat(const int &EdgeN)
Definition: network.h:521
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:3629
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:3625
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: network.h:2738
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:113
int GetNbrNId(const int &NodeN) const
Definition: network.h:3166
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
Definition: network.h:975
bool IsInNId(const int &NId) const
Definition: network.h:44
TEdgeData EdgeDat
Definition: network.h:1118
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:3851
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:67
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: network.h:2609
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:221
TNodeI(const TNodeI &NodeI)
Definition: network.h:66
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:373
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
Definition: network.h:2616
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:3525
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: network.h:1205
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: network.h:1835
TNode(TSIn &SIn)
Definition: network.h:33
THash< TInt, TNode > NodeH
Definition: network.h:144
TAttr SAttrN
Definition: network.h:2045
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3751
TStr GetDat() const
Returns an attribute of the node.
Definition: network.h:1974
int GetOutNId(const int &NodeN) const
Definition: network.h:42
TFltVecIter HI
Definition: network.h:1985
TEdge(const TEdge &Edge)
Definition: network.h:1778
TNodeData & GetNbrNDat(const int &NodeN)
Definition: network.h:588
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:69
TCRef CRef
Definition: network.h:1257
TInt GetDat() const
Returns an attribute of the node.
Definition: network.h:1926
int GetOutDeg() const
Definition: network.h:1097
TVec< TIntV >::TIter TIntVVecIter
Definition: network.h:1935
bool IsNbrNId(const int &NId) const
Definition: network.h:525
THash< TStr, TFlt > FltDefaultsN
Definition: network.h:2037
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:791
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3431
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
Definition: network.h:2618
const TEdge & GetEdge(const int &EId) const
Definition: network.h:1254
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: network.h:2595
TEdgeData TEdgeDat
Definition: network.h:494
static PNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from shared memory.
Definition: network.h:178
const TNodeData & GetNbrNDat(const int &NodeN) const
Definition: network.h:587
int GetUniqEdges(const bool &IsDir=true) const
Returns the number of edges in the network with a unique pair of nodes.
Definition: network.h:1545
TNodeEDatNet< TInt, TFlt > TIntFltNEDNet
Definition: network.h:1066
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:1483
Definition: fl.h:384
TAttr SAttrN
Definition: network.h:3824
TNodeData & GetNbrNDat(const int &EdgeN)
Definition: network.h:1194
TNodeData & GetInNDat(const int &NodeN)
Definition: network.h:586
const TNEANet * Graph
Definition: network.h:1942
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2450
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
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
void ReserveNIdOutDeg(const int &NId, const int &OutDeg)
Reserves memory for node ID NId having OutDeg out-edges.
Definition: network.h:3993
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: network.h:1176
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:3615
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:4027
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:3804
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:1346
TFlt GetDat() const
Returns an attribute of the node.
Definition: network.h:1997
int GetDeg() const
Definition: network.h:3730
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:3770
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:229
bool IsOutEId(const int &EId) const
Definition: network.h:1764
TAIntI BegNAIntI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: network.h:2306
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:3479
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
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
Definition: network.h:1911
int GetInNId(const int &EdgeN) const
Definition: network.h:518
TAFltI(const TAFltI &I)
Definition: network.h:1992
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2396
int GetSrcNId() const
Gets the source node of an edge.
Definition: network.h:130
TEdgeData & operator()()
Definition: network.h:620
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: network.h:1900
bool GetEDat(const int &SrcNId, const int &DstNId, TEdgeData &EdgeDat) const
Returns edge data in Data for the edge from node IDs SrcNId to DstNId.
Definition: network.h:953
TVec< TIntV > VecOfIntVecsE
Definition: network.h:2038
TIter EndI() const
Definition: hash.h:218
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:1650
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:1152
const TEdgeData & GetInEDat(const int &EdgeN) const
Definition: network.h:593
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:3549
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
Definition: network.h:1843
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2401
int GetSrcNId() const
Gets the source node of an edge.
Definition: network.h:617
TNodeData NodeDat
Definition: network.h:26
TAIntVI EndNAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2333
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:268
TNode(const int &NId)
Definition: network.h:3725
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:189
int GetInDeg() const
Definition: network.h:3731
bool IsNbrNId(const int &NId) const
Definition: network.h:3738
static PUndirNet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes a...
Definition: network.h:3299
bool IsNbrNId(const int &NId) const
Definition: network.h:46
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1393
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:3273
TNodeData NodeDat
Definition: network.h:1085
static TRnd Rnd
Definition: dt.h:1143
TAFltI GetEAFltI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2567
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:219
int GetNbrEId(const int &EdgeN) const
Definition: network.h:1762
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:2877
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1999
TDirNet TNet
Definition: network.h:3716
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:557
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
Definition: network.h:2559
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:367
TAStrI GetEAStrI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2555
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
Definition: network.h:1982
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the graph.
Definition: network.h:2290
TIntV InNIdV
Definition: network.h:27
Node Edge Network (directed multigraph, TNEGraph with data on nodes and edges).
Definition: network.h:1074
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:4201
int GetId() const
Returns edge ID.
Definition: network.h:1882
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
static PUndirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3301
void PackNIdV()
Definition: network.h:3740
void Load(TSIn &InStream)
Definition: network.h:1784
int GetOutNId(const int &EdgeN) const
Definition: network.h:519
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
TNodeEDatNet< TInt, TInt > TIntNEDNet
Definition: network.h:1064
void Defrag()
Definition: hash.h:555
bool IsOutEId(const int &EId) const
Definition: network.h:1104
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2483
int GetNbrNId(const int &NodeN) const
Definition: network.h:3735
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:1284
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:231
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:4107
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:613
Definition: dt.h:1383
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: network.h:1121
TVec< TStrV > VecOfStrVecsN
Definition: network.h:2039
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: network.h:1902
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:217
TPt< TNet > PNet
Definition: network.h:496
TNodeEDatNet(const TNodeEDatNet &NodeNet)
Definition: network.h:654
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:571
Definition: fl.h:58
void Save(TSOut &SOut) const
Definition: ds.h:954
TEdgeI & operator++(int)
Increment iterator.
Definition: network.h:123
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:223
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge between node IDs SrcNId and DstNId to the graph.
Definition: network.h:1557
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:1809
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:2947
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:3366
int AddFltAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2664
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: network.h:1833
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:4111
void IntVAttrValueNI(const TInt &NId, TVec< TIntV > &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2415
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:78
TEdge(TSIn &SIn)
Definition: network.h:1124
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:575
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:3497
THash< TInt, TIntV >::TIter TIntHVecIter
Definition: network.h:1938
THash< TInt, TEdge > EdgeH
Definition: network.h:2029
void PackNIdV()
Definition: network.h:3171
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEDatNet::New().
Definition: network.h:661
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:3061
TNodeI(const THashIter &NodeHIter)
Definition: network.h:3757
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2491
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
const TNodeData & GetSrcNDat() const
Definition: network.h:625
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2551
int GetDstNId() const
Returns the destination of the edge.
Definition: network.h:1886
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:508
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:3643
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:3005
int GetId() const
Definition: network.h:512
const TEdgeData & GetOutEDat(const int &EdgeN) const
Definition: network.h:522
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:3370
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
bool operator==(const TNodeI &NodeI) const
Definition: network.h:71
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:1231
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:2887
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:3376
static PNEANet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:2222
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:120
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
Definition: network.h:2548
virtual void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:347
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the network.
Definition: network.h:906
const TNodeData & GetDat() const
Definition: network.h:1187
TNodeData & GetInNDat(const int &EdgeN)
Definition: network.h:1190
void SortNIdV()
Definition: network.h:3741
const TNode & GetNode(const int &NId) const
Definition: network.h:3828
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2376
void Save(TSOut &SOut) const
Definition: network.h:511
TAIntVI(const TAIntVI &I)
Definition: network.h:1948
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:606
TNodeData & GetInNDat(const int &NodeN)
Definition: network.h:104
THash< TInt, TNode > NodeH
Definition: network.h:637
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:3987
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the network.
Definition: network.h:3398
THashIter NodeHI
Definition: network.h:61
TAttr SAttrE
Definition: network.h:2046
void DelKey(const TKey &Key)
Definition: hash.h:404
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1219
Definition: attr.h:4
TAIntI EndNAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2309
void LoadShM(TShMIn &MStream)
Definition: network.h:1106
TNodeEDatNet * Net
Definition: network.h:541
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:600
TUndirNet()
Definition: network.h:3282
int GetId() const
Returns ID of the current node.
Definition: network.h:1807
static const int Mn
Definition: dt.h:1138
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: network.h:1859
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: network.h:1841
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
Definition: network.h:2968
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2487
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:559
TInt MxNId
Definition: network.h:1258
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:3420
TAFltI BegNAFltI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
Definition: network.h:2382
TCRef CRef
Definition: network.h:142
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
Definition: network.h:786
int GetOutNId(const int &NodeN) const
Definition: network.h:3165
const TNodeData & GetDat() const
Definition: network.h:101
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:3065
TNEANet(const TNEANet &Graph, bool modeSubGraph)
Definition: network.h:2125
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:4187
Node Edge Network (directed graph, TNGraph with data on nodes and edges).
Definition: network.h:491
TVec< TFltV > VecOfFltVecsE
Definition: network.h:2040
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:3780
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:3671
TNode & GetNode(const int &NId)
Definition: network.h:632
int GetId() const
Definition: network.h:1094
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:2031
TAFltI EndNAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2385
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:714
TNodeData & GetDstNDat()
Definition: network.h:1245
TInt GetIntAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: network.h:2735
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:168
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:3226
int AddStrAttrDatN(const TNodeI &NodeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2659
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:3933
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:3553
void Gen(const int &ExpectVals)
Definition: hash.h:222
TUndirNet TNet
Definition: network.h:3147
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
TNode & GetNode(const int &NId)
Definition: network.h:1250
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:756
Tests (at compile time) if the graph is a network with data on edges.
Definition: gbase.h:34
TAIntI(const TIntVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1920
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:3836
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:784
int GetInDeg() const
Definition: network.h:3162
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:84
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
Definition: network.h:1855
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2478
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:3980
TEdgeDat & GetNbrEDat(const int &EdgeN)
Definition: network.h:1213
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:172
TNodeData & GetDstNDat()
Definition: network.h:134
TNodeI(const TNodeI &NodeI)
Definition: network.h:3188
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:1428
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:615
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: network.h:1825
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:2929
bool IsOutNId(const int &NId) const
Definition: network.h:3737
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:3985
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:3788
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3368
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
Definition: network.h:2634
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:4183
static PUndirNet Load_V1(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3303
void ReserveNIdDeg(const int &NId, const int &Deg)
Reserves memory for node ID NId having Deg edges.
Definition: network.h:3433
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:608
TFltV::TIter TFltVecIter
Definition: network.h:1984
TEdgeI & operator++(int)
Increment iterator.
Definition: network.h:610
TNode & GetNode(const int &NId)
Definition: network.h:3263
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the network.
Definition: network.h:381
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the network.
Definition: network.h:1412
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:3653
int GetDstNId() const
Gets the destination node of an edge.
Definition: network.h:132
int GetId() const
Definition: network.h:1127
static PDirNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:3871
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
Definition: ds.h:838
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the network.
Definition: network.h:3896
TCRef CRef
Definition: network.h:2025
TNode(const TNode &Node)
Definition: network.h:3726
bool operator<(const TNode &Node) const
Definition: network.h:53
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.h:939
TNode(TSIn &SIn)
Definition: network.h:510
TAStrI & operator++(int)
Definition: network.h:1977
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:3047
const TNodeData & GetDat() const
Definition: network.h:1098
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: network.h:2021
const TNodeData & GetSrcNDat() const
Definition: network.h:133
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:280
TNEANet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
Definition: network.h:2104
TAStrI(const TAStrI &I)
Definition: network.h:1969
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:96
TNEANet()
Definition: network.h:2097
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:2961
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:233
THashIter NodeHI
Definition: network.h:3184
TNodeData & GetDstNDat()
Definition: network.h:626
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
TNodeI(const THashIter &NodeHIter)
Definition: network.h:3187
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
void operator()(TNode *n, TShMIn &ShMIn)
Definition: network.h:150
const TEdgeData & GetDat() const
Definition: network.h:1240
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
Definition: gbase.h:30
THash< TInt, TNode > NodeH
Definition: network.h:3823
#define Assert(Cond)
Definition: bd.h:251
TAIntVI EndEAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2513
THash< TInt, TNode > NodeH
Definition: network.h:1259
TInt MxNId
Definition: network.h:3257
TNodeNet * Net
Definition: network.h:62
TNodeI EndNode
Definition: network.h:115
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
Definition: network.h:2296
TNodeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:165
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:3427
TEdgeData & GetDat()
Definition: network.h:1241
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
TNodeEDatNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:656
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:2901
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:793
const TNodeData & operator()() const
Definition: network.h:1185
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:3230
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:1016
TNodeEDatNet< TNodeData, TEdgeData > TNet
Definition: network.h:495
TNodeI(const TNodeI &NodeI)
Definition: network.h:3758
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
bool IsInNId(const int &NId) const
Definition: network.h:3168
THashIter NodeHI
Definition: network.h:540
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:94
TAIntVI GetNAIntVI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2352
int AddKey(const TKey &Key)
Definition: shash.h:1254
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:3601
TInt MxNId
Definition: network.h:143
int FFirstKeyId() const
Definition: hash.h:278
void Save(TSOut &SOut) const
Definition: network.h:3728
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:3248
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:128
TAIntI GetNAIntI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2312
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: network.h:1199
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:3120
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:3465
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
Definition: network.h:2605
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:306
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:1811
int GetDstNId() const
Definition: network.h:1783
TNode(const int &NId)
Definition: network.h:30
void PackOutNIdV()
Definition: network.h:3170
TNodeI(const THashIter &NodeHIter, const TNodeEDatNet *NetPt)
Definition: network.h:544
THash< TInt, TNode >::TIter THashIter
Definition: network.h:3183
TEdge(TSIn &SIn)
Definition: network.h:1779
TNodeData & GetSrcNDat()
Definition: network.h:624
TVec< TPair< TInt, TEdgeData > > TNIdDatPrV
Definition: network.h:497
TNodeData & GetDat()
Definition: network.h:102
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:4051
TNode(const TNode &Node)
Definition: network.h:1753
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
Definition: network.h:2015
int GetSrcNId() const
Returns the source of the edge.
Definition: network.h:1884
TEdgeData & GetDat()
Definition: network.h:1138
TNodeNet()
Definition: network.h:160
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:3214
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:722
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:777
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:537
TVec< TVec< TIntV > > VecOfIntVecVecsE
Definition: network.h:2041
TNodeEdgeNet & operator=(const TNodeEdgeNet &Net)
Definition: network.h:1303
void LoadShM(TShMIn &MStream)
Definition: network.h:3742
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: network.h:1890
static TStr GetNullStr()
Definition: dt.cpp:1626
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:3611
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:3784
int GetDstNId() const
Returns the destination of the edge. Since the network is undirected, this is the node with a greater...
Definition: network.h:3252
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3372
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:4155
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:3805
void Save_V2(TSOut &SOut) const
Saves the graph without any sparse data structures. Available for backwards compatibility.
Definition: network.h:2164
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:266
bool IsInNId(const int &NId) const
Definition: network.h:523
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:3023
THash< TInt, TEdge > EdgeH
Definition: network.h:1260
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:3969
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
Definition: network.h:1626
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:818
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2442
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:1164
void SortNIdV()
Definition: network.h:3172
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2433
TInt MxNId
Definition: network.h:636
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:2943
Directed multigraph with node edge attributes.
Definition: network.h:1741
Definition: fl.h:128
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:126
TPt< TNEANet > PNet
Definition: network.h:1744
TEdgeData & GetOutEDat(const int &EdgeN)
Definition: network.h:590
void LoadNetworkShM(TShMIn &ShMIn)
load network from shared memory for this network
Definition: network.cpp:2
static PDirNet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes a...
Definition: network.h:3859
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: network.h:1845
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:2905
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: network.h:1863
bool Empty() const
Tests whether the graph is empty (has zero nodes).
Definition: network.h:2625
TNode(TSIn &SIn)
Definition: network.h:3727
TInt MxEId
Definition: network.h:2027
static PNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from shared memory.
Definition: network.h:669
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1519
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:3667
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
Definition: network.h:2372
TNodeI CurNode
Definition: network.h:3800
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: network.h:1904
TNodeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:162
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1382
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1976
int GetInDeg() const
Definition: network.h:1096
TStrV::TIter TStrVecIter
Definition: network.h:1961
const TNodeData & operator()() const
Definition: network.h:99
TEdgeData & GetEDat(const int &EId)
Returns edge data for the edge with ID EId.
Definition: network.h:1399
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
Definition: network.h:209
int GetId() const
Definition: network.h:3160
int GetSrcNId() const
Gets the source of an edge.
Definition: network.h:1235
TPt< TNet > PNet
Definition: network.h:21
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:3937
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:2933
bool IsInEId(const int &EId) const
Definition: network.h:1763
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:4141
void SortByKey(const bool &Asc=true)
Definition: hash.h:291
void SetEDat(const int &EId, const TEdgeData &EdgeDat)
Sets edge data for the edge of ID NId in the network.
Definition: network.h:1620
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.h:401
Definition: dt.h:1134
void LoadShM(TShMIn &MStream)
Definition: network.h:1765
TEdge & GetEdge(const int &EId)
Definition: network.h:2007
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:432
int GetOutDeg() const
Definition: network.h:1759
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:92
const TNode & GetNode(const int &NId) const
Definition: network.h:3264
TAIntVI BegEAIntVI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2496
int GetNbrNId(const int &EdgeN) const
Definition: network.h:520
void LoadShM(TShMIn &MStream)
Definition: network.h:47
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:215
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
Definition: network.h:2614
int GetEId(const int &SrcNId, const int &DstNId) const
Definition: network.h:1387
int GetDeg() const
Definition: network.h:3161
int GetId() const
Returns ID of the current node.
Definition: network.h:74
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
THash< TInt, TEdge >::TIter THashIter
Definition: network.h:1221
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
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:4097
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:645
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:1406
TAIntVI GetEAIntVI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2530
bool IsNbrNId(const int &NId) const
Definition: network.h:3167
TUndirNet(const TUndirNet &Graph)
Definition: network.h:3285
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1849
const TNodeData & GetOutNDat(const int &NodeN) const
Definition: network.h:105
const TEdgeData & operator()() const
Definition: network.h:1238
int GetId() const
Gets edge ID.
Definition: network.h:1233
const TEdgeDat & GetNbrEDat(const int &EdgeN) const
Definition: network.h:1214
TNode(const int &NId)
Definition: network.h:1752
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
Definition: ds.h:932
int GetId() const
Definition: network.h:3729
TUndirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3284
TNodeNet< TInt > TIntNNet
Definition: network.h:481
TNodeNet< TFlt > TFltNNet
Definition: network.h:483
TNodeData & GetDat()
Definition: network.h:582
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
Definition: network.h:4118
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:311
TNodeI EndNode
Definition: network.h:3800
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1867
TNode(const TNode &Node)
Definition: network.h:32
static PNEANet Load_V2(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:2199
int DelAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
Definition: network.h:2771
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:789
TNode(const int &NId)
Definition: network.h:507
int Len() const
Definition: shash.h:1121
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3324
TNode(const TNode &Node)
Definition: network.h:1090
TPt< TStrNNet > PStrNNet
Definition: network.h:486
void SortEIdById(const bool &Asc=true)
Sorts edges by edge IDs.
Definition: network.h:1430
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:1473
THash< TInt, TEdge >::TIter THashIter
Definition: network.h:1869
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2474
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the network.
Definition: network.h:3338
TNode(const int &NId)
Definition: network.h:1088
TNodeEdgeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:1281
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:710
TNodeData TNodeDat
Definition: network.h:493
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:3429
TEdgeData TEdgeDat
Definition: network.h:1077
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:1078
int GetId() const
Definition: network.h:35
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:1230
THash< TStr, TStr > StrDefaultsE
Definition: network.h:2036
const TEdgeData & GetDat() const
Definition: network.h:623
int GetOutDeg() const
Definition: network.h:515
int GetInEId(const int &NodeN) const
Definition: network.h:1100
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:872
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:1342
const TNode & GetNodeKId(const int &NodeKeyId) const
Definition: network.h:1252
const TNodeData & GetSrcNDat() const
Definition: network.h:1242
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
void Load(TSIn &InStream)
Definition: network.h:1130
void ConvertToSparse()
Definition: network.h:2228
int GetEdges() const
Returns the number of edges in the graph.
Definition: network.h:2576
void Save(TSOut &SOut) const
Definition: network.h:1780
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:3422
TNodeNet< TNodeData > TNet
Definition: network.h:20
static PDirNet Load_V1(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3863
Undirected network.
Definition: network.h:3145
TNodeNet< TStr > TStrNNet
Definition: network.h:485
int GetOutEId(const int &EdgeN) const
Definition: network.h:1761
THashIter NodeHI
Definition: network.h:1146
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:1162
TNodeI CurNode
Definition: network.h:115
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:2140
TAttrPair SAttrE
Definition: network.h:3261
void GetEIdV(TIntV &EIdV) const
Returns a vector of all edge IDs in the network.
Definition: network.h:1642
bool IsInEId(const int &EId) const
Definition: network.h:1103
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:1227
int GetDstNId() const
Returns the destination node of the edge.
Definition: network.h:3817
TAIntVI BegNAIntVI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: network.h:2316
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
TDirNet()
Definition: network.h:3844
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: network.h:1847
const TEdgeDat & GetInEDat(const int &EdgeN) const
Definition: network.h:1210
const TNodeData & GetDstNDat() const
Definition: network.h:627
TNodeNet & operator=(const TNodeNet &NodeNet)
Definition: network.h:185
const TNodeData & GetNbrNDat(const int &NodeN) const
Definition: network.h:107
TNEANet(const TNEANet &Graph)
Definition: network.h:2111
static PNEANet Load_V1(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:2184
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:1875
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:593
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
static PNet New()
Static constructor that returns a pointer to the network.
Definition: network.h:1288
void DelEdge(const int &EId)
Deletes an edge with ID EId from the network.
Definition: network.h:1581
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:3075
TPt< TIntNNet > PIntNNet
Definition: network.h:482
void operator()(TNode *n, TShMIn &ShMIn)
Definition: network.h:642
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:88
bool operator<(const TEdge &Edge) const
Definition: network.h:1126
TNodeEdgeNet * Net
Definition: network.h:1147
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:3774
TNode(TSIn &SIn)
Definition: network.h:1754
const TNode & GetNode(const int &NId) const
Definition: network.h:2006
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:567
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:3539
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
Definition: network.h:2573
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:4093
Definition: hash.h:97
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:1354
TAttr SAttrN
Definition: network.h:3260
int GetInDeg() const
Definition: network.h:37
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: network.h:1837
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:4229
TAIntI & operator++(int)
Definition: network.h:1929
const TEdgeData & GetDat() const
Definition: network.h:1137
int GetDeg() const
Definition: network.h:1757
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:2891
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:3009
TVec< TFltV > VecOfFltVecsN
Definition: network.h:2040
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:4065
int GetInDeg() const
Definition: network.h:1758
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2563
TIntV::TIter TIntVecIter
Definition: network.h:1913
TAFltI GetNAFltI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2388
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:3597
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:1458
void Clr()
Deletes all nodes and edges from the graph.
Definition: network.h:2627
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
Definition: network.h:275
TEdgeData & GetNbrEDat(const int &EdgeN)
Definition: network.h:594
void Save(TSOut &SOut) const
Definition: network.h:3159
void operator()(TNode *n, TShMIn &ShMIn)
Definition: network.h:1265
int GetId() const
Definition: network.h:1756
TVec< THash< TInt, TIntV > > VecOfIntHashVecsN
Definition: network.h:2042
const TNodeData & GetNbrNDat(const int &EdgeN) const
Definition: network.h:1193
TCRef CRef
Definition: network.h:3256
int GetDeg() const
Definition: network.h:513
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:4169
TNodeData NodeDat
Definition: network.h:502
int GetEId(const int &SrcNId, const int &DstNId) const
Returns an edge ID between node IDs SrcNId and DstNId, if such an edge exists. Otherwise, return -1.
Definition: network.h:2601
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:3374
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:1419
virtual ~TNodeNet()
Definition: network.h:166
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:577
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:3493
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1853
const TNodeData & GetOutNDat(const int &NodeN) const
Definition: network.h:583
TVal1 Val1
Definition: ds.h:34
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:1334
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: network.h:1395
TVal2 Val2
Definition: ds.h:35
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:361
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2146
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: network.h:1203
bool operator<(const TNode &Node) const
Definition: network.h:532
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:3051
Definition: bd.h:196
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
Definition: network.h:746
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.h:408
THash< TStr, TInt > IntDefaultsN
Definition: network.h:2035
int GetDstNId() const
Definition: network.h:1129
TNodeI(const THashIter &NodeHIter, const TNEANet *GraphPt)
Definition: network.h:1799
TNode(const int &NId)
Definition: network.h:3156
TAIntVI(const TIntVVecIter &HIter, const TIntHVecIter &HHIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt, bool is_dense)
Definition: network.h:1945
TNodeEdgeNet * Net
Definition: network.h:1223
TIntV OutNIdV
Definition: network.h:3722
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
Definition: network.h:716
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2298
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3882
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:3978
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:3790
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:3219
const TNEANet * Graph
Definition: network.h:1988
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:423
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:1005
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:1519
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:80
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
int GetSrcNId() const
Definition: network.h:1128
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:2919
int GetRndKeyId(TRnd &Rnd) const
Get an index of a random element. If the hash table has many deleted keys, this may take a long time...
Definition: hash.h:444
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:1183
static PDirNet New()
Static constructor that returns a pointer to the network. Call: PDirNet Graph = TDirNet::New().
Definition: network.h:3855
TEdge & GetEdge(const int &EId)
Definition: network.h:1253
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
Definition: network.h:3560
int GetSrcNId() const
Returns the source of the edge. Since the network is undirected, this is the node with a smaller ID o...
Definition: network.h:3250
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:1228
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
int GetDstNId() const
Gets the destination node of an edge.
Definition: network.h:619
TDirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:3849
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:121
TPt< TNet > PNet
Definition: network.h:1079
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
Definition: network.h:1207
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: network.h:2300
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.h:998
TVec< TVec< TIntV > > VecOfIntVecVecsN
Definition: network.h:2041
int GetInDeg() const
Definition: network.h:514
THashIter EdgeHI
Definition: network.h:1870
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:257
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:3469
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:3019
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition: ds.h:543
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:3033
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: network.h:1777
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2304
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:712
const TEdgeData & GetOutEDat(const int &EdgeN) const
Definition: network.h:591
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
Definition: network.h:2017
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:1463
int GetInEId(const int &EdgeN) const
Definition: network.h:1760
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:3410
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:4041
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2446
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:3639
TEdgeData & GetDat()
Definition: network.h:622
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:3929
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1892
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:278
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:546
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:2013
TAStrI(const TStrVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1968
TNodeEdgeNet< TInt, TInt > TIntNENet
Definition: network.h:1715
int GetOutDeg() const
Definition: network.h:3163
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:663
TInt MxNId
Definition: network.h:3822
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:433
int GetInNId(const int &NodeN) const
Definition: network.h:3733
TIntVecIter HI
Definition: network.h:1914
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:3925
char * CStr()
Definition: dt.h:476
bool IsOutNId(const int &NId) const
Definition: network.h:3169
TDirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3846
TNodeData & GetNbrNDat(const int &NodeN)
Definition: network.h:108
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the network is undirected...
Definition: network.h:3205
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:58
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:3535
THashIter NodeHI
Definition: network.h:1795
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:2957
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:4037
TPt< TNEANet > PNEANet
Pointer to a directed attribute multigraph (TNEANet)
Definition: network.h:1720
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TIntV GetDat() const
Returns an attribute of the node.
Definition: network.h:1953
static PDirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3861
int AddAttributes(const int NId)
Definition: network.cpp:468
TNEANet TNet
Definition: network.h:1743
const TEdge & GetEdge(const int &EId) const
Definition: network.h:2008
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:3037
Definition: dt.h:971
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:2176
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: network.h:1861
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:1660
static PNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:1296
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.h:323
TIntV OutNIdV
Definition: network.h:27
TInt NEdges
Definition: network.h:3257
TAIntVI & operator++(int)
Definition: network.h:1954
TNodeI(const TNodeI &NodeI)
Definition: network.h:1151
int GetSrcNId() const
Returns the source node of the edge.
Definition: network.h:3815
int Len() const
Definition: hash.h:228
TIntVVecIter HI
Definition: network.h:1936
TNodeData & GetOutNDat(const int &NodeN)
Definition: network.h:584
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
Definition: network.h:2768
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:1160
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:597
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: network.h:1857
TNEANet(bool copyAll, const TNEANet &Graph)
Definition: network.h:2131
int GetOutDeg() const
Definition: network.h:3732
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.h:1384
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1391
bool operator==(const TNodeI &NodeI) const
Definition: network.h:550
THashIter NodeHI
Definition: network.h:3754
TEdgeDat & GetInEDat(const int &EdgeN)
Definition: network.h:1209
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:2915
void Save(TSOut &SOut) const
Definition: network.h:34
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
Definition: network.h:3085
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
Definition: network.h:1959
bool operator<(const TNodeI &NodeI) const
Definition: network.h:549
void SortNodeAdjV()
Sorts the adjacency lists of each node.
Definition: network.h:3995
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: network.h:1888
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1143
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2654
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: network.h:1894
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:4023
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:4173
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
Definition: network.h:1898
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1991
const TNEANet * Graph
Definition: network.h:1917
void Save(TSOut &SOut) const
Definition: network.h:1125
TAIntI(const TAIntI &I)
Definition: network.h:1921
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
THash< TInt, TNode >::TIter THashIter
Definition: network.h:60
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:3240
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:1340
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: network.h:1851
TNIdDatPrV OutNIdV
Definition: network.h:504
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3931
void SortNIdV()
Sorts the adjacency lists of the current node.
Definition: network.h:3209
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3181
const TNEANet * Graph
Definition: network.h:1965
int GetOutEId(const int &NodeN) const
Definition: network.h:1101
THash< TStr, TBool > KeyToDenseN
KeyToDense[N|E]: Key->(True if Vec, False if Hash)
Definition: network.h:2033
static PNEANet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and...
Definition: network.h:2180
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the network.
Definition: network.h:1410
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:4055
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:2571
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1145
Node Network (directed graph, TNGraph with data on nodes only).
Definition: network.h:17
int GetId() const
Returns ID of the current node.
Definition: network.h:1158
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:2995
int GetDeg() const
Returns degree of the current node.
Definition: network.h:555
const TEdgeData & GetEDat(const int &EId) const
Returns edge data for the edge with ID EId.
Definition: network.h:1401
TNodeEDatNet< TStr, TInt > TStrIntNEDNet
Definition: network.h:1068
int GetId() const
Returns ID of the current node.
Definition: network.h:3768
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:3408
TUndirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:3288
const TEdgeData & GetNbrEDat(const int &EdgeN) const
Definition: network.h:595
int GetId() const
Returns ID of the current node.
Definition: network.h:553
const TNodeData & GetDstNDat() const
Definition: network.h:1244
const TNodeData & GetDat() const
Definition: network.h:581
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:31
int GetDstNId() const
Gets destination of an edge.
Definition: network.h:1237
TIntHVecIter HHI
Definition: network.h:1939
static const double Mn
Definition: dt.h:1387
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:3483
TNodeEDatNet()
Definition: network.h:651
int GetNbrNId(const int &NodeN) const
Definition: network.h:43
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1896
bool operator==(const TNodeI &NodeI) const
Definition: network.h:1156
TPt< TDirNet > PDirNet
Pointer to a directed network (TDirNet)
Definition: network.h:3127
int GetOutDeg() const
Definition: network.h:38
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:1290
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
TNodeEdgeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1278
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:680
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
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:779
TIter GetI(const TKey &Key) const
Definition: hash.h:220
void SortByDat(const bool &Asc=true)
Definition: hash.h:292
TPt< TFltNENet > PFltNENet
Definition: network.h:1718
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:724
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
Definition: network.h:3293
TNodeData & GetSrcNDat()
Definition: network.h:1243
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:259