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