SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
mmnet.h
Go to the documentation of this file.
1 #ifndef MMNET_H
2 #define MMNET_H
3 
4 
5 class TMMNet;
6 
7 
8 typedef TPt<TMMNet> PMMNet;
9 
11 class TModeNet;
12 
14 class TCrossNet;
15 
16 
17 //#//////////////////////////////////////////////
19 
23 class TModeNet : public TNEANet {
24 public:
25  typedef TModeNet TNetMM;
26 public:
28  class TNodeI : public TNEANet::TNodeI {
29  public:
30  TNodeI() : TNEANet::TNodeI() { }
31  TNodeI(const THashIter& NodeHIter, const TModeNet* GraphPt) : TNEANet::TNodeI(NodeHIter, GraphPt) { }
32  TNodeI(const TNodeI& NodeI) : TNEANet::TNodeI(NodeI) { }
33  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Graph=NodeI.Graph; return *this; }
35  TNodeI& operator++ (int) { NodeHI++; return *this; }
36  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
37  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
39  void GetNeighborsByCrossNet(TStr& Name, TIntV& Neighbors, const bool isOutEId=false) {
40  const TModeNet *TMGraph = static_cast<const TModeNet *>(Graph); TMGraph->GetNeighborsByCrossNet(GetId(), Name, Neighbors, isOutEId); }
42  void GetCrossNetNames(TStrV& Names) { const TModeNet *TMGraph = static_cast<const TModeNet *>(Graph); TMGraph->GetCrossNetNames(Names); }
43  friend class TModeNet;
44  };
45 private:
47  TMMNet *MMNet; // A pointer to the parent MMNet
48  THash<TStr, TBool> NeighborTypes; // Mapping of the Neighbor/CrossNets for this mode to whether it requires a one (or two) vectors to store neighbors
49 
50 public:
51  TModeNet() : TNEANet(), ModeId(-1), MMNet(), NeighborTypes() { }
52  TModeNet(const int& TypeId) : TNEANet(), ModeId(TypeId), MMNet(), NeighborTypes() { }
54  explicit TModeNet(const int& Nodes, const int& Edges) : TNEANet(Nodes, Edges),
55  ModeId(-1), MMNet(), NeighborTypes(){ }
56  explicit TModeNet(const int& Nodes, const int& Edges, const int& TypeId) : TNEANet(Nodes, Edges),
57  ModeId(TypeId), MMNet(), NeighborTypes() { }
58  TModeNet(const TModeNet& Graph) : TNEANet(true, Graph), ModeId(Graph.ModeId), MMNet(Graph.MMNet), NeighborTypes(Graph.NeighborTypes) { }
60  TModeNet(TSIn& SIn) : TNEANet(SIn), ModeId(SIn), MMNet(), NeighborTypes(SIn) { }
61 private:
62  TModeNet(const TModeNet& Graph, bool isSubModeGraph) : TNEANet(Graph, isSubModeGraph), ModeId(Graph.ModeId), MMNet(), NeighborTypes() {}
63 public:
65  void Save(TSOut& SOut) const {
66  TNEANet::Save(SOut); ModeId.Save(SOut); NeighborTypes.Save(SOut); }
68  void LoadShM(TShMIn & ShMIn) {
70  ModeId = TInt(ShMIn);
71  MMNet = NULL;
72  NeighborTypes.LoadShM(ShMIn);
73  }
75  void DelNode(const int& NId);
77  void GetCrossNetNames(TStrV& Names) const { NeighborTypes.GetKeyV(Names); }
79  void GetNeighborsByCrossNet(const int& NId, TStr& Name, TIntV& Neighbors, const bool isOutEId=false) const;
80 
82  TNodeI BegMMNI() const { return TNodeI(NodeH.BegI(), this); }
84  TNodeI EndMMNI() const { return TNodeI(NodeH.EndI(), this); }
86  TNodeI GetMMNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
88  void Clr();
89 
90 
91  TModeNet& operator = (const TModeNet& Graph) {
92  if (this!=&Graph) {
93  MxNId=Graph.MxNId; MxEId=Graph.MxEId; NodeH=Graph.NodeH; EdgeH=Graph.EdgeH;
101  ModeId=Graph.ModeId; MMNet=Graph.MMNet; NeighborTypes=Graph.NeighborTypes;
102  }
103  return *this;
104  }
105 
106 private:
107  //method to add neighbors; will be called by TMMNet AddEdge function; outEdge == true iff NId(which is of the type of the TModeNet; i.e. it should refer to a node in this graph) is the source node.
108  int AddNeighbor(const int& NId, const int& EId, const bool outEdge, const int linkId, const bool sameMode, bool isDir);
109  int AddNeighbor(const int& NId, const int& EId, const bool outEdge, const TStr& linkName, const bool sameMode, bool isDir);
110  int DelNeighbor(const int& NId, const int& EId, bool outEdge, const TStr& CrossName, const bool sameMode, bool isDir);
111  int DelNeighbor(const int& NId, const int& EId, bool outEdge, const TInt& linkId, const bool sameMode, bool isDir);
112  TStr GetNeighborCrossName(const TStr& CrossName, bool isOutEdge, const bool sameMode, bool isDir) const;
113  void SetParentPointer(TMMNet* parent);
114  int AddNbrType(const TStr& CrossName, const bool sameMode, bool isDir);
116  int AddIntVAttrByVecN(const TStr& attr, TVec<TIntV>& Attrs, TBool UseDense=true);
117  int AddIntVAttrByHashN(const TStr& attr, THash<TInt, TIntV>& Attrs);
118  void RemoveCrossNets(TModeNet& Result, TStrV& CrossNets);
119  int DelNbrType(const TStr& CrossName);
120  int GetAttrTypeN(const TStr& attr) const;
121  void ClrNbr(const TStr& CrossNetName, const bool& outEdge, const bool& sameMode, bool& isDir);
122 public:
123  friend class TMMNet;
124  friend class TCrossNet;
125 };
126 
127 
128 //#///////////////////////////////////////////////
130 
133 class TCrossNet {
134 
135 public:
136  //#///////////////////////////////////////////////
138  class TCrossEdge {
139  private:
142  public:
143  TCrossEdge() : EId(-1), SrcNId(-1), DstNId(-1) { }
144  TCrossEdge(const int& Id, const int& SourceNId, const int& DestNId) :
145  EId(Id), SrcNId(SourceNId), DstNId(DestNId) { }
146  TCrossEdge(const TCrossEdge& MultiEdge) : EId(MultiEdge.EId), SrcNId(MultiEdge.SrcNId),
147  DstNId(MultiEdge.DstNId) { }
148  TCrossEdge(TSIn& SIn) : EId(SIn), SrcNId(SIn), DstNId(SIn) { }
149  void Save(TSOut& SOut) const { EId.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
150  int GetId() const { return EId; }
151  int GetSrcNId() const { return SrcNId; }
152  int GetDstNId() const { return DstNId; }
153  size_t GetMemUsed() const { return EId.GetMemUsed() + SrcNId.GetMemUsed() + DstNId.GetMemUsed(); }
154  friend class TCrossNet;
155  };
157  class TCrossEdgeI {
158  private:
160  THashIter CrossHI;
161  const TCrossNet *Graph;
162  public:
163  TCrossEdgeI() : CrossHI(), Graph(NULL) { }
164  TCrossEdgeI(const THashIter& CrossHIter, const TCrossNet *GraphPt) : CrossHI(CrossHIter), Graph(GraphPt) { }
165  TCrossEdgeI(const TCrossEdgeI& EdgeI) : CrossHI(EdgeI.CrossHI), Graph(EdgeI.Graph) { }
166  TCrossEdgeI& operator = (const TCrossEdgeI& EdgeI) { if (this!=&EdgeI) { CrossHI=EdgeI.CrossHI; Graph=EdgeI.Graph; } return *this; }
168  TCrossEdgeI& operator++ (int) { CrossHI++; return *this; }
169  bool operator < (const TCrossEdgeI& EdgeI) const { return CrossHI < EdgeI.CrossHI; }
170  bool operator == (const TCrossEdgeI& EdgeI) const { return CrossHI == EdgeI.CrossHI; }
172  int GetId() const { return CrossHI.GetDat().GetId(); }
174  int GetSrcNId() const { return CrossHI.GetDat().GetSrcNId(); }
176  int GetDstNId() const { return CrossHI.GetDat().GetDstNId(); }
177 
179  int GetSrcModeId() const { return Graph->GetMode1(); }
181  int GetDstModeId() const { return Graph->GetMode2(); }
183  bool IsDirected() const { return Graph->IsDirected(); }
184 
185 
186  friend class TCrossNet;
187  };
188 
190  class TAIntI {
191  private:
193  TIntVecIter HI;
195  const TCrossNet *Graph;
196  public:
197  TAIntI() : HI(), attr(), Graph(NULL) { }
198  TAIntI(const TIntVecIter& HIter, TStr attribute, const TCrossNet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { attr = attribute; }
199  TAIntI(const TAIntI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { }
200  TAIntI& operator = (const TAIntI& I) { HI = I.HI; Graph=I.Graph; attr = I.attr; return *this; }
201  bool operator < (const TAIntI& I) const { return HI < I.HI; }
202  bool operator == (const TAIntI& I) const { return HI == I.HI; }
204  TInt GetDat() const { return HI[0]; }
206  bool IsDeleted() const { return GetDat() == Graph->GetIntAttrDefaultE(attr); };
207  TAIntI& operator++(int) { HI++; return *this; }
208  friend class TCrossNet;
209  };
210 
212  class TAStrI {
213  private:
215  TStrVecIter HI;
217  const TCrossNet *Graph;
218  public:
219  TAStrI() : HI(), attr(), Graph(NULL) { }
220  TAStrI(const TStrVecIter& HIter, TStr attribute, const TCrossNet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { attr = attribute; }
221  TAStrI(const TAStrI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { }
222  TAStrI& operator = (const TAStrI& I) { HI = I.HI; Graph=I.Graph; attr = I.attr; return *this; }
223  bool operator < (const TAStrI& I) const { return HI < I.HI; }
224  bool operator == (const TAStrI& I) const { return HI == I.HI; }
226  TStr GetDat() const { return HI[0]; }
228  bool IsDeleted() const { return GetDat() == Graph->GetStrAttrDefaultE(attr); };
229  TAStrI& operator++(int) { HI++; return *this; }
230  friend class TCrossNet;
231  };
232 
234  class TAFltI {
235  private:
237  TFltVecIter HI;
239  const TCrossNet *Graph;
240  public:
241  TAFltI() : HI(), attr(), Graph(NULL) { }
242  TAFltI(const TFltVecIter& HIter, TStr attribute, const TCrossNet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { attr = attribute; }
243  TAFltI(const TAFltI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { }
244  TAFltI& operator = (const TAFltI& I) { HI = I.HI; Graph=I.Graph; attr = I.attr; return *this; }
245  bool operator < (const TAFltI& I) const { return HI < I.HI; }
246  bool operator == (const TAFltI& I) const { return HI == I.HI; }
248  TFlt GetDat() const { return HI[0]; }
250  bool IsDeleted() const { return GetDat() == Graph->GetFltAttrDefaultE(attr); };
251  TAFltI& operator++(int) { HI++; return *this; }
252  friend class TCrossNet;
253  };
254 private:
255  class TLoadVecInit {
256  public:
258  template<typename TElem>
259  void operator() (TVec<TElem>* Node, TShMIn& ShMIn) {
260  Node->LoadShM(ShMIn);
261  }
262  };
263 private:
278  enum { IntType, StrType, FltType };
279 public:
280  TCrossNet() : CrossH(), MxEId(0), Mode1(-1), Mode2(-1), IsDirect(), CrossNetId(), Net(), KeyToIndexTypeE(), IntDefaultsE(), StrDefaultsE(),
281  FltDefaultsE(), VecOfIntVecsE(), VecOfStrVecsE(), VecOfFltVecsE() {}
282  TCrossNet(TInt MId1, TInt MId2, TInt LId) : CrossH(), MxEId(0), Mode1(MId1), Mode2(MId2), IsDirect(true),CrossNetId(LId), Net(),
283  KeyToIndexTypeE(), IntDefaultsE(), StrDefaultsE(), FltDefaultsE(), VecOfIntVecsE(), VecOfStrVecsE(), VecOfFltVecsE() {}
284  TCrossNet(TInt MId1, TInt MId2, TBool IsDir, TInt LId) : CrossH(), MxEId(0), Mode1(MId1), Mode2(MId2), IsDirect(IsDir),CrossNetId(LId), Net(),
285  KeyToIndexTypeE(), IntDefaultsE(), StrDefaultsE(), FltDefaultsE(), VecOfIntVecsE(), VecOfStrVecsE(), VecOfFltVecsE() {}
286  TCrossNet(TSIn& SIn) : CrossH(SIn), MxEId(SIn), Mode1(SIn), Mode2(SIn), IsDirect(SIn), CrossNetId(SIn), Net(),
287  KeyToIndexTypeE(SIn), IntDefaultsE(SIn), StrDefaultsE(SIn), FltDefaultsE(SIn), VecOfIntVecsE(SIn), VecOfStrVecsE(SIn), VecOfFltVecsE(SIn) {}
288  TCrossNet(const TCrossNet& OtherTCrossNet) : CrossH(OtherTCrossNet.CrossH), MxEId(OtherTCrossNet.MxEId), Mode1(OtherTCrossNet.Mode1),
289  Mode2(OtherTCrossNet.Mode2), IsDirect(OtherTCrossNet.IsDirect), CrossNetId(OtherTCrossNet.CrossNetId),Net(OtherTCrossNet.Net), KeyToIndexTypeE(OtherTCrossNet.KeyToIndexTypeE),
290  IntDefaultsE(OtherTCrossNet.IntDefaultsE), StrDefaultsE(OtherTCrossNet.StrDefaultsE), FltDefaultsE(OtherTCrossNet.FltDefaultsE), VecOfIntVecsE(OtherTCrossNet.VecOfIntVecsE),
291  VecOfStrVecsE(OtherTCrossNet.VecOfStrVecsE), VecOfFltVecsE(OtherTCrossNet.VecOfFltVecsE) {}
292 
293  TCrossNet& operator=(const TCrossNet& OtherTCrossNet) {
294  CrossH = OtherTCrossNet.CrossH;
295  MxEId = OtherTCrossNet.MxEId;
296  Mode1 = OtherTCrossNet.Mode1;
297  Mode2 = OtherTCrossNet.Mode2;
298  CrossNetId = OtherTCrossNet.CrossNetId;
299  IsDirect = OtherTCrossNet.IsDirect;
300  Net = OtherTCrossNet.Net;
301  KeyToIndexTypeE = OtherTCrossNet.KeyToIndexTypeE;
302  IntDefaultsE = OtherTCrossNet.IntDefaultsE;
303  StrDefaultsE = OtherTCrossNet.StrDefaultsE;
304  FltDefaultsE = OtherTCrossNet.FltDefaultsE;
305  VecOfIntVecsE = OtherTCrossNet.VecOfIntVecsE;
306  VecOfStrVecsE = OtherTCrossNet.VecOfStrVecsE;
307  VecOfFltVecsE = OtherTCrossNet.VecOfFltVecsE;
308  return *this;
309  }
310 
311 private:
312  void SetParentPointer(TMMNet* parent);
314  TInt GetIntAttrDefaultE(const TStr& attribute) const { return IntDefaultsE.IsKey(attribute) ? IntDefaultsE.GetDat(attribute) : (TInt) TInt::Mn; }
316  TStr GetStrAttrDefaultE(const TStr& attribute) const { return StrDefaultsE.IsKey(attribute) ? StrDefaultsE.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
318  TFlt GetFltAttrDefaultE(const TStr& attribute) const { return FltDefaultsE.IsKey(attribute) ? FltDefaultsE.GetDat(attribute) : (TFlt) TFlt::Mn; }
319  int GetAttrTypeE(const TStr& attr) const;
320  TCrossEdge& GetEdge(int eid) { return CrossH[eid]; }
321 public:
323  bool IsEdge(const int& EId) const { return CrossH.IsKey(EId); }
324 
325  int GetMxEId() const { return MxEId; }
327  int GetEdges() const { return CrossH.Len(); }
329  void Clr();
330 
332  int AddEdge(const int& sourceNId, const int& destNId, int EId=-1);
334  TCrossEdgeI GetEdgeI(const int& EId) const { return TCrossEdgeI(CrossH.GetI(EId), this); }
335  TCrossEdgeI BegEdgeI() const { return TCrossEdgeI(CrossH.BegI(), this); }
336  TCrossEdgeI EndEdgeI() const { return TCrossEdgeI(CrossH.EndI(), this); }
338  int DelEdge(const int& EId);
340  int GetMode1() const { return Mode1; }
342  int GetMode2() const {return Mode2; }
344  void Save(TSOut& SOut) const { CrossH.Save(SOut); MxEId.Save(SOut); Mode1.Save(SOut); Mode2.Save(SOut); IsDirect.Save(SOut); CrossNetId.Save(SOut);
345  KeyToIndexTypeE.Save(SOut); IntDefaultsE.Save(SOut); StrDefaultsE.Save(SOut); FltDefaultsE.Save(SOut); VecOfIntVecsE.Save(SOut);
346  VecOfStrVecsE.Save(SOut); VecOfFltVecsE.Save(SOut); }
348  void LoadShM(TShMIn& ShMIn) {
349  CrossH.LoadShM(ShMIn);
350  MxEId = TInt(ShMIn);
351  Mode1 = TInt(ShMIn);
352  Mode2 = TInt(ShMIn);
353  IsDirect = TBool(ShMIn);
354  CrossNetId = TInt(ShMIn);
355  Net = NULL;
356  KeyToIndexTypeE.LoadShM(ShMIn);
357  IntDefaultsE.LoadShM(ShMIn);
358  StrDefaultsE.LoadShM(ShMIn);
359  FltDefaultsE.LoadShM(ShMIn);
360  TLoadVecInit VecFn;
361  VecOfIntVecsE.LoadShM(ShMIn, VecFn);
362  VecOfStrVecsE.Load(ShMIn);
363  VecOfFltVecsE.Load(ShMIn);
364  }
365 
367  bool IsDirected() const { return IsDirect;}
369  void AttrNameEI(const TInt& EId, TStrV& Names) const {
370  AttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
371  void AttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const;
373  void AttrValueEI(const TInt& EId, TStrV& Values) const {
374  AttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
375  void AttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Values) const;
377  void IntAttrNameEI(const TInt& EId, TStrV& Names) const {
378  IntAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
379  void IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const;
381  void IntAttrValueEI(const TInt& EId, TIntV& Values) const {
382  IntAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
383  void IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TIntV& Values) const;
384 
385 
387  void StrAttrNameEI(const TInt& EId, TStrV& Names) const {
388  StrAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
389  void StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const;
391  void StrAttrValueEI(const TInt& EId, TStrV& Values) const {
392  StrAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
393  void StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Values) const;
395  void FltAttrNameEI(const TInt& EId, TStrV& Names) const {
396  FltAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
397  void FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const;
399  void FltAttrValueEI(const TInt& EId, TFltV& Values) const {
400  FltAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
401  void FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TFltV& Values) const;
402 
404  int AddIntAttrDatE(const TCrossEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AddIntAttrDatE(EdgeI.GetId(), value, attr); }
405  int AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr);
407  int AddStrAttrDatE(const TCrossEdgeI& EdgeI, const TStr& value, const TStr& attr) { return AddStrAttrDatE(EdgeI.GetId(), value, attr); }
408  int AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr);
410  int AddFltAttrDatE(const TCrossEdgeI& EdgeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatE(EdgeI.GetId(), value, attr); }
411  int AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr);
412 
414  TInt GetIntAttrDatE(const TCrossEdgeI& EdgeI, const TStr& attr) { return GetIntAttrDatE(EdgeI.GetId(), attr); }
415  TInt GetIntAttrDatE(const int& EId, const TStr& attr);
417  TStr GetStrAttrDatE(const TCrossEdgeI& EdgeI, const TStr& attr) { return GetStrAttrDatE(EdgeI.GetId(), attr); }
418  TStr GetStrAttrDatE(const int& EId, const TStr& attr);
420  TFlt GetFltAttrDatE(const TCrossEdgeI& EdgeI, const TStr& attr) { return GetFltAttrDatE(EdgeI.GetId(), attr); }
421  TFlt GetFltAttrDatE(const int& EId, const TStr& attr);
422 
424  TAIntI BegEAIntI(const TStr& attr) const {
425  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, this);
426  }
428  TAIntI EndEAIntI(const TStr& attr) const {
429  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, this);
430  }
432  TAIntI GetEAIntI(const TStr& attr, const int& EId) const {
433  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(CrossH.GetKeyId(EId)), attr, this);
434  }
435 
437  TAStrI BegEAStrI(const TStr& attr) const {
438  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, this); }
440  TAStrI EndEAStrI(const TStr& attr) const {
441  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, this);
442  }
444  TAStrI GetEAStrI(const TStr& attr, const int& EId) const {
445  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(CrossH.GetKeyId(EId)), attr, this);
446  }
448  TAFltI BegEAFltI(const TStr& attr) const {
449  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, this);
450  }
452  TAFltI EndEAFltI(const TStr& attr) const {
453  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, this);
454  }
456  TAFltI GetEAFltI(const TStr& attr, const int& EId) const {
457  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(CrossH.GetKeyId(EId)), attr, this);
458  }
459 
461  int DelAttrDatE(const TCrossEdgeI& EdgeI, const TStr& attr) { return DelAttrDatE(EdgeI.GetId(), attr); }
462  int DelAttrDatE(const int& EId, const TStr& attr);
463 
465  int AddIntAttrE(const TStr& attr, TInt defaultValue=TInt::Mn);
467  int AddStrAttrE(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
469  int AddFltAttrE(const TStr& attr, TFlt defaultValue=TFlt::Mn);
470 
472  int DelAttrE(const TStr& attr);
473 
474  // Returns true if \c attr exists for edge \c EId and has default value.
475  bool IsAttrDeletedE(const int& EId, const TStr& attr) const;
476  // Returns true if Int \c attr exists for edge \c EId and has default value.
477  bool IsIntAttrDeletedE(const int& EId, const TStr& attr) const;
478  // Returns true if Str \c attr exists for edge \c NId and has default value.
479  bool IsStrAttrDeletedE(const int& EId, const TStr& attr) const;
480  // Returns true if Flt \c attr exists for edge \c NId and has default value.
481  bool IsFltAttrDeletedE(const int& EId, const TStr& attr) const;
482 
483  // Returns true if EId attr deleted for current edge attr iterator.
484  bool EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const;
485  // Returns true if EId attr deleted for current edge int attr iterator.
486  bool EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const;
487  // Returns true if EId attr deleted for current edge str attr iterator.
488  bool EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const;
489  // Returns true if EId attr deleted for current edge flt attr iterator.
490  bool EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const;
491 
492  // Returns edge attribute value, converted to Str type.
493  TStr GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& CrossHI) const;
494 
495  friend class TMMNet;
496  friend class TModeNet;
497 };
498 
499 //#///////////////////////////////////////////////
501 
504 class TMMNet {
505 
506 public:
508  class TModeNetI {
509  protected:
511  THashIter ModeNetHI;
512  const TMMNet *Graph;
513  public:
514  TModeNetI() : ModeNetHI(), Graph(NULL) { }
515  TModeNetI(const THashIter& ModeNetHIter, const TMMNet* GraphPt) : ModeNetHI(ModeNetHIter), Graph(GraphPt) { }
516  TModeNetI(const TModeNetI& ModeNetI) : ModeNetHI(ModeNetI.ModeNetHI), Graph(ModeNetI.Graph) { }
517  TModeNetI& operator = (const TModeNetI& ModeNetI) { ModeNetHI = ModeNetI.ModeNetHI; Graph=ModeNetI.Graph; return *this; }
519  TModeNetI& operator++ (int) { ModeNetHI++; return *this; }
520  bool operator < (const TModeNetI& ModeNetI) const { return ModeNetHI < ModeNetI.ModeNetHI; }
521  bool operator == (const TModeNetI& ModeNetI) const { return ModeNetHI == ModeNetI.ModeNetHI; }
523  int GetModeId() { return ModeNetHI.GetKey(); }
525  TStr GetModeName() { return Graph->GetModeName(ModeNetHI.GetKey()); }
527  TModeNet& GetModeNet() { return Graph->GetModeNetById(GetModeId()); }
528  friend class TMMNet;
529  };
530 
532  class TCrossNetI {
533  protected:
535  THashIter CrossNetHI;
536  const TMMNet *Graph;
537  public:
538  TCrossNetI() : CrossNetHI(), Graph(NULL) { }
539  TCrossNetI(const THashIter& CrossNetHIter, const TMMNet* GraphPt) : CrossNetHI(CrossNetHIter), Graph(GraphPt) { }
540  TCrossNetI(const TCrossNetI& CrossNetI) : CrossNetHI(CrossNetI.CrossNetHI), Graph(CrossNetI.Graph) { }
541  TCrossNetI& operator = (const TCrossNetI& CrossNetI) { CrossNetHI = CrossNetI.CrossNetHI; Graph=CrossNetI.Graph; return *this; }
543  TCrossNetI& operator++ (int) { CrossNetHI++; return *this; }
544  bool operator < (const TCrossNetI& CrossNetI) const { return CrossNetHI < CrossNetI.CrossNetHI; }
545  bool operator == (const TCrossNetI& CrossNetI) const { return CrossNetHI == CrossNetI.CrossNetHI; }
547  int GetCrossId() { return CrossNetHI.GetKey(); }
549  TStr GetCrossName() { return Graph->GetCrossName(CrossNetHI.GetKey()); }
552  friend class TMMNet;
553  };
554 
555 public:
556  TCRef CRef; //Reference counter. Necessary for pointers.
557 
558 private:
559 
564 
567 
570 
571 public:
572  friend class TCrossNet;
573  friend class TModeNet;
574 
575 private:
576  class TModeNetInit {
577  public:
579  void operator() (TModeNet* Node, TShMIn& ShMIn) { Node->LoadShM(ShMIn);}
580  };
581 
583  public:
585  void operator() (TCrossNet* Node, TShMIn& ShMIn) { Node->LoadShM(ShMIn);}
586  };
587 private:
588  void LoadNetworkShM(TShMIn& ShMIn);
589 public:
590  TMMNet() : CRef(), MxModeId(0), MxCrossNetId(0), TModeNetH(), TCrossNetH(), ModeIdToNameH(), ModeNameToIdH(), CrossIdToNameH(), CrossNameToIdH() {}
591  TMMNet(const TMMNet& OtherTMMNet) : MxModeId(OtherTMMNet.MxModeId), MxCrossNetId(OtherTMMNet.MxCrossNetId), TModeNetH(OtherTMMNet.TModeNetH),
592  TCrossNetH(OtherTMMNet.TCrossNetH), ModeIdToNameH(OtherTMMNet.ModeIdToNameH), ModeNameToIdH(OtherTMMNet.ModeNameToIdH), CrossIdToNameH(OtherTMMNet.CrossIdToNameH), CrossNameToIdH(OtherTMMNet.CrossNameToIdH) {}
593  TMMNet(TSIn& SIn) : MxModeId(SIn), MxCrossNetId(SIn), TModeNetH(SIn), TCrossNetH(SIn), ModeIdToNameH(SIn), ModeNameToIdH(SIn), CrossIdToNameH(SIn), CrossNameToIdH(SIn) {
594  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
595  it.GetDat().SetParentPointer(this);
596  }
597  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
598  it.GetDat().SetParentPointer(this);
599  }
600  }
602  int AddModeNet(const TStr& ModeName);
604  int DelModeNet(const TInt& ModeId);
605  int DelModeNet(const TStr& ModeName);
607  int AddCrossNet(const TStr& ModeName1, const TStr& ModeName2, const TStr& CrossNetName, bool isDir=true);
608  int AddCrossNet(const TInt& ModeId1, const TInt& ModeId2, const TStr& CrossNetName, bool isDir=true);
610  int DelCrossNet(const TInt& CrossNetId);
611  int DelCrossNet(const TStr& CrossNet);
612 
614  void Save(TSOut& SOut) const {MxModeId.Save(SOut); MxCrossNetId.Save(SOut); TModeNetH.Save(SOut);
615  TCrossNetH.Save(SOut); ModeIdToNameH.Save(SOut); ModeNameToIdH.Save(SOut); CrossIdToNameH.Save(SOut);
616  CrossNameToIdH.Save(SOut); }
618  static PMMNet Load(TSIn& SIn) { return PMMNet(new TMMNet(SIn)); }
620  static PMMNet LoadShM(TShMIn& ShMIn) {
621  TMMNet* Network = new TMMNet();
622  Network->LoadNetworkShM(ShMIn);
623  return PMMNet(Network);
624  }
625  static PMMNet New() { return PMMNet(new TMMNet()); }
626 
628  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
629  it.GetDat().ConvertToSparse();
630  }
631  }
632 
634  int GetModeId(const TStr& ModeName) const { if (ModeNameToIdH.IsKey(ModeName)) { return ModeNameToIdH.GetDat(ModeName); } else { return -1; } }
636  TStr GetModeName(const TInt& ModeId) const { if (ModeIdToNameH.IsKey(ModeId)) { return ModeIdToNameH.GetDat(ModeId); } else {return TStr::GetNullStr();} }
638  int GetCrossId(const TStr& CrossName) const { if (CrossNameToIdH.IsKey(CrossName)) { return CrossNameToIdH.GetDat(CrossName); } else { return -1; } }
640  TStr GetCrossName(const TInt& CrossId) const { if (CrossIdToNameH.IsKey(CrossId)) { return CrossIdToNameH.GetDat(CrossId); } else { return TStr::GetNullStr(); } }
641 
643  TModeNet& GetModeNetByName(const TStr& ModeName) const;
644  TModeNet& GetModeNetById(const TInt& ModeId) const;
645 
647  TCrossNet& GetCrossNetByName(const TStr& CrossName) const;
648  TCrossNet& GetCrossNetById(const TInt& CrossId) const;
649 
651  TCrossNetI GetCrossNetI(const int& Id) const { return TCrossNetI(TCrossNetH.GetI(Id), this); }
652  TCrossNetI BegCrossNetI() const { return TCrossNetI(TCrossNetH.BegI(), this); }
653  TCrossNetI EndCrossNetI() const { return TCrossNetI(TCrossNetH.EndI(), this); }
654 
656  TModeNetI GetModeNetI(const int& Id) const { return TModeNetI(TModeNetH.GetI(Id), this); }
657  TModeNetI BegModeNetI() const { return TModeNetI(TModeNetH.BegI(), this); }
658  TModeNetI EndModeNetI() const { return TModeNetI(TModeNetH.EndI(), this); }
659 
661  int GetModeNets() { return TModeNetH.Len(); }
663  int GetCrossNets() { return TCrossNetH.Len(); }
664 
666  PMMNet GetSubgraphByCrossNet(TStrV& CrossNetTypes);
668  PMMNet GetSubgraphByModeNet(TStrV& ModeNetTypes);
669 
671  PNEANet ToNetwork(TIntV& CrossNetTypes, TIntStrStrTrV& NodeAttrMap, TVec<TTriple<TInt, TStr, TStr> >& EdgeAttrMap);
673  PNEANet ToNetwork2(TIntV& CrossNetTypes, TIntStrPrVH& NodeAttrMap, THash<TInt, TVec<TPair<TStr, TStr> > >& EdgeAttrMap);
674 
675  #ifdef GCC_ATOMIC
676  PNEANetMP ToNetworkMP(TStrV& CrossNetNames);
677  #endif // GCC_ATOMIC
678 
679 private:
680  void ClrNbr(const TInt& ModeId, const TInt& CrossNetId, const bool& outEdge, const bool& sameMode, bool& isDir);
681  int AddMode(const TStr& ModeName, const TInt& ModeId, const TModeNet& ModeNet);
682  int AddCrossNet(const TStr& CrossNetName, const TInt& CrossNetId, const TCrossNet& CrossNet);
683  int AddNodeAttributes(PNEANet& NewNet, TModeNet& Net, TVec<TPair<TStr, TStr> >& Attrs, int ModeId, int oldId, int NId);
684  int AddEdgeAttributes(PNEANet& NewNet, TCrossNet& Net, TVec<TPair<TStr, TStr> >& Attrs, int CrossId, int oldId, int EId);
685  void GetPartitionRanges(TIntPrV& Partitions, const TInt& NumPartitions, const TInt& MxVal) const;
686 };
687 
688 // set flags
689 namespace TSnap {
690 template <> struct IsMultiGraph<TModeNet> { enum { Val = 1 }; };
691 template <> struct IsDirected<TModeNet> { enum { Val = 1 }; };
692 }
693 #endif // MMNET_H
TCrossNet & GetCrossNet()
Gets a reference to the crossnet.
Definition: mmnet.h:551
Definition: bd.h:440
TVec< TIntV > VecOfIntVecsN
Definition: network.h:2063
TStr GetStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: mmnet.h:417
THash< TStr, TBool > KeyToDenseE
Definition: network.h:2058
TModeNetI GetModeNetI(const int &Id) const
Iterator over all modenets.
Definition: mmnet.h:656
bool operator<(const TNodeI &NodeI) const
Definition: mmnet.h:36
Main namespace for all the Snap global entities.
Definition: alg.h:1
int GetId() const
Returns edge ID.
Definition: mmnet.h:172
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:595
int AddFltAttrDatE(const TCrossEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: mmnet.h:410
void LoadShM(TShMIn &ShMIn)
Loads network from shared memory stream.
Definition: mmnet.h:348
TMMNet(TSIn &SIn)
Definition: mmnet.h:593
TCrossEdgeI(const TCrossEdgeI &EdgeI)
Definition: mmnet.h:165
void LoadNetworkShM(TShMIn &ShMIn)
Definition: mmnet.cpp:649
TCrossNet(TSIn &SIn)
Definition: mmnet.h:286
PNEANet ToNetwork2(TIntV &CrossNetTypes, TIntStrPrVH &NodeAttrMap, THash< TInt, TVec< TPair< TStr, TStr > > > &EdgeAttrMap)
Converts multimodal network to TNEANet; as attr names can collide, AttrMap specifies the Mode/Cross I...
Definition: mmnet.cpp:1028
THash< TStr, TFlt > FltDefaultsE
Definition: network.h:2062
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:427
int AddIntVAttrByVecN(const TStr &attr, TVec< TIntV > &Attrs, TBool UseDense=true)
Adds a new TIntV node attribute to the hashmap.
Definition: mmnet.cpp:124
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: mmnet.h:399
bool operator<(const TCrossNetI &CrossNetI) const
Definition: mmnet.h:544
int GetModeId(const TStr &ModeName) const
Gets the mode id from the mode name.
Definition: mmnet.h:634
int AddIntVAttrByHashN(const TStr &attr, THash< TInt, TIntV > &Attrs)
Definition: mmnet.cpp:144
TStrIntPrH KeyToIndexTypeE
Definition: mmnet.h:271
void operator()(TVec< TElem > *Node, TShMIn &ShMIn)
Definition: mmnet.h:259
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: mmnet.h:250
int AddStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: mmnet.h:407
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: mmnet.h:432
TVec< TStrV > VecOfStrVecsE
Definition: network.h:2064
THash< TStr, TFlt > FltDefaultsE
Definition: mmnet.h:274
THash< TStr, TInt > IntDefaultsE
Definition: network.h:2060
int DelCrossNet(const TInt &CrossNetId)
Deletes a crossnet from the multimodal network.
Definition: mmnet.cpp:708
TModeNet iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:508
TCrossNetI EndCrossNetI() const
Definition: mmnet.h:653
TFltV::TIter TFltVecIter
Definition: mmnet.h:236
TModeNet TNetMM
Definition: mmnet.h:25
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: mmnet.h:395
TInt MxModeId
Definition: mmnet.h:560
const TCrossNet * Graph
Definition: mmnet.h:239
void ConvertToSparse()
Definition: mmnet.h:627
TModeNetI(const THashIter &ModeNetHIter, const TMMNet *GraphPt)
Definition: mmnet.h:515
Node iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:28
TVec< TIntV > VecOfIntVecsE
Definition: mmnet.h:275
Definition: ds.h:130
void GetNeighborsByCrossNet(TStr &Name, TIntV &Neighbors, const bool isOutEId=false)
Gets the neighbors (NIds) for the given node for the given CrossNet type.
Definition: mmnet.h:39
TCrossNet(const TCrossNet &OtherTCrossNet)
Definition: mmnet.h:288
TModeNet & GetModeNet()
Gets a reference to the modenet.
Definition: mmnet.h:527
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:444
TVec< THash< TInt, TIntV > > VecOfIntHashVecsE
Definition: network.h:2068
void GetPartitionRanges(TIntPrV &Partitions, const TInt &NumPartitions, const TInt &MxVal) const
Definition: mmnet.cpp:1115
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
Definition: mmnet.h:373
void Save(TSOut &SOut) const
Definition: dt.h:1153
TStr GetCrossName()
Gets the name of the crossnet.
Definition: mmnet.h:549
PMMNet GetSubgraphByCrossNet(TStrV &CrossNetTypes)
Gets the induced subgraph given a vector of crossnet type names.
Definition: mmnet.cpp:791
THash< TInt, TModeNet >::TIter THashIter
Definition: mmnet.h:510
int GetSrcModeId() const
Returns the source mode of the crossnet.
Definition: mmnet.h:179
THashIter CrossHI
Definition: mmnet.h:160
int GetSrcNId() const
Returns the source of the edge.
Definition: mmnet.h:174
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1794
TNodeI GetMMNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: mmnet.h:86
void DelNode(const int &NId)
Deletes the given node from this mode.
Definition: mmnet.cpp:64
Tests (at compile time) if the graph is directed.
Definition: gbase.h:28
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: mmnet.h:206
TMMNet * MMNet
Definition: mmnet.h:47
TIter BegI() const
Definition: hash.h:213
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: mmnet.h:424
bool operator==(const TCrossEdgeI &EdgeI) const
Definition: mmnet.h:170
TCrossNet()
Definition: mmnet.h:280
TAStrI(const TStrVecIter &HIter, TStr attribute, const TCrossNet *GraphPt)
Definition: mmnet.h:220
TCrossNet iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:532
const TCrossNet * Graph
Definition: mmnet.h:161
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:314
THashIter CrossNetHI
Definition: mmnet.h:535
const TNEANet * Graph
Definition: network.h:1796
void Save(TSOut &SOut) const
Definition: hash.h:183
TStrVecIter HI
Definition: mmnet.h:215
TModeNet(const int &TypeId)
Definition: mmnet.h:52
TStrIntPrH KeyToIndexTypeE
Definition: network.h:2056
TCrossEdgeI BegEdgeI() const
Definition: mmnet.h:335
A single edge in the cross net. Has an Edge Id, and the source and destination node ids...
Definition: mmnet.h:138
bool operator==(const TAIntI &I) const
Definition: mmnet.h:202
TAttr SAttrN
Definition: network.h:2072
TMMNet * Net
Definition: mmnet.h:270
TFlt GetDat() const
Returns an attribute of the node.
Definition: mmnet.h:248
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
Definition: mmnet.h:448
THash< TStr, TFlt > FltDefaultsN
Definition: network.h:2062
bool operator==(const TAStrI &I) const
Definition: mmnet.h:224
TAIntI & operator++(int)
Definition: mmnet.h:207
void Save(TSOut &SOut) const
Definition: dt.h:995
Definition: fl.h:384
int DelNeighbor(const int &NId, const int &EId, bool outEdge, const TStr &CrossName, const bool sameMode, bool isDir)
Definition: mmnet.cpp:51
int GetModeId()
Gets the mode id.
Definition: mmnet.h:523
TInt MxNId
Definition: network.h:2052
TModeNet(const int &Nodes, const int &Edges, const int &TypeId)
Definition: mmnet.h:56
static PMMNet Load(TSIn &SIn)
Loads the TMMNet from binary stream.
Definition: mmnet.h:618
TAStrI GetEAStrI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: mmnet.h:444
bool operator<(const TAStrI &I) const
Definition: mmnet.h:223
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:157
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1792
TVec< TIntV > VecOfIntVecsE
Definition: network.h:2063
TIter EndI() const
Definition: hash.h:218
TCrossEdge & GetEdge(int eid)
Definition: mmnet.h:320
void Load(TSIn &SIn)
Definition: ds.h:946
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
int DelEdge(const int &EId)
Deletes an edge by its id.
Definition: mmnet.cpp:301
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: mmnet.h:440
int DelAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
Definition: mmnet.h:461
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
TCRef CRef
Definition: mmnet.h:556
int DelModeNet(const TInt &ModeId)
Deletes a mode from the multimodal network.
Definition: mmnet.cpp:727
bool operator==(const TModeNetI &ModeNetI) const
Definition: mmnet.h:521
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: mmnet.h:428
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:431
TCrossEdgeI EndEdgeI() const
Definition: mmnet.h:336
const TCrossNet * Graph
Definition: mmnet.h:195
int GetDstNId() const
Definition: mmnet.h:152
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:318
TCrossNetI BegCrossNetI() const
Definition: mmnet.h:652
bool operator<(const TAIntI &I) const
Definition: mmnet.h:201
TCrossEdgeI & operator=(const TCrossEdgeI &EdgeI)
Definition: mmnet.h:166
TModeNet(const TModeNet &Graph)
Definition: mmnet.h:58
Definition: dt.h:1386
TVec< TStrV > VecOfStrVecsN
Definition: network.h:2064
TNodeI & operator=(const TNodeI &NodeI)
Definition: mmnet.h:33
TCrossNet(TInt MId1, TInt MId2, TBool IsDir, TInt LId)
Definition: mmnet.h:284
Definition: fl.h:58
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
Definition: mmnet.h:437
void Save(TSOut &SOut) const
Definition: ds.h:954
TCrossEdge(const int &Id, const int &SourceNId, const int &DestNId)
Definition: mmnet.h:144
PNEANet ToNetwork(TIntV &CrossNetTypes, TIntStrStrTrV &NodeAttrMap, TVec< TTriple< TInt, TStr, TStr > > &EdgeAttrMap)
Converts multimodal network to TNEANet; as attr names can collide, AttrMap specifies the (Mode/Cross ...
Definition: mmnet.cpp:866
bool operator==(const TAFltI &I) const
Definition: mmnet.h:246
THash< TInt, TEdge > EdgeH
Definition: network.h:2054
void GetNeighborsByCrossNet(const int &NId, TStr &Name, TIntV &Neighbors, const bool isOutEId=false) const
For the given node, gets all the neighbors for the crossnet type. If this mode is both the source and...
Definition: mmnet.cpp:113
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: mmnet.h:381
TCrossNetI(const TCrossNetI &CrossNetI)
Definition: mmnet.h:540
int AddCrossNet(const TStr &ModeName1, const TStr &ModeName2, const TStr &CrossNetName, bool isDir=true)
Adds a crossnet to the multimodal network. Specify modes by id or names; by default, crossnet is directed.
Definition: mmnet.cpp:683
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
Definition: mmnet.h:234
int AddModeNet(const TStr &ModeName)
Adds a mode to the multimodal network.
Definition: mmnet.cpp:668
TModeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
Definition: mmnet.h:54
int GetCrossNets()
Returns the number of crossnets in the multimodal network.
Definition: mmnet.h:663
THash< TStr, TStr > StrDefaultsE
Definition: mmnet.h:273
TModeNet & operator=(const TModeNet &Graph)
Definition: mmnet.h:91
int GetId() const
Definition: mmnet.h:150
TAttr SAttrE
Definition: network.h:2073
const TMMNet * Graph
Definition: mmnet.h:536
int GetId() const
Returns ID of the current node.
Definition: network.h:1807
static const int Mn
Definition: dt.h:1141
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: mmnet.h:228
TVec< TStrV > VecOfStrVecsE
Definition: mmnet.h:276
TNodeI EndMMNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: mmnet.h:84
int AddIntAttrDatE(const TCrossEdgeI &EdgeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: mmnet.h:404
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
TCrossNetI GetCrossNetI(const int &Id) const
Iterator over all crossnets.
Definition: mmnet.h:651
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: mmnet.h:387
TVec< TFltV > VecOfFltVecsE
Definition: network.h:2065
TInt ModeId
Definition: mmnet.h:46
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:2056
void GetCrossNetNames(TStrV &Names)
Gets all the CrossNets that include the given node.
Definition: mmnet.h:42
void GetCrossNetNames(TStrV &Names) const
Gets a list of CrossNets that have this Mode as either a source or destination type.
Definition: mmnet.h:77
TAFltI GetEAFltI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: mmnet.h:456
TAFltI & operator=(const TAFltI &I)
Definition: mmnet.h:244
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:342
TAFltI & operator++(int)
Definition: mmnet.h:251
TFltVecIter HI
Definition: mmnet.h:237
TAFltI(const TFltVecIter &HIter, TStr attribute, const TCrossNet *GraphPt)
Definition: mmnet.h:242
void RemoveCrossNets(TModeNet &Result, TStrV &CrossNets)
Definition: mmnet.cpp:157
TCrossNet(TInt MId1, TInt MId2, TInt LId)
Definition: mmnet.h:282
int GetSrcNId() const
Definition: mmnet.h:151
TCrossEdge(const TCrossEdge &MultiEdge)
Definition: mmnet.h:146
bool operator==(const TNodeI &NodeI) const
Definition: mmnet.h:37
THash< TInt, TCrossNet >::TIter THashIter
Definition: mmnet.h:534
TCrossEdgeI & operator++(int)
Increment iterator.
Definition: mmnet.h:168
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
Definition: mmnet.h:190
THashIter ModeNetHI
Definition: mmnet.h:511
int AddNbrType(const TStr &CrossName, const bool sameMode, bool isDir)
Definition: mmnet.cpp:89
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
Definition: mmnet.cpp:587
int GetModeNets()
Returns the number of modes in the multimodal network.
Definition: mmnet.h:661
TInt GetDat() const
Returns an attribute of the node.
Definition: mmnet.h:204
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: mmnet.h:452
TMMNet()
Definition: mmnet.h:590
bool operator<(const TCrossEdgeI &EdgeI) const
Definition: mmnet.h:169
THash< TStr, TStr > StrDefaultsN
Definition: network.h:2061
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Definition: mmnet.cpp:606
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
Definition: gbase.h:30
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
Definition: mmnet.h:212
TInt CrossNetId
Definition: mmnet.h:269
int DelNbrType(const TStr &CrossName)
Definition: mmnet.cpp:97
TStr GetModeName(const TInt &ModeId) const
Gets the mode name from the mode id.
Definition: mmnet.h:636
TNodeI BegMMNI() const
Returns an iterator referring to the first node in the graph.
Definition: mmnet.h:82
bool operator<(const TAFltI &I) const
Definition: mmnet.h:245
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:438
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:450
TCrossNetI & operator=(const TCrossNetI &CrossNetI)
Definition: mmnet.h:541
TModeNetI EndModeNetI() const
Definition: mmnet.h:658
void Clr()
Deletes all nodes and edges from the graph.
Definition: mmnet.cpp:219
TStr GetCrossName(const TInt &CrossId) const
Gets the crossnet name from the crossnet id.
Definition: mmnet.h:640
const TCrossNet * Graph
Definition: mmnet.h:217
int GetDstNId() const
Returns the destination of the edge.
Definition: mmnet.h:176
void LoadShM(TShMIn &ShMIn)
Loads graph from shared memory.
Definition: mmnet.h:68
PNEANetMP ToNetworkMP(TStrV &CrossNetNames)
Definition: mmnet.cpp:1136
TVec< TVec< TIntV > > VecOfIntVecVecsE
Definition: network.h:2066
static TStr GetNullStr()
Definition: dt.cpp:1626
TStr GetDat() const
Returns an attribute of the node.
Definition: mmnet.h:226
THash< TStr, TInt > IntDefaultsE
Definition: mmnet.h:272
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:419
TStrV::TIter TStrVecIter
Definition: mmnet.h:214
int AddNodeAttributes(PNEANet &NewNet, TModeNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int ModeId, int oldId, int NId)
Definition: mmnet.cpp:1314
int GetCrossId()
Gets the crossnet id.
Definition: mmnet.h:547
Directed multigraph with node edge attributes.
Definition: network.h:1741
Definition: fl.h:128
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
void LoadNetworkShM(TShMIn &ShMIn)
load network from shared memory for this network
Definition: network.cpp:2
void Save(TSOut &SOut) const
Saves the TMMNet to binary stream.
Definition: mmnet.h:614
TInt MxEId
Definition: network.h:2052
TMMNet(const TMMNet &OtherTMMNet)
Definition: mmnet.h:591
THash< TInt, TCrossEdge >::TIter THashIter
Definition: mmnet.h:159
TModeNetI & operator=(const TModeNetI &ModeNetI)
Definition: mmnet.h:517
void ClrNbr(const TStr &CrossNetName, const bool &outEdge, const bool &sameMode, bool &isDir)
Definition: mmnet.cpp:14
TAFltI(const TAFltI &I)
Definition: mmnet.h:243
void operator()(TModeNet *Node, TShMIn &ShMIn)
Definition: mmnet.h:579
TModeNet()
Definition: mmnet.h:51
const TMMNet * Graph
Definition: mmnet.h:512
Definition: dt.h:1137
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:432
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TNodeI & operator++(int)
Increments the iterator.
Definition: mmnet.h:35
bool operator==(const TCrossNetI &CrossNetI) const
Definition: mmnet.h:545
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
static PMMNet New()
Definition: mmnet.h:625
static PMMNet LoadShM(TShMIn &ShMIn)
Loads network from mmapped shared memory.
Definition: mmnet.h:620
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: mmnet.h:369
TPt< TMMNet > PMMNet
Definition: mmnet.h:5
void Save(TSOut &SOut) const
Saves the TCrossNet to the binary stream.
Definition: mmnet.h:344
TModeNet(const TModeNet &Graph, bool isSubModeGraph)
Definition: mmnet.h:62
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:325
THash< TStr, TBool > NeighborTypes
Definition: mmnet.h:48
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: mmnet.h:377
TCrossNetI & operator++(int)
Increments iterator.
Definition: mmnet.h:543
TModeNetI BegModeNetI() const
Definition: mmnet.h:657
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
Definition: ds.h:932
void Save(TSOut &SOut) const
Definition: mmnet.h:149
Definition: ds.h:32
int GetEdges() const
Returns the number of edges in the graph.
Definition: mmnet.h:327
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753
TCrossEdge(TSIn &SIn)
Definition: mmnet.h:148
bool IsDirected() const
Returns whether the edge is directed.
Definition: mmnet.h:183
TModeNetI & operator++(int)
Increment iterator.
Definition: mmnet.h:519
int GetMxEId() const
Definition: mmnet.h:325
THash< TStr, TStr > StrDefaultsE
Definition: network.h:2061
size_t GetMemUsed() const
Definition: mmnet.h:153
int AddEdge(const int &sourceNId, const int &destNId, int EId=-1)
Adds an edge to the CrossNet; Mode1 NId should be the sourceNId always, regardless of whether edge is...
Definition: mmnet.cpp:233
void GetKeyV(TVec< TKey > &KeyV) const
Definition: hash.h:484
TFlt GetFltAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: mmnet.h:420
TAStrI(const TAStrI &I)
Definition: mmnet.h:221
TModeNet(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
Definition: mmnet.h:60
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:2187
TAStrI & operator=(const TAStrI &I)
Definition: mmnet.h:222
Definition: dt.h:412
int GetMemUsed() const
Definition: dt.h:1169
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:423
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:593
TInt Mode1
Definition: mmnet.h:266
TInt Mode2
The first mode. In the case of directed crossnets, this is implicitly understood to be the source mod...
Definition: mmnet.h:267
TVec< TFltV > VecOfFltVecsN
Definition: network.h:2065
TNodeI(const THashIter &NodeHIter, const TModeNet *GraphPt)
Definition: mmnet.h:31
TCrossEdgeI GetEdgeI(const int &EId) const
Edge iterators.
Definition: mmnet.h:334
int GetCrossId(const TStr &CrossName) const
Gets the crossnet id from the crossnet name.
Definition: mmnet.h:638
bool operator<(const TModeNetI &ModeNetI) const
Definition: mmnet.h:520
TVec< THash< TInt, TIntV > > VecOfIntHashVecsN
Definition: network.h:2068
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:340
TVal2 Val2
Definition: ds.h:35
TStr GetNeighborCrossName(const TStr &CrossName, bool isOutEdge, const bool sameMode, bool isDir) const
Definition: mmnet.cpp:3
TBool IsDirect
The second mode. In the case of directed crossnets, this is implicitly understood to be the destinati...
Definition: mmnet.h:268
Definition: bd.h:196
THash< TStr, TInt > IntDefaultsN
Definition: network.h:2060
void operator()(TCrossNet *Node, TShMIn &ShMIn)
Definition: mmnet.h:585
TAIntI(const TIntVecIter &HIter, TStr attribute, const TCrossNet *GraphPt)
Definition: mmnet.h:198
TAIntI & operator=(const TAIntI &I)
Definition: mmnet.h:200
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:412
THash< TInt, TNode > NodeH
Definition: network.h:2053
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
Definition: mmnet.cpp:625
TModeNetI(const TModeNetI &ModeNetI)
Definition: mmnet.h:516
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: mmnet.h:323
TVec< TVec< TIntV > > VecOfIntVecVecsN
Definition: network.h:2066
int AddMode(const TStr &ModeName, const TInt &ModeId, const TModeNet &ModeNet)
Definition: mmnet.cpp:768
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
Definition: mmnet.cpp:567
TVec< TFltV > VecOfFltVecsE
Definition: mmnet.h:277
TInt MxEId
The HashTable from Edge id to the corresponding Edge.
Definition: mmnet.h:265
void ClrNbr(const TInt &ModeId, const TInt &CrossNetId, const bool &outEdge, const bool &sameMode, bool &isDir)
Definition: mmnet.cpp:786
THashIter NodeHI
Definition: network.h:1795
TIntV::TIter TIntVecIter
Definition: mmnet.h:192
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:456
TCrossNet & GetCrossNetByName(const TStr &CrossName) const
Gets a reference to the crossnet.
Definition: mmnet.cpp:758
bool IsKey(const TKey &Key) const
Definition: hash.h:258
int AddEdgeAttributes(PNEANet &NewNet, TCrossNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int CrossId, int oldId, int EId)
Definition: mmnet.cpp:1341
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
Definition: mmnet.h:65
Definition: dt.h:974
TStr GetModeName()
Gets the name of the mode.
Definition: mmnet.h:525
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
TNodeI(const TNodeI &NodeI)
Definition: mmnet.h:32
THash< TInt, TCrossEdge > CrossH
Definition: mmnet.h:264
int Len() const
Definition: hash.h:228
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:597
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:762
TInt GetIntAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: mmnet.h:414
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:367
TIntVecIter HI
Definition: mmnet.h:193
TCrossNetI(const THashIter &CrossNetHIter, const TMMNet *GraphPt)
Definition: mmnet.h:539
PMMNet GetSubgraphByModeNet(TStrV &ModeNetTypes)
Gets the induced subgraph given a vector of mode type names.
Definition: mmnet.cpp:834
TAIntI(const TAIntI &I)
Definition: mmnet.h:199
THash< TStr, TBool > KeyToDenseN
KeyToDense[N|E]: Key->(True if Vec, False if Hash)
Definition: network.h:2058
TCrossEdgeI(const THashIter &CrossHIter, const TCrossNet *GraphPt)
Definition: mmnet.h:164
TModeNet & GetModeNetByName(const TStr &ModeName) const
Gets a reference to the modenet.
Definition: mmnet.cpp:748
TCrossNet & operator=(const TCrossNet &OtherTCrossNet)
Definition: mmnet.h:293
void Clr()
Deletes all nodes from this mode and edges from associated crossnets.
Definition: mmnet.cpp:29
int GetAttrTypeN(const TStr &attr) const
Definition: mmnet.cpp:204
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:85
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: mmnet.h:391
int GetAttrTypeE(const TStr &attr) const
Definition: mmnet.cpp:212
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:316
int GetDstModeId() const
Returns the destination mode of the crossnet.
Definition: mmnet.h:181
static const double Mn
Definition: dt.h:1390
Multimodal networks.
Definition: mmnet.h:504
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568
TIter GetI(const TKey &Key) const
Definition: hash.h:220
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133
int AddNeighbor(const int &NId, const int &EId, const bool outEdge, const int linkId, const bool sameMode, bool isDir)
Definition: mmnet.cpp:38
TAStrI & operator++(int)
Definition: mmnet.h:229