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
mmnet.cpp
Go to the documentation of this file.
1 // Mutimodal Network
3 TStr TModeNet::GetNeighborCrossName(const TStr& CrossName, bool isOutEdge, const bool sameMode, bool isDir) const {
4  TStr Cpy(CrossName);
5  if (!isDir || !sameMode) { return Cpy; }
6  if (isOutEdge) {
7  Cpy += ":SRC";
8  } else {
9  Cpy += ":DST";
10  }
11  return Cpy;
12 }
13 
14 void TModeNet::ClrNbr(const TStr& CrossNetName, const bool& outEdge, const bool& sameMode, bool& isDir) {
15  TStr Name = GetNeighborCrossName(CrossNetName, outEdge, sameMode, isDir);
16  TInt location = CheckDenseOrSparseN(Name);
17  int index = KeyToIndexTypeN.GetDat(Name).Val2;
18  if (location == 1) {
19  TVec<TIntV> Attrs(MxNId);
20  VecOfIntVecVecsN[index] = Attrs;
21  } else {
22  THash<TInt, TIntV> Attrs;
23  VecOfIntHashVecsN[index] = Attrs;
24  }
25 
26 
27 }
28 
29 void TModeNet::Clr() {
30  TStrV CNets;
31  NeighborTypes.GetKeyV(CNets);
32  for (int i=0; i < CNets.Len(); i++) {
33  MMNet->GetCrossNetByName(CNets[i]).Clr();
34  }
35  TNEANet::Clr();
36 }
37 
38 int TModeNet::AddNeighbor(const int& NId, const int& EId, bool outEdge, const int linkId, const bool sameMode, bool isDir){
39  TStr CrossName = MMNet->GetCrossName(linkId);
40  return AddNeighbor(NId, EId, outEdge, CrossName, sameMode, isDir);
41 }
42 
43 int TModeNet::AddNeighbor(const int& NId, const int& EId, bool outEdge, const TStr& CrossName, const bool sameMode, bool isDir){
44  if (!NeighborTypes.IsKey(CrossName)) {
45  AddNbrType(CrossName, sameMode, isDir);
46  }
47  TStr Name = GetNeighborCrossName(CrossName, outEdge, sameMode, isDir);
48  return AppendIntVAttrDatN(NId, EId, Name);
49 }
50 
51 int TModeNet::DelNeighbor(const int& NId, const int& EId, bool outEdge, const TStr& CrossName, const bool sameMode, bool isDir){
52  if (!NeighborTypes.IsKey(CrossName)) {
53  return -1;
54  }
55  TStr Name = GetNeighborCrossName(CrossName, outEdge, sameMode, isDir);
56  return DelFromIntVAttrDatN(NId, EId, Name);
57 }
58 
59 int TModeNet::DelNeighbor(const int& NId, const int& EId, bool outEdge, const TInt& linkId, const bool sameMode, bool isDir){
60  TStr CrossName = MMNet->GetCrossName(linkId);
61  return DelNeighbor(NId, EId, outEdge, CrossName, sameMode, isDir);
62 }
63 
64 void TModeNet::DelNode(const int& NId) {
65  TStrV Names;
66  GetCrossNetNames(Names);
67  for (int i=0; i < Names.Len(); i++) {
68  TCrossNet& Cross = MMNet->GetCrossNetByName(Names[i]);
69  TIntV OutEIds;
70  GetNeighborsByCrossNet(NId, Names[i], OutEIds, true);
71  for (int j=0; j < OutEIds.Len(); j++) {
72  Cross.DelEdge(OutEIds[j].Val);
73  }
74  if (Cross.IsDirect && Cross.Mode1 == Cross.Mode2) {
75  TIntV InEIds;
76  GetNeighborsByCrossNet(NId, Names[i], InEIds, false);
77  for (int j=0; j < InEIds.Len(); j++) {
78  Cross.DelEdge(InEIds[j].Val);
79  }
80  }
81  }
82  TNEANet::DelNode(NId);
83 }
84 
86  MMNet = parent;
87 }
88 
89 int TModeNet::AddNbrType(const TStr& CrossName, const bool sameMode, bool isDir) {
90  //IAssertR(!NeighborTypes.IsKey(CrossName),TStr::Fmt("Neighbor Cross Types already exists: %s", CrossName.CStr()));
91  if (NeighborTypes.IsKey(CrossName)) { return -1; } //Don't want to add nbr type multiple times
92  bool hasSingleVector = (!isDir || !sameMode);
93  NeighborTypes.AddDat(CrossName, hasSingleVector);
94  return 0;
95 }
96 
97 int TModeNet::DelNbrType(const TStr& CrossName) {
98  //IAssertR(!NeighborTypes.IsKey(CrossName),TStr::Fmt("Neighbor Cross Types already exists: %s", CrossName.CStr()));
99  bool hasSingleVector = NeighborTypes.GetDat(CrossName);
100  NeighborTypes.DelKey(CrossName);
101  if (hasSingleVector) {
102  return DelAttrN(CrossName);
103  } else {
104  TStr InName = GetNeighborCrossName(CrossName, true, true, true);
105  TStr OutName = GetNeighborCrossName(CrossName, false, true, true);
106  if (DelAttrN(InName) == -1 || DelAttrN(OutName) == -1) {
107  return -1;
108  }
109  }
110  return 0;
111 }
112 
113 void TModeNet::GetNeighborsByCrossNet(const int& NId, TStr& Name, TIntV& Neighbors, const bool isOutEId) const{
114  //IAssertR(NeighborTypes.IsKey(Name), TStr::Fmt("Cross Type does not exist: %s", Name));
115  TBool hasSingleVector = NeighborTypes.GetDat(Name);
116  if (hasSingleVector) {
117  Neighbors = GetIntVAttrDatN(NId, Name);
118  } else {
119  TStr DirectionalName = GetNeighborCrossName(Name, isOutEId, true, true);
120  Neighbors = GetIntVAttrDatN(NId, DirectionalName);
121  }
122 }
123 
124 int TModeNet::AddIntVAttrByVecN(const TStr& attr, TVec<TIntV>& Attrs, TBool UseDense){
125  TInt CurrLen;
126  if (UseDense) {
127  CurrLen = VecOfIntVecVecsN.Len();
128  KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
129  KeyToDenseN.AddDat(attr, true);
130  VecOfIntVecVecsN.Add(Attrs);
131  } else {
132  THash<TInt, TIntV> NewHash;
133  CurrLen = VecOfIntHashVecsN.Len();
134  KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
135  KeyToDenseN.AddDat(attr, false);
136  for (int i=0; i< Attrs.Len(); i++) {
137  NewHash.AddDat(i, Attrs[i]);
138  }
139  VecOfIntHashVecsN.Add(NewHash);
140  }
141  return 0;
142 }
143 
145  TInt CurrLen;
146  THash<TInt, TIntV> NewHash;
147  CurrLen = VecOfIntHashVecsN.Len();
148  KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
149  KeyToDenseN.AddDat(attr, false);
150  for (int i=0; i< Attrs.Len(); i++) {
151  NewHash.AddDat(i, Attrs[i]);
152  }
153  VecOfIntHashVecsN.Add(NewHash);
154  return 0;
155 }
156 
157 void TModeNet::RemoveCrossNets(TModeNet& Result, TStrV& CrossNets) {
158  const TModeNet& self = *this;
159  Result = TModeNet(self, false);
160  for (TStrIntPrH::TIter it = KeyToIndexTypeN.BegI(); it < KeyToIndexTypeN.EndI(); it++) {
161  TStr AttrName = it.GetKey();
162  TInt AttrType = it.GetDat().GetVal1();
163  TInt AttrIndex = it.GetDat().GetVal2();
164  if (AttrType != IntVType) {
165  Result.KeyToIndexTypeN.AddDat(AttrName, it.GetDat());
166  } else {
167  TStr WithoutSuffix = AttrName;
168  bool removeSuffix = false;
169  if (AttrName.IsSuffix(":SRC") || AttrName.IsSuffix(":DST")) {
170  WithoutSuffix = AttrName.GetSubStr(0, AttrName.Len()-5);
171  removeSuffix = true;
172  }
173  bool isSingleVNbrAttr = (NeighborTypes.IsKey(AttrName) && NeighborTypes.GetDat(AttrName));
174  bool isMultiVNbrAttr = (removeSuffix && NeighborTypes.IsKey(WithoutSuffix) && !NeighborTypes.GetDat(WithoutSuffix));
175  if (isSingleVNbrAttr || isMultiVNbrAttr) {
176  TStr NbrName = isSingleVNbrAttr ? AttrName : WithoutSuffix;
177  if (CrossNets.IsIn(NbrName)) {
178  Result.AddNbrType(NbrName, removeSuffix, removeSuffix);
179  TInt location = CheckDenseOrSparseN(AttrName);
180  if (location == 1) {
181  TVec<TIntV>& Attrs = VecOfIntVecVecsN[AttrIndex];
182  Result.AddIntVAttrByVecN(AttrName, Attrs);
183  } else {
184  THash<TInt, TIntV>& Attrs = VecOfIntHashVecsN[AttrIndex];
185  Result.AddIntVAttrByHashN(AttrName, Attrs);
186  }
187 
188  }
189  } else {
190  TInt location = CheckDenseOrSparseN(AttrName);
191  if (location == 1) {
192  TVec<TIntV>& Attrs = VecOfIntVecVecsN[AttrIndex];
193  Result.AddIntVAttrByVecN(AttrName, Attrs);
194  } else {
195  THash<TInt, TIntV>& Attrs = VecOfIntHashVecsN[AttrIndex];
196  Result.AddIntVAttrByHashN(AttrName, Attrs);
197  }
198 
199  }
200  }
201  }
202 }
203 
204 int TModeNet::GetAttrTypeN(const TStr& attr) const {
205  if (KeyToIndexTypeN.IsKey(attr)) {
206  return KeyToIndexTypeN.GetDat(attr).Val1;
207  }
208  return -1;
209 }
210 
211 
212 int TCrossNet::GetAttrTypeE(const TStr& attr) const {
213  if (KeyToIndexTypeE.IsKey(attr)) {
214  return KeyToIndexTypeE.GetDat(attr).Val1;
215  }
216  return -1;
217 }
218 
220  CrossH.Clr();
221  MxEId=0;
223  IntDefaultsE.Clr();
224  StrDefaultsE.Clr();
225  FltDefaultsE.Clr();
226  VecOfIntVecsE.Clr();
227  VecOfStrVecsE.Clr();
228  VecOfFltVecsE.Clr();
231 }
232 
233 int TCrossNet::AddEdge(const int& sourceNId, const int& destNId, int EId){
234  if (EId == -1) { EId = MxEId; MxEId++; }
235  else { MxEId = TMath::Mx(EId+1, MxEId()); }
236  if (Net != NULL) {
237  TModeNet& M1 = Net->TModeNetH.GetDat(this->Mode1);
238  TModeNet& M2 = Net->TModeNetH.GetDat(this->Mode2);
239  if (!M1.IsNode(sourceNId) || !M2.IsNode(destNId)) { return -1; }
240  TStr ThisCrossName = Net->GetCrossName(this->CrossNetId);
241  M1.AddNeighbor(sourceNId, EId, true, ThisCrossName, Mode1==Mode2, IsDirect);
242  M2.AddNeighbor(destNId, EId, false, ThisCrossName, Mode1==Mode2, IsDirect);
243  }
244  TCrossNet::TCrossEdge newEdge(EId, sourceNId, destNId);
245  CrossH.AddDat(EId, newEdge);
246  int i;
247  // update attribute columns
248  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
249  TVec<TInt>& IntVec = VecOfIntVecsE[i];
250  int KeyId = CrossH.GetKeyId(EId);
251  if (IntVec.Len() > KeyId) {
252  IntVec[KeyId] = TInt::Mn;
253  } else {
254  IntVec.Ins(KeyId, TInt::Mn);
255  }
256  }
257  TVec<TStr> DefIntVec = TVec<TStr>();
258  IntDefaultsE.GetKeyV(DefIntVec);
259  for (i = 0; i < DefIntVec.Len(); i++) {
260  TStr attr = DefIntVec[i];
261  TVec<TInt>& IntVec = VecOfIntVecsE[KeyToIndexTypeE.GetDat(DefIntVec[i]).Val2];
262  IntVec[CrossH.GetKeyId(EId)] = GetIntAttrDefaultE(attr);
263  }
264 
265  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
266  TVec<TStr>& StrVec = VecOfStrVecsE[i];
267  int KeyId = CrossH.GetKeyId(EId);
268  if (StrVec.Len() > KeyId) {
269  StrVec[KeyId] = TStr::GetNullStr();
270  } else {
271  StrVec.Ins(KeyId, TStr::GetNullStr());
272  }
273  }
274  TVec<TStr> DefStrVec = TVec<TStr>();
275  StrDefaultsE.GetKeyV(DefStrVec);
276  for (i = 0; i < DefStrVec.Len(); i++) {
277  TStr attr = DefStrVec[i];
278  TVec<TStr>& StrVec = VecOfStrVecsE[KeyToIndexTypeE.GetDat(DefStrVec[i]).Val2];
279  StrVec[CrossH.GetKeyId(EId)] = GetStrAttrDefaultE(attr);
280  }
281 
282  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
283  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
284  int KeyId = CrossH.GetKeyId(EId);
285  if (FltVec.Len() > KeyId) {
286  FltVec[KeyId] = TFlt::Mn;
287  } else {
288  FltVec.Ins(KeyId, TFlt::Mn);
289  }
290  }
291  TVec<TStr> DefFltVec = TVec<TStr>();
292  FltDefaultsE.GetKeyV(DefFltVec);
293  for (i = 0; i < DefFltVec.Len(); i++) {
294  TStr attr = DefFltVec[i];
295  TVec<TFlt>& FltVec = VecOfFltVecsE[KeyToIndexTypeE.GetDat(DefFltVec[i]).Val2];
296  FltVec[CrossH.GetKeyId(EId)] = GetFltAttrDefaultE(attr);
297  }
298  return EId;
299 }
300 
301 int TCrossNet::DelEdge(const int& EId) {
302  TCrossEdge& Edge = CrossH.GetDat(EId);
303  int srcNode = Edge.SrcNId;
304  int dstNode = Edge.DstNId;
305  TStr ThisCrossName = Net->GetCrossName(this->CrossNetId);
306  Net->GetModeNetById(this->Mode1).DelNeighbor(srcNode, EId, true, ThisCrossName, Mode1==Mode2, IsDirect);
307  Net->GetModeNetById(this->Mode2).DelNeighbor(dstNode, EId, false, ThisCrossName, Mode1==Mode2, IsDirect);
308  int i;
309  for (i = 0; i < VecOfIntVecsE.Len(); i++) {
310  TVec<TInt>& IntVec = VecOfIntVecsE[i];
311  IntVec[CrossH.GetKeyId(EId)] = TInt::Mn;
312  }
313  for (i = 0; i < VecOfStrVecsE.Len(); i++) {
314  TVec<TStr>& StrVec = VecOfStrVecsE[i];
315  StrVec[CrossH.GetKeyId(EId)] = TStr::GetNullStr();
316  }
317  for (i = 0; i < VecOfFltVecsE.Len(); i++) {
318  TVec<TFlt>& FltVec = VecOfFltVecsE[i];
319  FltVec[CrossH.GetKeyId(EId)] = TFlt::Mn;
320  }
321  CrossH.DelKey(EId);
322  return 0;
323 }
324 
326  Net = parent;
327 }
328 
329 void TCrossNet::AttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const {
330  Names = TVec<TStr>();
331  while (!CrossHI.IsEnd()) {
332  if (!EdgeAttrIsDeleted(EId, CrossHI)) {
333  Names.Add(CrossHI.GetKey());
334  }
335  CrossHI++;
336  }
337 }
338 
339 void TCrossNet::AttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Values) const {
340  Values = TVec<TStr>();
341  while (!CrossHI.IsEnd()) {
342  if (!EdgeAttrIsDeleted(EId, CrossHI)) {
343  Values.Add(GetEdgeAttrValue(EId, CrossHI));
344  }
345  CrossHI++;
346  }
347 }
348 
349 void TCrossNet::IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const {
350  Names = TVec<TStr>();
351  while (!CrossHI.IsEnd()) {
352  if (CrossHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, CrossHI)) {
353  Names.Add(CrossHI.GetKey());
354  }
355  CrossHI++;
356  }
357 }
358 
359 void TCrossNet::IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TIntV& Values) const {
360  Values = TVec<TInt>();
361  while (!CrossHI.IsEnd()) {
362  if (CrossHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, CrossHI)) {
363  TInt val = (this->VecOfIntVecsE.GetVal(CrossHI.GetDat().Val2).GetVal(EId));
364  Values.Add(val);
365  }
366  CrossHI++;
367  }
368 }
369 
370 void TCrossNet::StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const {
371  Names = TVec<TStr>();
372  while (!CrossHI.IsEnd()) {
373  if (CrossHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, CrossHI)) {
374  Names.Add(CrossHI.GetKey());
375  }
376  CrossHI++;
377  }
378 }
379 
380 void TCrossNet::StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Values) const {
381  Values = TVec<TStr>();
382  while (!CrossHI.IsEnd()) {
383  if (CrossHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, CrossHI)) {
384  TStr val = this->VecOfStrVecsE.GetVal(CrossHI.GetDat().Val2).GetVal(EId);
385  Values.Add(val);
386  }
387  CrossHI++;
388  }
389 }
390 
391 void TCrossNet::FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TStrV& Names) const {
392  Names = TVec<TStr>();
393  while (!CrossHI.IsEnd()) {
394  if (CrossHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, CrossHI)) {
395  Names.Add(CrossHI.GetKey());
396  }
397  CrossHI++;
398  }
399 }
400 
401 void TCrossNet::FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter CrossHI, TFltV& Values) const {
402  Values = TVec<TFlt>();
403  while (!CrossHI.IsEnd()) {
404  if (CrossHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, CrossHI)) {
405  TFlt val = (this->VecOfFltVecsE.GetVal(CrossHI.GetDat().Val2).GetVal(EId));
406  Values.Add(val);
407  }
408  CrossHI++;
409  }
410 }
411 
412 bool TCrossNet::IsAttrDeletedE(const int& EId, const TStr& attr) const {
413  bool IntDel = IsIntAttrDeletedE(EId, attr);
414  bool StrDel = IsStrAttrDeletedE(EId, attr);
415  bool FltDel = IsFltAttrDeletedE(EId, attr);
416  return IntDel || StrDel || FltDel;
417 }
418 
419 bool TCrossNet::IsIntAttrDeletedE(const int& EId, const TStr& attr) const {
420  return EdgeAttrIsIntDeleted(EId, KeyToIndexTypeE.GetI(attr));
421 }
422 
423 bool TCrossNet::IsStrAttrDeletedE(const int& EId, const TStr& attr) const {
424  return EdgeAttrIsStrDeleted(EId, KeyToIndexTypeE.GetI(attr));
425 }
426 
427 bool TCrossNet::IsFltAttrDeletedE(const int& EId, const TStr& attr) const {
428  return EdgeAttrIsFltDeleted(EId, KeyToIndexTypeE.GetI(attr));
429 }
430 
431 bool TCrossNet::EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const {
432  bool IntDel = EdgeAttrIsIntDeleted(EId, CrossHI);
433  bool StrDel = EdgeAttrIsStrDeleted(EId, CrossHI);
434  bool FltDel = EdgeAttrIsFltDeleted(EId, CrossHI);
435  return IntDel || StrDel || FltDel;
436 }
437 
438 bool TCrossNet::EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const {
439  return (CrossHI.GetDat().Val1 == IntType &&
440  GetIntAttrDefaultE(CrossHI.GetKey()) == this->VecOfIntVecsE.GetVal(
441  this->KeyToIndexTypeE.GetDat(CrossHI.GetKey()).Val2).GetVal(CrossH.GetKeyId(EId)));
442 }
443 
444 bool TCrossNet::EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const {
445  return (CrossHI.GetDat().Val1 == StrType &&
446  GetStrAttrDefaultE(CrossHI.GetKey()) == this->VecOfStrVecsE.GetVal(
447  this->KeyToIndexTypeE.GetDat(CrossHI.GetKey()).Val2).GetVal(CrossH.GetKeyId(EId)));
448 }
449 
450 bool TCrossNet::EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& CrossHI) const {
451  return (CrossHI.GetDat().Val1 == FltType &&
452  GetFltAttrDefaultE(CrossHI.GetKey()) == this->VecOfFltVecsE.GetVal(
453  this->KeyToIndexTypeE.GetDat(CrossHI.GetKey()).Val2).GetVal(CrossH.GetKeyId(EId)));
454 }
455 
456 TStr TCrossNet::GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& CrossHI) const {
457  if (CrossHI.GetDat().Val1 == IntType) {
458  return (this->VecOfIntVecsE.GetVal(
459  this->KeyToIndexTypeE.GetDat(CrossHI.GetKey()).Val2).GetVal(CrossH.GetKeyId(EId))).GetStr();
460  } else if(CrossHI.GetDat().Val1 == StrType) {
461  return this->VecOfStrVecsE.GetVal(
462  this->KeyToIndexTypeE.GetDat(CrossHI.GetKey()).Val2).GetVal(CrossH.GetKeyId(EId));
463  } else if (CrossHI.GetDat().Val1 == FltType) {
464  return (this->VecOfFltVecsE.GetVal(
465  this->KeyToIndexTypeE.GetDat(CrossHI.GetKey()).Val2).GetVal(CrossH.GetKeyId(EId))).GetStr();
466  }
467  return TStr::GetNullStr();
468 }
469 
470 int TCrossNet::AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr) {
471  int i;
472  TInt CurrLen;
473  if (!IsEdge(EId)) {
474  //AddEdge(EId);
475  return -1;
476  }
477  if (KeyToIndexTypeE.IsKey(attr)) {
479  NewVec[CrossH.GetKeyId(EId)] = value;
480  } else {
481  CurrLen = VecOfIntVecsE.Len();
482  KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
483  TVec<TInt> NewVec = TVec<TInt>();
484  for (i = 0; i < MxEId; i++) {
485  NewVec.Ins(i, GetIntAttrDefaultE(attr));
486  }
487  NewVec[CrossH.GetKeyId(EId)] = value;
488  VecOfIntVecsE.Add(NewVec);
489  }
490  return 0;
491 }
492 
493 int TCrossNet::AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr) {
494  int i;
495  TInt CurrLen;
496  if (!IsEdge(EId)) {
497  //AddEdge(EId);
498  return -1;
499  }
500  if (KeyToIndexTypeE.IsKey(attr)) {
502  NewVec[CrossH.GetKeyId(EId)] = value;
503  } else {
504  CurrLen = VecOfStrVecsE.Len();
505  KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
506  TVec<TStr> NewVec = TVec<TStr>();
507  for (i = 0; i < MxEId; i++) {
508  NewVec.Ins(i, GetStrAttrDefaultE(attr));
509  }
510  NewVec[CrossH.GetKeyId(EId)] = value;
511  VecOfStrVecsE.Add(NewVec);
512  }
513  return 0;
514 }
515 
516 int TCrossNet::AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr) {
517  int i;
518  TInt CurrLen;
519 
520  if (!IsEdge(EId)) {
521  //AddEdge(EId);
522  return -1;
523  }
524  if (KeyToIndexTypeE.IsKey(attr)) {
526  NewVec[CrossH.GetKeyId(EId)] = value;
527  } else {
528  CurrLen = VecOfFltVecsE.Len();
529  KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
530  TVec<TFlt> NewVec = TVec<TFlt>();
531  for (i = 0; i < MxEId; i++) {
532  NewVec.Ins(i, GetFltAttrDefaultE(attr));
533  }
534  NewVec[CrossH.GetKeyId(EId)] = value;
535  VecOfFltVecsE.Add(NewVec);
536  }
537  return 0;
538 }
539 
540 TInt TCrossNet::GetIntAttrDatE(const int& EId, const TStr& attr) {
542 }
543 
544 TStr TCrossNet::GetStrAttrDatE(const int& EId, const TStr& attr) {
546 }
547 
548 TFlt TCrossNet::GetFltAttrDatE(const int& EId, const TStr& attr) {
550 }
551 
552 int TCrossNet::DelAttrDatE(const int& EId, const TStr& attr) {
553  // TODO(nkhadke): add error checking
554  TInt vecType = KeyToIndexTypeE(attr).Val1;
555  if (vecType == IntType) {
557  } else if (vecType == StrType) {
559  } else if (vecType == FltType) {
561  } else {
562  return -1;
563  }
564  return 0;
565 }
566 
567 int TCrossNet::AddIntAttrE(const TStr& attr, TInt defaultValue){
568  // TODO(nkhadke): add error checking
569  int i;
570  TInt CurrLen;
571  TVec<TInt> NewVec;
572  CurrLen = VecOfIntVecsE.Len();
573  KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
574  NewVec = TVec<TInt>();
575  for (i = 0; i < MxEId; i++) {
576  NewVec.Ins(i, defaultValue);
577  }
578  VecOfIntVecsE.Add(NewVec);
579  if (!IntDefaultsE.IsKey(attr)) {
580  IntDefaultsE.AddDat(attr, defaultValue);
581  } else {
582  return -1;
583  }
584  return 0;
585 }
586 
587 int TCrossNet::AddStrAttrE(const TStr& attr, TStr defaultValue) {
588  int i;
589  TInt CurrLen;
590  TVec<TStr> NewVec;
591  CurrLen = VecOfStrVecsE.Len();
592  KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
593  NewVec = TVec<TStr>();
594  for (i = 0; i < MxEId; i++) {
595  NewVec.Ins(i, defaultValue);
596  }
597  VecOfStrVecsE.Add(NewVec);
598  if (!StrDefaultsE.IsKey(attr)) {
599  StrDefaultsE.AddDat(attr, defaultValue);
600  } else {
601  return -1;
602  }
603  return 0;
604 }
605 
606 int TCrossNet::AddFltAttrE(const TStr& attr, TFlt defaultValue) {
607  int i;
608  TInt CurrLen;
609  TVec<TFlt> NewVec;
610  CurrLen = VecOfFltVecsE.Len();
611  KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
612  NewVec = TVec<TFlt>();
613  for (i = 0; i < MxEId; i++) {
614  NewVec.Ins(i, defaultValue);
615  }
616  VecOfFltVecsE.Add(NewVec);
617  if (!FltDefaultsE.IsKey(attr)) {
618  FltDefaultsE.AddDat(attr, defaultValue);
619  } else {
620  return -1;
621  }
622  return 0;
623 }
624 
625 int TCrossNet::DelAttrE(const TStr& attr) {
626  TInt vecType = KeyToIndexTypeE(attr).Val1;
627  if (vecType == IntType) {
629  if (IntDefaultsE.IsKey(attr)) {
630  IntDefaultsE.DelKey(attr);
631  }
632  } else if (vecType == StrType) {
634  if (StrDefaultsE.IsKey(attr)) {
635  StrDefaultsE.DelKey(attr);
636  }
637  } else if (vecType == FltType) {
639  if (FltDefaultsE.IsKey(attr)) {
640  FltDefaultsE.DelKey(attr);
641  }
642  } else {
643  return -1;
644  }
645  KeyToIndexTypeE.DelKey(attr);
646  return 0;
647 }
648 
650  MxModeId = TInt(ShMIn);
651  MxCrossNetId = TInt(ShMIn);
652  TModeNetInit Fm;
653  TModeNetH.LoadShM(ShMIn, Fm);
654  TCrossNetInit Fc;
655  TCrossNetH.LoadShM(ShMIn, Fc);
656  ModeIdToNameH.LoadShM(ShMIn);
657  ModeNameToIdH.LoadShM(ShMIn);
658  CrossIdToNameH.LoadShM(ShMIn);
659  CrossNameToIdH.LoadShM(ShMIn);
660  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
661  it.GetDat().SetParentPointer(this);
662  }
663  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
664  it.GetDat().SetParentPointer(this);
665  }
666 }
667 
668 int TMMNet::AddModeNet(const TStr& ModeName) {
669  if (ModeNameToIdH.IsKey(ModeName)) {
670  return -1;
671  }
672  TInt ModeId = TInt(MxModeId);
673  MxModeId++;
674  ModeIdToNameH.AddDat(ModeId, ModeName);
675  ModeNameToIdH.AddDat(ModeName, ModeId);
676 
677  TModeNet NewGraph(ModeId);
678  NewGraph.SetParentPointer(this);
679  TModeNetH.AddDat(ModeId, NewGraph);
680  return ModeId;
681 }
682 
683 int TMMNet::AddCrossNet(const TStr& ModeName1, const TStr& ModeName2, const TStr& CrossNetName, bool isDir) {
684  TInt ModeId1 = GetModeId(ModeName1);
685  TInt ModeId2 = GetModeId(ModeName2);
686  return AddCrossNet(ModeId1, ModeId2, CrossNetName, isDir);
687 }
688 
689 int TMMNet::AddCrossNet(const TInt& ModeId1, const TInt& ModeId2, const TStr& CrossNetName, bool isDir) {
690  if (CrossNameToIdH.IsKey(CrossNetName)) {
691  return -1;
692  }
693  TInt CrossNetId = TInt(MxCrossNetId);
694  MxCrossNetId++;
695  CrossIdToNameH.AddDat(CrossNetId, CrossNetName);
696  CrossNameToIdH.AddDat(CrossNetName, CrossNetId);
697 
698  TCrossNet Cross = TCrossNet(ModeId1, ModeId2, isDir, CrossNetId);
699  Cross.SetParentPointer(this);
700  TCrossNetH.AddDat(CrossNetId, Cross);
701 
702  TModeNetH.GetDat(ModeId1).AddNbrType(CrossNetName, ModeId1==ModeId2, isDir);
703  TModeNetH.GetDat(ModeId2).AddNbrType(CrossNetName, ModeId1==ModeId2, isDir);
704 
705  return CrossNetId;
706 }
707 
708 int TMMNet::DelCrossNet(const TInt& CrossNetId) {
709  return DelCrossNet(CrossIdToNameH.GetDat(CrossNetId));
710 }
711 
712 int TMMNet::DelCrossNet(const TStr& CrossNet) {
713  IAssertR(CrossNameToIdH.IsKey(CrossNet),TStr::Fmt("No such link type: %s", CrossNet.CStr()));
714  TInt CrossNetId = CrossNameToIdH.GetDat(CrossNet);
715  TInt Mode1 = GetCrossNetById(CrossNetId).Mode1;
716  TInt Mode2 = GetCrossNetById(CrossNetId).Mode2;
717  if (GetModeNetById(Mode1).DelNbrType(CrossNet) == -1 || (Mode1 != Mode2 && GetModeNetById(Mode2).DelNbrType(CrossNet) == -1)) {
718  return -1;
719  }
720  CrossNameToIdH.DelKey(CrossNet);
721  CrossIdToNameH.DelKey(CrossNetId);
722  GetCrossNetById(CrossNetId).SetParentPointer(NULL);
723  TCrossNetH.DelKey(CrossNetId);
724  return 0;
725 }
726 
727 int TMMNet::DelModeNet(const TInt& ModeId) {
728  TStrV CrossNets;
729  GetModeNetById(ModeId).GetCrossNetNames(CrossNets);
730  for (int i = 0; i < CrossNets.Len(); i++) {
731  if (DelCrossNet(CrossNets[i]) == -1) {
732  return -1;
733  }
734  }
735  TStr ModeName = ModeIdToNameH.GetDat(ModeId);
736  ModeNameToIdH.DelKey(ModeName);
737  ModeIdToNameH.DelKey(ModeId);
738  GetModeNetById(ModeId).SetParentPointer(NULL);
739  TModeNetH.DelKey(ModeId);
740  return 0;
741 }
742 
743 int TMMNet::DelModeNet(const TStr& ModeName) {
744  IAssertR(ModeNameToIdH.IsKey(ModeName), TStr::Fmt("No such mode with name: %s", ModeName.CStr()));
745  return DelModeNet(ModeNameToIdH.GetDat(ModeName));
746 }
747 
748 TModeNet& TMMNet::GetModeNetByName(const TStr& ModeName) const {
749  //IAssertR(ModeNameToIdH.IsKey(ModeName),TStr::Fmt("No such mode name: %s", ModeName.CStr()));
750  return GetModeNetById(ModeNameToIdH.GetDat(ModeName));
751 }
752 
753 TModeNet& TMMNet::GetModeNetById(const TInt& ModeId) const {
754 // IAssertR(ModeId < TModeNetH.Len(), TStr::Fmt("Mode with id %d does not exist", ModeId));
755  TModeNet &Net = (const_cast<TMMNet *>(this))->TModeNetH.GetDat(ModeId);
756  return Net;
757 }
758 TCrossNet& TMMNet::GetCrossNetByName(const TStr& CrossName) const{
759  //IAssertR(CrossNameToIdH.IsKey(CrossName),TStr::Fmt("No such link name: %s", CrossName.CStr()));
760  return GetCrossNetById(CrossNameToIdH.GetDat(CrossName));
761 }
762 TCrossNet& TMMNet::GetCrossNetById(const TInt& CrossId) const{
763  //IAssertR(CrossIdToNameH.IsKey(CrossId),TStr::Fmt("No link with id %d exists", CrossId));
764  TCrossNet& CrossNet = (const_cast<TMMNet *>(this))->TCrossNetH.GetDat(CrossId);
765  return CrossNet;
766 }
767 
768 int TMMNet::AddMode(const TStr& ModeName, const TInt& ModeId, const TModeNet& ModeNet) {
769  ModeIdToNameH.AddDat(ModeId, ModeName);
770  ModeNameToIdH.AddDat(ModeName, ModeId);
771 
772  TModeNetH.AddDat(ModeId, ModeNet);
773  TModeNetH[ModeId].SetParentPointer(this);
774  return ModeId;
775 
776 }
777 int TMMNet::AddCrossNet(const TStr& CrossNetName, const TInt& CrossNetId, const TCrossNet& CrossNet) {
778  CrossIdToNameH.AddDat(CrossNetId, CrossNetName);
779  CrossNameToIdH.AddDat(CrossNetName, CrossNetId);
780 
781  TCrossNetH.AddDat(CrossNetId, CrossNet);
782  TCrossNetH[CrossNetId].SetParentPointer(this);
783  return CrossNetId;
784 }
785 
786 void TMMNet::ClrNbr(const TInt& ModeId, const TInt& CrossNetId, const bool& outEdge, const bool& sameMode, bool& isDir) {
787  TStr CrossNetName = CrossIdToNameH[CrossNetId];
788  TModeNetH[ModeId].ClrNbr(CrossNetName, outEdge, sameMode, isDir);
789 }
790 
792  PMMNet Result = New();
793  TInt MxMode = 0;
794  TInt MxCross = 0;
795  TIntH ModeH;
796  for(int i = 0; i < CrossNetTypes.Len(); i++) {
797  TStr CrossName = CrossNetTypes[i];
798  TInt OldId = CrossNameToIdH.GetDat(CrossName);
799  TInt NewId = MxCross++;
800  TCrossNet NewCrossNet(TCrossNetH.GetDat(OldId));
801  TInt OldModeId1 = NewCrossNet.Mode1;
802  TInt OldModeId2 = NewCrossNet.Mode2;
803  TInt NewModeId1, NewModeId2;
804  if (ModeH.IsKey(OldModeId1)) {
805  NewModeId1 = ModeH.GetDat(OldModeId1);
806  } else {
807  NewModeId1 = MxMode++;
808  ModeH.AddDat(OldModeId1, NewModeId1);
809  }
810  if (ModeH.IsKey(OldModeId2)) {
811  NewModeId2 = ModeH.GetDat(OldModeId2);
812  } else {
813  NewModeId2 = MxMode++;
814  ModeH.AddDat(OldModeId2, NewModeId2);
815  }
816  NewCrossNet.Mode1 = NewModeId1;
817  NewCrossNet.Mode2 = NewModeId2;
818  NewCrossNet.CrossNetId = NewId;
819  Result->AddCrossNet(CrossName, NewId, NewCrossNet);
820  }
821  for(TIntH::TIter it = ModeH.BegI(); it < ModeH.EndI(); it++) {
822  TStr ModeName = ModeIdToNameH.GetDat(it.GetKey());
823  TInt NewModeId = it.GetDat();
824  TModeNet NewModeNet;
825  TModeNetH.GetDat(it.GetKey()).RemoveCrossNets(NewModeNet, CrossNetTypes);
826  NewModeNet.ModeId = NewModeId;
827  Result->AddMode(ModeName, NewModeId, NewModeNet);
828  }
829  Result->MxModeId = MxMode;
830  Result->MxCrossNetId = MxCross;
831  return Result;
832 }
833 
835  THash<TInt, TBool> ModeTypeIds;
836  for (int i = 0; i < ModeNetTypes.Len(); i++) {
837  ModeTypeIds.AddDat(ModeNameToIdH.GetDat(ModeNetTypes[i]), true);
838  }
839  TStrV CrossNetTypes;
840  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
841  TCrossNet& CrossNet = it.GetDat();
842  if (ModeTypeIds.IsKey(CrossNet.Mode1) && ModeTypeIds.IsKey(CrossNet.Mode2)) {
843  CrossNetTypes.Add(CrossIdToNameH.GetDat(it.GetKey()));
844  ModeTypeIds[CrossNet.Mode1] = false;
845  ModeTypeIds[CrossNet.Mode2] = false;
846  }
847  }
848 
849  PMMNet Result = GetSubgraphByCrossNet(CrossNetTypes);
850  TInt MxMode = Result->MxModeId;
851  TStrV EmptyCrossNetTypes;
852  for (THash<TInt, TBool>::TIter it = ModeTypeIds.BegI(); it < ModeTypeIds.EndI(); it++) {
853  if (it.GetDat().Val) {
854  TStr ModeName = ModeIdToNameH.GetDat(it.GetKey());
855  TInt NewModeId = MxMode++;
856  TModeNet NewModeNet;
857  TModeNetH.GetDat(it.GetKey()).RemoveCrossNets(NewModeNet, EmptyCrossNetTypes);
858  NewModeNet.ModeId = NewModeId;
859  Result->AddMode(ModeName, NewModeId, NewModeNet);
860  }
861  }
862  Result->MxModeId = MxMode;
863  return Result;
864 }
865 
866 PNEANet TMMNet::ToNetwork(TIntV& CrossNetTypes, TIntStrStrTrV& NodeAttrMap, TVec<TTriple<TInt, TStr, TStr> >& EdgeAttrMap) {
867  TIntPrIntH NodeMap;
868  THash<TIntPr, TIntPr> EdgeMap;
869  THashSet<TInt> Modes;
870  PNEANet NewNet = TNEANet::New();
871  //Add nodes and edges
872  for (int i = 0; i < CrossNetTypes.Len(); i++) {
873  TCrossNet& CrossNet = GetCrossNetById(CrossNetTypes[i]);
874  TInt Mode1 = CrossNet.GetMode1();
875  TInt Mode2 = CrossNet.GetMode2();
876  Modes.AddKey(Mode1);
877  Modes.AddKey(Mode2);
878  bool isDirected = CrossNet.IsDirected();
879  for(TCrossNet::TCrossEdgeI EdgeI = CrossNet.BegEdgeI(); EdgeI != CrossNet.EndEdgeI(); EdgeI++) {
880  int srcNode = EdgeI.GetSrcNId();
881  int dstNode = EdgeI.GetDstNId();
882  TIntPr SrcNodeMapping(Mode1, srcNode);
883  int srcId = 0;
884  if (NodeMap.IsKey(SrcNodeMapping)) {
885  srcId = NodeMap.GetDat(SrcNodeMapping);
886  } else {
887  srcId = NewNet->AddNode();
888  NodeMap.AddDat(SrcNodeMapping, srcId);
889  }
890  TIntPr DstNodeMapping(Mode2, dstNode);
891  int dstId = 0;
892  if (NodeMap.IsKey(DstNodeMapping)) {
893  dstId = NodeMap.GetDat(DstNodeMapping);
894  } else {
895  dstId = NewNet->AddNode();
896  NodeMap.AddDat(DstNodeMapping, dstId);
897  }
898  int edgeId = EdgeI.GetId();
899  TIntPr EdgeMapping(CrossNetTypes[i], edgeId);
900  int newEId = NewNet->AddEdge(srcId, dstId);
901  int otherEId = -1;
902  if (!isDirected) {
903  otherEId = NewNet->AddEdge(dstId, srcId);
904  }
905  EdgeMap.AddDat(EdgeMapping, TIntPr(newEId, otherEId));
906  }
907  }
908 
909  for (THashSet<TInt>::TIter it = Modes.BegI(); it != Modes.EndI(); it++) {
910  TModeNet &ModeNet = GetModeNetById(it.GetKey());
911  TInt ModeId = it.GetKey();
912  for(TModeNet::TNodeI NodeIt = ModeNet.BegMMNI(); NodeIt != ModeNet.EndMMNI(); NodeIt++) {
913  TIntPr NodeKey(ModeId, NodeIt.GetId());
914  if (!NodeMap.IsKey(NodeKey)) {
915  int newId = NewNet->AddNode();
916  NodeMap.AddDat(NodeKey, newId);
917  }
918  }
919  }
920 
921  //Add attributes
922  NewNet->AddIntAttrN(TStr("Mode"));
923  NewNet->AddIntAttrN(TStr("Id"));
924  NewNet->AddIntAttrE(TStr("CrossNet"));
925  NewNet->AddIntAttrE(TStr("Id"));
926  for(TIntPrIntH::TIter it = NodeMap.BegI(); it != NodeMap.EndI(); it++) {
927  NewNet->AddIntAttrDatN(it.GetDat(), it.GetKey().GetVal1(), TStr("Mode"));
928  NewNet->AddIntAttrDatN(it.GetDat(), it.GetKey().GetVal2(), TStr("Id"));
929  }
930  for(THash<TIntPr, TIntPr>::TIter it = EdgeMap.BegI(); it != EdgeMap.EndI(); it++) {
931  NewNet->AddIntAttrDatE(it.GetDat().GetVal1(), it.GetKey().GetVal1(), TStr("CrossNet"));
932  NewNet->AddIntAttrDatE(it.GetDat().GetVal1(), it.GetKey().GetVal2(), TStr("Id"));
933  if (it.GetDat().GetVal2() != -1) {
934  NewNet->AddIntAttrDatE(it.GetDat().GetVal2(), it.GetKey().GetVal1(), TStr("CrossNet"));
935  NewNet->AddIntAttrDatE(it.GetDat().GetVal2(), it.GetKey().GetVal2(), TStr("Id"));
936  }
937  }
938 
939  for (int i = 0; i < NodeAttrMap.Len(); i++) {
940  //mode, orig attr, new attr
941  TInt ModeId = NodeAttrMap[i].Val1;
942  TStr OrigAttr = NodeAttrMap[i].Val2;
943  TStr NewAttr = NodeAttrMap[i].Val3;
944  TModeNet& Net = GetModeNetById(ModeId);
945  int type = Net.GetAttrTypeN(OrigAttr);
946  if (type == TModeNet::IntType) {
947  NewNet->AddIntAttrN(NewAttr, Net.GetIntAttrDefaultN(OrigAttr));
948  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
949  TIntPr OldNId(ModeId, it.GetId());
950  int NewId = NodeMap.GetDat(OldNId);
951  int Val = Net.GetIntAttrDatN(it.GetId(), OrigAttr);
952  NewNet->AddIntAttrDatN(NewId, Val, NewAttr);
953  }
954  } else if (type == TModeNet::FltType) {
955  NewNet->AddFltAttrN(NewAttr, Net.GetFltAttrDefaultN(OrigAttr));
956  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
957  TIntPr OldNId(ModeId, it.GetId());
958  int NewId = NodeMap.GetDat(OldNId);
959  TFlt Val = Net.GetFltAttrDatN(it.GetId(), OrigAttr);
960  NewNet->AddFltAttrDatN(NewId, Val, NewAttr);
961  }
962 
963  } else if (type == TModeNet::StrType) {
964  NewNet->AddStrAttrN(NewAttr, Net.GetStrAttrDefaultN(OrigAttr));
965  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
966  TIntPr OldNId(ModeId, it.GetId());
967  int NewId = NodeMap.GetDat(OldNId);
968  TStr Val = Net.GetStrAttrDatN(it.GetId(), OrigAttr);
969  NewNet->AddStrAttrDatN(NewId, Val, NewAttr);
970  }
971  } else if (type == TModeNet::IntVType) {
972  NewNet->AddIntVAttrN(NewAttr);
973  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
974  TIntPr OldNId(ModeId, it.GetId());
975  int NewId = NodeMap.GetDat(OldNId);
976  TIntV Val = Net.GetIntVAttrDatN(it.GetId(), OrigAttr);
977  NewNet->AddIntVAttrDatN(NewId, Val, NewAttr);
978  }
979  }
980  }
981 
982  for (int i = 0; i < EdgeAttrMap.Len(); i++) {
983  //mode, orig attr, new attr
984  TInt CrossId = EdgeAttrMap[i].Val1;
985  TStr OrigAttr = EdgeAttrMap[i].Val2;
986  TStr NewAttr = EdgeAttrMap[i].Val3;
987  TCrossNet& Net = GetCrossNetById(CrossId);
988  int type = Net.GetAttrTypeE(OrigAttr);
989  if (type == TCrossNet::IntType) {
990  NewNet->AddIntAttrE(NewAttr, Net.GetIntAttrDefaultE(OrigAttr));
991  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++) {
992  TIntPr OldNId(CrossId, it.GetId());
993  TIntPr NewId = EdgeMap.GetDat(OldNId);
994  int Val = Net.GetIntAttrDatE(it.GetId(), OrigAttr);
995  NewNet->AddIntAttrDatE(NewId.Val1, Val, NewAttr);
996  if (NewId.Val2 != -1) {
997  NewNet->AddIntAttrDatE(NewId.Val2, Val, NewAttr);
998  }
999  }
1000  } else if (type == TCrossNet::FltType) {
1001  NewNet->AddFltAttrE(NewAttr, Net.GetFltAttrDefaultE(OrigAttr));
1002  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++) {
1003  TIntPr OldNId(CrossId, it.GetId());
1004  TIntPr NewId = EdgeMap.GetDat(OldNId);
1005  TFlt Val = Net.GetFltAttrDatE(it.GetId(), OrigAttr);
1006  NewNet->AddFltAttrDatE(NewId.Val1, Val, NewAttr);
1007  if (NewId.Val2 != -1) {
1008  NewNet->AddFltAttrDatE(NewId.Val2, Val, NewAttr);
1009  }
1010  }
1011 
1012  } else if (type == TCrossNet::StrType) {
1013  NewNet->AddStrAttrE(NewAttr, Net.GetStrAttrDefaultE(OrigAttr));
1014  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++){
1015  TIntPr OldNId(CrossId, it.GetId());
1016  TIntPr NewId = EdgeMap.GetDat(OldNId);
1017  TStr Val = Net.GetStrAttrDatE(it.GetId(), OrigAttr);
1018  NewNet->AddStrAttrDatE(NewId.Val1, Val, NewAttr);
1019  if (NewId.Val2 != -1) {
1020  NewNet->AddStrAttrDatE(NewId.Val2, Val, NewAttr);
1021  }
1022  }
1023  }
1024  }
1025  return NewNet;
1026 }
1027 
1028 PNEANet TMMNet::ToNetwork2(TIntV& CrossNetTypes, TIntStrPrVH& NodeAttrMap, THash<TInt, TVec<TPair<TStr, TStr> > >& EdgeAttrMap) {
1029  TIntPrIntH NodeMap;
1030  THashSet<TInt> Modes;
1031  PNEANet NewNet = TNEANet::New();
1032  NewNet->AddIntAttrN(TStr("Mode"));
1033  NewNet->AddIntAttrN(TStr("Id"));
1034  NewNet->AddIntAttrE(TStr("CrossNet"));
1035  NewNet->AddIntAttrE(TStr("Id"));
1036 
1037  //Add nodes and edges
1038  for (int i = 0; i < CrossNetTypes.Len(); i++) {
1039  TCrossNet& CrossNet = GetCrossNetById(CrossNetTypes[i]);
1040  TStrPrV CNetAttrs;
1041  if (EdgeAttrMap.IsKey(CrossNetTypes[i])) {
1042  CNetAttrs = EdgeAttrMap.GetDat(CrossNetTypes[i]);
1043  }
1044  TInt Mode1 = CrossNet.GetMode1();
1045  TInt Mode2 = CrossNet.GetMode2();
1046  TModeNet& Mode1Net = GetModeNetById(Mode1);
1047  TModeNet& Mode2Net = GetModeNetById(Mode2);
1048  TStrPrV Mode1Attrs;
1049  if (NodeAttrMap.IsKey(Mode1)) {
1050  Mode1Attrs = NodeAttrMap.GetDat(Mode1);
1051  }
1052  TStrPrV Mode2Attrs;
1053  if (NodeAttrMap.IsKey(Mode2)) {
1054  Mode2Attrs = NodeAttrMap.GetDat(Mode2);
1055  }
1056  Modes.AddKey(Mode1);
1057  Modes.AddKey(Mode2);
1058  bool isDirected = CrossNet.IsDirected();
1059  for(TCrossNet::TCrossEdgeI EdgeI = CrossNet.BegEdgeI(); EdgeI != CrossNet.EndEdgeI(); EdgeI++) {
1060  int srcNode = EdgeI.GetSrcNId();
1061  int dstNode = EdgeI.GetDstNId();
1062  TIntPr SrcNodeMapping(Mode1, srcNode);
1063  int srcId = 0;
1064  if (NodeMap.IsKey(SrcNodeMapping)) {
1065  srcId = NodeMap.GetDat(SrcNodeMapping);
1066  } else {
1067  srcId = NewNet->AddNode();
1068  NodeMap.AddDat(SrcNodeMapping, srcId);
1069  NewNet->AddIntAttrDatN(srcId, srcNode, TStr("Id"));
1070  NewNet->AddIntAttrDatN(srcId, Mode1, TStr("Mode"));
1071  AddNodeAttributes(NewNet, Mode1Net, Mode1Attrs, Mode1, srcNode, srcId);
1072  }
1073  TIntPr DstNodeMapping(Mode2, dstNode);
1074  int dstId = 0;
1075  if (NodeMap.IsKey(DstNodeMapping)) {
1076  dstId = NodeMap.GetDat(DstNodeMapping);
1077  } else {
1078  dstId = NewNet->AddNode();
1079  NodeMap.AddDat(DstNodeMapping, dstId);
1080  NewNet->AddIntAttrDatN(dstId, dstNode, TStr("Id"));
1081  NewNet->AddIntAttrDatN(dstId, Mode2, TStr("Mode"));
1082  AddNodeAttributes(NewNet, Mode2Net, Mode2Attrs, Mode2, dstNode, dstId);
1083  }
1084  int edgeId = EdgeI.GetId();
1085  int newEId = NewNet->AddEdge(srcId, dstId);
1086  NewNet->AddIntAttrDatE(newEId, edgeId, TStr("Id"));
1087  NewNet->AddIntAttrDatE(newEId, CrossNetTypes[i], TStr("CrossNet"));
1088  AddEdgeAttributes(NewNet, CrossNet, CNetAttrs, CrossNetTypes[i], edgeId, newEId);
1089  if (!isDirected) {
1090  int otherEId = NewNet->AddEdge(dstId, srcId);
1091  NewNet->AddIntAttrDatE(otherEId, edgeId, TStr("Id"));
1092  NewNet->AddIntAttrDatE(otherEId, CrossNetTypes[i], TStr("CrossNet"));
1093  AddEdgeAttributes(NewNet, CrossNet, CNetAttrs, CrossNetTypes[i], edgeId, otherEId);
1094  }
1095  }
1096  }
1097 
1098  for (THashSet<TInt>::TIter it = Modes.BegI(); it != Modes.EndI(); it++) {
1099  TInt ModeId = it.GetKey();
1100  TModeNet &ModeNet = GetModeNetById(ModeId);
1101  TStrPrV ModeAttrs = NodeAttrMap.GetDat(ModeId);
1102  for(TModeNet::TNodeI NodeIt = ModeNet.BegMMNI(); NodeIt != ModeNet.EndMMNI(); NodeIt++) {
1103  TIntPr NodeKey(ModeId, NodeIt.GetId());
1104  if (!NodeMap.IsKey(NodeKey)) {
1105  int newId = NewNet->AddNode();
1106  NodeMap.AddDat(NodeKey, newId);
1107  AddNodeAttributes(NewNet, ModeNet, ModeAttrs, ModeId, NodeIt.GetId(), newId);
1108  }
1109  }
1110  }
1111 
1112  return NewNet;
1113 }
1114 
1115 void TMMNet::GetPartitionRanges(TIntPrV& Partitions, const TInt& NumPartitions, const TInt& MxLen) const {
1116  if (MxLen <= NumPartitions) {
1117  Partitions.Add(TIntPr(0,MxLen));
1118  } else {
1119  TInt PartitionSize = MxLen/NumPartitions;
1120  TInt CurrStart = 0;
1121  bool done = false;
1122  while (!done) {
1123  TInt CurrEnd = CurrStart + PartitionSize;
1124  if (MxLen - CurrEnd < PartitionSize) {
1125  CurrEnd = MxLen;
1126  done = true;
1127  }
1128  Partitions.Add(TIntPr(CurrStart, CurrEnd));
1129  CurrStart = CurrEnd;
1130  }
1131  }
1132 }
1133 
1134 #ifdef GCC_ATOMIC
1135 
1137 
1138  TStrIntH CrossNetStart;
1139  THashSet<TInt> ModeSet;
1140  int offset = 0;
1141  int NumEdges = 0;
1142  TVec<TCrossNet> CrossNets;
1143  for (int i=0; i < CrossNetNames.Len(); i++) {
1144  CrossNets.Add(GetCrossNetByName(CrossNetNames[i]));
1145  CrossNetStart.AddDat(CrossNetNames[i], offset);
1146  TCrossNet& CrossNet = GetCrossNetByName(CrossNetNames[i]);
1147  int factor = CrossNet.IsDirected() ? 1 : 2;
1148  offset += (CrossNet.GetMxEId() * factor);
1149  NumEdges += (CrossNet.GetEdges() * factor);
1150  ModeSet.AddKey(CrossNet.GetMode1());
1151  ModeSet.AddKey(CrossNet.GetMode2());
1152  }
1153  int MxEId = offset;
1154  int NumNodes = 0;
1155  for (THashSet<TInt>::TIter MI = ModeSet.BegI(); MI < ModeSet.EndI(); MI++) {
1156  TModeNet& ModeNet = GetModeNetById(MI.GetKey());
1157  NumNodes += ModeNet.GetNodes();
1158  }
1159  THashMP<TIntPr, TInt> NodeMap(NumNodes);
1160  THashMP<TIntPr, TIntPr> EdgeMap(NumEdges);
1161  PNEANetMP NewNet = TNEANetMP::New(NumNodes, NumEdges);
1162 
1163  int num_threads = omp_get_max_threads();
1164  offset = 0;
1165  for (THashSet<TInt>::TIter MI = ModeSet.BegI(); MI < ModeSet.EndI(); MI++) {
1166  TInt ModeId = MI.GetKey();
1167  TModeNet& ModeNet = GetModeNetById(ModeId);
1168  TIntV KeyIds;
1169  ModeNet.NodeH.GetKeyV(KeyIds);
1170 
1171  TIntPrV NodePartitions;
1172  GetPartitionRanges(NodePartitions, num_threads, KeyIds.Len());
1173  int curr_nid;
1174  #pragma omp parallel for schedule(static) private(curr_nid)
1175  for (int i = 0; i < NodePartitions.Len(); i++) {
1176  TInt CurrStart = NodePartitions[i].GetVal1();
1177  TInt CurrEnd = NodePartitions[i].GetVal2();
1178  curr_nid = offset + CurrStart;
1179  for (int idx = CurrStart; idx < CurrEnd ; idx++) {
1180  int n_i = KeyIds[idx];
1181  if (ModeNet.IsNode(n_i)) {
1182  //Collect neighbors
1183  TIntV InNbrs;
1184  TIntV OutNbrs;
1185  for (int j=0; j < CrossNetNames.Len(); j++) {
1186  TStr CrossNetName = TStr(CrossNetNames[j].CStr());
1187  if (ModeNet.NeighborTypes.IsKey(CrossNetName)) {
1188  if (ModeNet.NeighborTypes.GetDat(CrossNetName)) {
1189 
1190  TIntV Neighbors;
1191  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetName, Neighbors);
1192  int edge_offset = CrossNetStart.GetDat(CrossNetName);
1193  TCrossNet& CrossNet = GetCrossNetByName(CrossNetName);
1194  //TCrossNet* CrossNet = &CrossNets[j];
1195  bool isDir = CrossNet.IsDirected();
1196  bool isOutNbr = CrossNet.GetMode1() == ModeId;
1197  int factor = isDir ? 1 : 2;
1198 
1199  int id_offset = isDir || isOutNbr ? 0 : 1;
1200  if (!isDir && CrossNet.GetMode1() == CrossNet.GetMode2()) {
1201  id_offset = n_i == CrossNet.GetEdge(n_i).GetSrcNId() ? 0 : 1;
1202  }
1203 
1204  for (int k = 0; k < Neighbors.Len(); k++) {
1205  if (isOutNbr && id_offset == 0) {
1206  OutNbrs.Add(edge_offset + Neighbors[k]*factor + id_offset);
1207  } else {
1208  InNbrs.Add(edge_offset + Neighbors[k]*factor + id_offset);
1209  }
1210  if (!isDir) {
1211  int opp_offset = id_offset == 1 ? 0 : 1;
1212  if (isOutNbr && id_offset == 0) {
1213  InNbrs.Add(edge_offset + Neighbors[k]*factor + opp_offset);
1214  } else {
1215  OutNbrs.Add(edge_offset + Neighbors[k]*factor + opp_offset);
1216  }
1217  }
1218  }
1219  } else {
1220  TIntV TempOut;
1221  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetName, TempOut, true);
1222  OutNbrs.AddV(TempOut);
1223  TIntV TempIn;
1224  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetName, TempIn, false);
1225  InNbrs.AddV(TempIn);
1226  }
1227  }
1228  }
1229 
1230  NewNet->AddNodeWithEdges(curr_nid, InNbrs, OutNbrs);
1231  TIntPr NodeKey(MI.GetKey(), n_i);
1232  NodeMap.AddDat(NodeKey, curr_nid);
1233  curr_nid++;
1234  }
1235  }
1236  }
1237  offset += KeyIds.Len();
1238  }
1239  NewNet->SetNodes(offset);
1240 
1241  for (int j=0; j < CrossNetNames.Len(); j++) {
1242  TStr CrossNetName = CrossNetNames[j];
1243  TCrossNet& CrossNet = GetCrossNetByName(CrossNetName);
1244  TInt CrossNetId = GetCrossId(CrossNetName);
1245  TInt Mode1 = CrossNet.GetMode1();
1246  TInt Mode2 = CrossNet.GetMode2();
1247  TIntPrV EdgePartitions;
1248  GetPartitionRanges(EdgePartitions, num_threads, CrossNet.MxEId);
1249  int curr_eid;
1250  offset = CrossNetStart.GetDat(CrossNetNames[j]);
1251  int factor = CrossNet.IsDirected() ? 1 : 2;
1252  #pragma omp parallel for schedule(static) private(curr_eid)
1253  for (int i = 0; i < EdgePartitions.Len(); i++) {
1254  TInt CurrStart = EdgePartitions[i].GetVal1();
1255  TInt CurrEnd = EdgePartitions[i].GetVal2();
1256  for (int e_i = CurrStart; e_i < CurrEnd ; e_i++) {
1257  curr_eid = offset + factor*e_i;
1258  if (CrossNet.IsEdge(e_i)) {
1259  int new_eid = curr_eid;
1260  TIntPr EdgeKey(CrossNetId, e_i);
1261  TCrossNet::TCrossEdgeI edge = CrossNet.GetEdgeI(e_i);
1262  int srcNode = edge.GetSrcNId();
1263  int dstNode = edge.GetDstNId();
1264  TIntPr NodeKeySrc(Mode1, srcNode);
1265  TIntPr NodeKeyDst(Mode2, dstNode);
1266  int newSrc = NodeMap.GetDat(NodeKeySrc);
1267  int newDst = NodeMap.GetDat(NodeKeyDst);
1268  NewNet->AddEdgeUnchecked(curr_eid, newSrc, newDst);
1269  curr_eid++;
1270  int otherEId = -1;
1271  if (!CrossNet.IsDirected()) {
1272  otherEId = curr_eid;
1273  NewNet->AddEdgeUnchecked(otherEId, newDst, newSrc);
1274  }
1275  EdgeMap.AddDat(EdgeKey, TIntPr(new_eid, otherEId));
1276  }
1277  }
1278  }
1279  }
1280  NewNet->SetEdges(MxEId);
1281  NewNet->ReserveAttr(2, 0, 0, 2, 0, 0);
1282 
1283  //Add attributes
1284  NewNet->AddIntAttrN(TStr("Mode"));
1285  NewNet->AddIntAttrN(TStr("Id"));
1286  NewNet->AddIntAttrE(TStr("CrossNet"));
1287  NewNet->AddIntAttrE(TStr("Id"));
1288 
1289  TIntPrV NewNodeIds;
1290  NodeMap.GetKeyV(NewNodeIds);
1291 
1292  #pragma omp parallel for schedule(static)
1293  for(int i = 0; i < NewNodeIds.Len(); i++) {
1294  NewNet->AddIntAttrDatN(NodeMap.GetDat(NewNodeIds[i]), NewNodeIds[i].GetVal1(), TStr("Mode"));
1295  NewNet->AddIntAttrDatN(NodeMap.GetDat(NewNodeIds[i]), NewNodeIds[i].GetVal2(), TStr("Id"));
1296  }
1297 
1298  TIntPrV NewEdgeIds;
1299  EdgeMap.GetKeyV(NewEdgeIds);
1300  #pragma omp parallel for schedule(static)
1301  for(int i = 0; i < NewEdgeIds.Len(); i++) {
1302  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal1(), NewEdgeIds[i].GetVal2(), TStr("Id"));
1303  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal1(), NewEdgeIds[i].GetVal1(), TStr("CrossNet"));
1304  if (EdgeMap.GetDat(NewEdgeIds[i]).GetVal2() != -1) {
1305  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal2(), NewEdgeIds[i].GetVal1(), TStr("CrossNet"));
1306  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal2(), NewEdgeIds[i].GetVal2(), TStr("Id"));
1307  }
1308  }
1309  return NewNet;
1310 }
1311 
1312 #endif // GCC_ATOMIC
1313 
1314 int TMMNet::AddNodeAttributes(PNEANet& NewNet, TModeNet& Net, TVec<TPair<TStr, TStr> >& Attrs, int ModeId, int oldId, int NId) {
1315  for (int i = 0; i < Attrs.Len(); i++) {
1316  //mode, orig attr, new attr
1317  TStr OrigAttr = Attrs[i].Val1;
1318  TStr NewAttr = Attrs[i].Val2;
1319  int type = Net.GetAttrTypeN(OrigAttr);
1320  if (type == TModeNet::IntType) {
1321  TIntPr OldNId(ModeId, oldId);
1322  TInt Val = Net.GetIntAttrDatN(oldId, OrigAttr);
1323  NewNet->AddIntAttrDatN(NId, Val, NewAttr);
1324  } else if (type == TModeNet::FltType) {
1325  TIntPr OldNId(ModeId, oldId);
1326  TFlt Val = Net.GetFltAttrDatN(oldId, OrigAttr);
1327  NewNet->AddFltAttrDatN(NId, Val, NewAttr);
1328  } else if (type == TModeNet::StrType) {
1329  TIntPr OldNId(ModeId, oldId);
1330  TStr Val = Net.GetStrAttrDatN(oldId, OrigAttr);
1331  NewNet->AddStrAttrDatN(NId, Val, NewAttr);
1332  } else if (type == TModeNet::IntVType) {
1333  TIntPr OldNId(ModeId, oldId);
1334  TIntV Val = Net.GetIntVAttrDatN(oldId, OrigAttr);
1335  NewNet->AddIntVAttrDatN(NId, Val, NewAttr);
1336  }
1337  }
1338  return 0;
1339 }
1340 
1341 int TMMNet::AddEdgeAttributes(PNEANet& NewNet, TCrossNet& Net, TVec<TPair<TStr, TStr> >& Attrs, int CrossId, int oldId, int EId) {
1342  for (int i = 0; i < Attrs.Len(); i++) {
1343  //mode, orig attr, new attr
1344  TStr OrigAttr = Attrs[i].Val1;
1345  TStr NewAttr = Attrs[i].Val2;
1346  int type = Net.GetAttrTypeE(OrigAttr);
1347  if (type == TCrossNet::IntType) {
1348  TIntPr OldNId(CrossId, oldId);
1349  TInt Val = Net.GetIntAttrDatE(oldId, OrigAttr);
1350  NewNet->AddIntAttrDatE(EId, Val, NewAttr);
1351  } else if (type == TCrossNet::FltType) {
1352  TIntPr OldNId(CrossId, oldId);
1353  TFlt Val = Net.GetFltAttrDatE(oldId, OrigAttr);
1354  NewNet->AddFltAttrDatE(EId, Val, NewAttr);
1355  } else if (type == TCrossNet::StrType) {
1356  TIntPr OldNId(CrossId, oldId);
1357  TStr Val = Net.GetStrAttrDatE(oldId, OrigAttr);
1358  NewNet->AddStrAttrDatE(EId, Val, NewAttr);
1359  }
1360  }
1361  return 0;
1362 }
TStr GetStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: mmnet.h:417
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2701
int AddFltAttrDatE(const TCrossEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: mmnet.h:410
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2276
#define IAssertR(Cond, Reason)
Definition: bd.h:265
void LoadNetworkShM(TShMIn &ShMIn)
Definition: mmnet.cpp:649
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
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2705
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
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:427
int Len() const
Definition: dt.h:487
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
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
int AddStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: mmnet.h:407
THash< TStr, TFlt > FltDefaultsE
Definition: mmnet.h:274
int DelCrossNet(const TInt &CrossNetId)
Deletes a crossnet from the multimodal network.
Definition: mmnet.cpp:708
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
Definition: network.cpp:1418
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
Node iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:28
TVec< TIntV > VecOfIntVecsE
Definition: mmnet.h:275
Definition: ds.h:130
TInt CheckDenseOrSparseN(const TStr &attr) const
Return 1 if in Dense, 0 if in Sparse, -1 if neither.
Definition: network.h:2083
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:444
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
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:828
PMMNet GetSubgraphByCrossNet(TStrV &CrossNetTypes)
Gets the induced subgraph given a vector of crossnet type names.
Definition: mmnet.cpp:791
TIter BegI() const
Definition: shash.h:1105
static PNEANetMP New()
Static cons returns pointer to graph. Ex: PNEANetMP Graph=TNEANetMP::New().
Definition: networkmp.h:316
int GetSrcNId() const
Returns the source of the edge.
Definition: mmnet.h:174
const TVal1 & GetVal1() const
Definition: ds.h:60
void DelNode(const int &NId)
Deletes the given node from this mode.
Definition: mmnet.cpp:64
TMMNet * MMNet
Definition: mmnet.h:47
TIter BegI() const
Definition: hash.h:213
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:314
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
void GetKeyV(TVec< TKey > &KeyV) const
Definition: hashmp.h:490
TMMNet * Net
Definition: mmnet.h:270
TStr GetSubStr(const int &BChN, const int &EChN) const
Definition: dt.cpp:811
Definition: fl.h:384
const TVal2 & GetVal2() const
Definition: ds.h:61
int DelNeighbor(const int &NId, const int &EId, bool outEdge, const TStr &CrossName, const bool sameMode, bool isDir)
Definition: mmnet.cpp:51
TInt MxNId
Definition: network.h:2027
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:157
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
Definition: network.h:2711
TIter EndI() const
Definition: hash.h:218
TCrossEdge & GetEdge(int eid)
Definition: mmnet.h:320
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
int DelEdge(const int &EId)
Deletes an edge by its id.
Definition: mmnet.cpp:301
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
int DelModeNet(const TInt &ModeId)
Deletes a mode from the multimodal network.
Definition: mmnet.cpp:727
virtual void DelNode(const int &NId)
Deletes node of ID NId from the graph.
Definition: network.cpp:531
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:431
TCrossEdgeI EndEdgeI() const
Definition: mmnet.h:336
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:318
const TKey & GetKey() const
Definition: hash.h:80
Definition: dt.h:1383
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
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
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 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
int AddModeNet(const TStr &ModeName)
Adds a mode to the multimodal network.
Definition: mmnet.cpp:668
THash< TStr, TStr > StrDefaultsE
Definition: mmnet.h:273
void DelKey(const TKey &Key)
Definition: hash.h:404
static const int Mn
Definition: dt.h:1138
TVec< TStrV > VecOfStrVecsE
Definition: mmnet.h:276
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
Definition: ds.h:649
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
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: mmnet.h:387
TInt ModeId
Definition: mmnet.h:46
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:2031
const TDat & GetDat() const
Definition: hash.h:81
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
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:342
void RemoveCrossNets(TModeNet &Result, TStrV &CrossNets)
Definition: mmnet.cpp:157
int GetSrcNId() const
Definition: mmnet.h:151
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
Definition: hash.h:78
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
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
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
Definition: ds.h:838
bool IsSuffix(const char *Str) const
Definition: dt.cpp:1093
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Definition: mmnet.cpp:606
TInt CrossNetId
Definition: mmnet.h:269
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2708
int DelNbrType(const TStr &CrossName)
Definition: mmnet.cpp:97
TNodeI BegMMNI() const
Returns an iterator referring to the first node in the graph.
Definition: mmnet.h:82
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
int AddKey(const TKey &Key)
Definition: shash.h:1254
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
bool Val
Definition: dt.h:973
int GetDstNId() const
Returns the destination of the edge.
Definition: mmnet.h:176
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
Definition: network.h:2015
PNEANetMP ToNetworkMP(TStrV &CrossNetNames)
Definition: mmnet.cpp:1136
static TStr GetNullStr()
Definition: dt.cpp:1626
THash< TStr, TInt > IntDefaultsE
Definition: mmnet.h:272
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:419
int AddNodeAttributes(PNEANet &NewNet, TModeNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int ModeId, int oldId, int NId)
Definition: mmnet.cpp:1314
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
void ClrNbr(const TStr &CrossNetName, const bool &outEdge, const bool &sameMode, bool &isDir)
Definition: mmnet.cpp:14
TStr GetStr() const
Definition: dt.h:678
TModeNet()
Definition: mmnet.h:51
Definition: dt.h:1134
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
static PMMNet New()
Definition: mmnet.h:625
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: mmnet.h:369
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
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
Definition: ds.h:1180
TIter EndI() const
Definition: shash.h:1112
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
int GetMxEId() const
Definition: mmnet.h:325
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
Definition: dt.h:412
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:423
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
friend class TCrossNet
Definition: mmnet.h:572
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
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
void Clr()
Deletes all nodes and edges from the graph.
Definition: network.h:2627
TVec< THash< TInt, TIntV > > VecOfIntHashVecsN
Definition: network.h:2042
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:340
Hash-Table with multiprocessing support.
Definition: hashmp.h:81
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:361
TStr GetNeighborCrossName(const TStr &CrossName, bool isOutEdge, const bool sameMode, bool isDir) const
Definition: mmnet.cpp:3
Definition: bd.h:196
TBool IsDirect
The second mode. In the case of directed crossnets, this is implicitly understood to be the destinati...
Definition: mmnet.h:268
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2298
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
Definition: mmnet.cpp:412
THash< TInt, TNode > NodeH
Definition: network.h:2028
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
Definition: mmnet.cpp:625
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:2041
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
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
Definition: network.h:2017
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
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:2013
char * CStr()
Definition: dt.h:476
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &CrossHI) const
Definition: mmnet.cpp:456
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TCrossNet & GetCrossNetByName(const TStr &CrossName) const
Gets a reference to the crossnet.
Definition: mmnet.cpp:758
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int AddEdgeAttributes(PNEANet &NewNet, TCrossNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int CrossId, int oldId, int EId)
Definition: mmnet.cpp:1341
TDat & AddDat(const TKey &Key)
Definition: hashmp.h:181
Definition: dt.h:971
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:2176
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
THash< TInt, TCrossEdge > CrossH
Definition: mmnet.h:264
int Len() const
Definition: hash.h:228
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
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
const TDat & GetDat(const TKey &Key) const
Definition: hashmp.h:195
PMMNet GetSubgraphByModeNet(TStrV &ModeNetTypes)
Gets the induced subgraph given a vector of mode type names.
Definition: mmnet.cpp:834
THash< TStr, TBool > KeyToDenseN
KeyToDense[N|E]: Key->(True if Vec, False if Hash)
Definition: network.h:2033
TModeNet & GetModeNetByName(const TStr &ModeName) const
Gets a reference to the modenet.
Definition: mmnet.cpp:748
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
static const double Mn
Definition: dt.h:1387
Multimodal networks.
Definition: mmnet.h:504
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
Definition: ds.h:1110
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