SNAP Library 2.1, Developer Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
network.cpp
Go to the documentation of this file.
00001 
00002 // Attribute Node Edge Network
00003 bool TNEANet::HasFlag(const TGraphFlag& Flag) const {
00004   return HasGraphFlag(TNEANet::TNet, Flag);
00005 }
00006 
00007 bool TNEANet::TNodeI::IsInNId(const int& NId) const {
00008   const TNode& Node = NodeHI.GetDat();
00009   for (int edge = 0; edge < Node.GetInDeg(); edge++) {
00010     if (NId == Graph->GetEdge(Node.GetInEId(edge)).GetSrcNId())
00011       return true;
00012   }
00013   return false;
00014 }
00015 
00016 bool TNEANet::TNodeI::IsOutNId(const int& NId) const {
00017   const TNode& Node = NodeHI.GetDat();
00018   for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
00019     if (NId == Graph->GetEdge(Node.GetOutEId(edge)).GetDstNId())
00020       return true;
00021   }
00022   return false;
00023 }
00024 
00025 void TNEANet::AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
00026   Names = TVec<TStr>();
00027   while (!NodeHI.IsEnd()) {
00028     if (!NodeAttrIsDeleted(NId, NodeHI)) {
00029       Names.Add(NodeHI.GetKey());
00030     }
00031     NodeHI++;
00032   }  
00033 }
00034 
00035 void TNEANet::AttrValueNI(const TInt& NId , TStrIntPrH::TIter NodeHI, TStrV& Values) const {
00036   Values = TVec<TStr>();
00037   while (!NodeHI.IsEnd()) {
00038     if (!NodeAttrIsDeleted(NId, NodeHI)) {
00039       Values.Add(GetNodeAttrValue(NId, NodeHI));
00040     }
00041     NodeHI++;
00042   }
00043 }
00044 
00045 void TNEANet::IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
00046   Names = TVec<TStr>();
00047   while (!NodeHI.IsEnd()) {
00048     if (NodeHI.GetDat().Val1 == IntType && !NodeAttrIsIntDeleted(NId, NodeHI)) {
00049       Names.Add(NodeHI.GetKey());
00050     }
00051     NodeHI++;
00052   }  
00053 }
00054 
00055 void TNEANet::IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const {
00056   Values = TVec<TInt>();
00057   while (!NodeHI.IsEnd()) {
00058     if (NodeHI.GetDat().Val1 == IntType && !NodeAttrIsIntDeleted(NId, NodeHI)) {
00059       TInt val = this->VecOfIntVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NId);
00060       Values.Add(val);
00061     }
00062     NodeHI++;
00063   }  
00064 }
00065 
00066 void TNEANet::StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
00067   Names = TVec<TStr>();
00068   while (!NodeHI.IsEnd()) {
00069     if (NodeHI.GetDat().Val1 == StrType && !NodeAttrIsStrDeleted(NId, NodeHI)) {
00070       Names.Add(NodeHI.GetKey());
00071     }
00072     NodeHI++;
00073   }  
00074 }
00075 
00076 void TNEANet::StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const {
00077   Values = TVec<TStr>();
00078   while (!NodeHI.IsEnd()) {
00079     if (NodeHI.GetDat().Val1 == StrType && !NodeAttrIsStrDeleted(NId, NodeHI)) {
00080       TStr val = this->VecOfStrVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NId);
00081       Values.Add(val);
00082     }
00083     NodeHI++;
00084   }  
00085 }
00086 
00087 void TNEANet::FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const {
00088   Names = TVec<TStr>();
00089   while (!NodeHI.IsEnd()) {
00090     if (NodeHI.GetDat().Val1 == FltType && !NodeAttrIsFltDeleted(NId, NodeHI)) {
00091       Names.Add(NodeHI.GetKey());
00092     }
00093     NodeHI++;
00094   }  
00095 }
00096 
00097 void TNEANet::FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const {
00098   Values = TVec<TFlt>();
00099   while (!NodeHI.IsEnd()) {
00100     if (NodeHI.GetDat().Val1 == FltType && !NodeAttrIsFltDeleted(NId, NodeHI)) {
00101       TFlt val = (this->VecOfFltVecsN.GetVal(NodeHI.GetDat().Val2).GetVal(NId));
00102       Values.Add(val);
00103     }
00104     NodeHI++;
00105   }  
00106 }
00107 
00108 bool TNEANet::NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
00109   bool IntDel = NodeAttrIsIntDeleted(NId, NodeHI);
00110   bool StrDel = NodeAttrIsStrDeleted(NId, NodeHI);
00111   bool FltDel = NodeAttrIsFltDeleted(NId, NodeHI);
00112   return IntDel || StrDel || FltDel;
00113 }
00114 
00115 bool TNEANet::NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
00116   return (NodeHI.GetDat().Val1 == IntType &&
00117     GetIntAttrDefaultN(NodeHI.GetKey()) == this->VecOfIntVecsN.GetVal(
00118     this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NId));
00119 }
00120 
00121 bool TNEANet::NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
00122   return (NodeHI.GetDat().Val1 == StrType &&
00123     GetStrAttrDefaultN(NodeHI.GetKey()) == this->VecOfStrVecsN.GetVal(
00124     this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NId));
00125 }
00126 
00127 bool TNEANet::NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
00128   return (NodeHI.GetDat().Val1 == FltType &&
00129     GetFltAttrDefaultN(NodeHI.GetKey()) == this->VecOfFltVecsN.GetVal(
00130     this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NId));
00131 }
00132 
00133 TStr TNEANet::GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const {
00134   if (NodeHI.GetDat().Val1 == IntType) {
00135     return (this->VecOfIntVecsN.GetVal(
00136       this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NId)).GetStr();
00137   } else if(NodeHI.GetDat().Val1 == StrType) {
00138     return this->VecOfStrVecsN.GetVal(
00139     this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NId);
00140   } else if (NodeHI.GetDat().Val1 == FltType) {
00141     return (this->VecOfFltVecsN.GetVal(
00142       this->KeyToIndexTypeN.GetDat(NodeHI.GetKey()).Val2).GetVal(NId)).GetStr();
00143   }
00144   return TStr::GetNullStr();
00145 }
00146 
00147 void TNEANet::AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
00148   Names = TVec<TStr>();
00149   while (!EdgeHI.IsEnd()) {
00150     if (!EdgeAttrIsDeleted(EId, EdgeHI)) {
00151       Names.Add(EdgeHI.GetKey());
00152     }
00153     EdgeHI++;
00154   }  
00155 }
00156 
00157 void TNEANet::AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const {
00158   Values = TVec<TStr>();
00159   while (!EdgeHI.IsEnd()) {
00160     if (!EdgeAttrIsDeleted(EId, EdgeHI)) {
00161       Values.Add(GetNodeAttrValue(EId, EdgeHI));
00162     }
00163     EdgeHI++;
00164   }  
00165 }
00166 
00167 void TNEANet::IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
00168   Names = TVec<TStr>();
00169   while (!EdgeHI.IsEnd()) {
00170     if (EdgeHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, EdgeHI)) {
00171       Names.Add(EdgeHI.GetKey());
00172     }
00173     EdgeHI++;
00174   }  
00175 }
00176 
00177 void TNEANet::IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const {
00178   Values = TVec<TInt>();
00179   while (!EdgeHI.IsEnd()) {
00180     if (EdgeHI.GetDat().Val1 == IntType && !EdgeAttrIsIntDeleted(EId, EdgeHI)) {
00181       TInt val = (this->VecOfIntVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId));
00182       Values.Add(val);
00183     }
00184     EdgeHI++;
00185   }  
00186 }
00187 
00188 void TNEANet::StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
00189   Names = TVec<TStr>();
00190   while (!EdgeHI.IsEnd()) {
00191     if (EdgeHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, EdgeHI)) {
00192       Names.Add(EdgeHI.GetKey());
00193     }
00194     EdgeHI++;
00195   }  
00196 }
00197 
00198 void TNEANet::StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const {
00199   Values = TVec<TStr>();
00200   while (!EdgeHI.IsEnd()) {
00201     if (EdgeHI.GetDat().Val1 == StrType && !EdgeAttrIsStrDeleted(EId, EdgeHI)) {
00202       TStr val = this->VecOfStrVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId);
00203       Values.Add(val);
00204     }
00205     EdgeHI++;
00206   }  
00207 }
00208 
00209 void TNEANet::FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const {
00210   Names = TVec<TStr>();
00211   while (!EdgeHI.IsEnd()) {
00212     if (EdgeHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, EdgeHI)) {
00213       Names.Add(EdgeHI.GetKey());
00214     }
00215     EdgeHI++;
00216   }  
00217 }
00218 
00219 void TNEANet::FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const {
00220   Values = TVec<TFlt>();
00221   while (!EdgeHI.IsEnd()) {
00222     if (EdgeHI.GetDat().Val1 == FltType && !EdgeAttrIsFltDeleted(EId, EdgeHI)) {
00223       TFlt val = (this->VecOfFltVecsE.GetVal(EdgeHI.GetDat().Val2).GetVal(EId));
00224       Values.Add(val);
00225     }
00226     EdgeHI++;
00227   }  
00228 }
00229 
00230 bool TNEANet::EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
00231   bool IntDel = EdgeAttrIsIntDeleted(EId, EdgeHI);
00232   bool StrDel = EdgeAttrIsStrDeleted(EId, EdgeHI);
00233   bool FltDel = EdgeAttrIsFltDeleted(EId, EdgeHI);
00234   return IntDel || StrDel || FltDel;
00235 }
00236 
00237 bool TNEANet::EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
00238   return (EdgeHI.GetDat().Val1 == IntType &&
00239     GetIntAttrDefaultE(EdgeHI.GetKey()) == this->VecOfIntVecsE.GetVal(
00240     this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EId));
00241 }
00242 
00243 bool TNEANet::EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
00244   return (EdgeHI.GetDat().Val1 == StrType &&
00245     GetStrAttrDefaultE(EdgeHI.GetKey()) == this->VecOfStrVecsE.GetVal(
00246     this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EId));
00247 }
00248 
00249 bool TNEANet::EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
00250   return (EdgeHI.GetDat().Val1 == FltType &&
00251     GetFltAttrDefaultE(EdgeHI.GetKey()) == this->VecOfFltVecsE.GetVal(
00252     this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EId));
00253 }
00254 
00255 TStr TNEANet::GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const {
00256   if (EdgeHI.GetDat().Val1 == IntType) {
00257     return (this->VecOfIntVecsE.GetVal(
00258       this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EId)).GetStr();
00259   } else if(EdgeHI.GetDat().Val1 == StrType) {
00260     return this->VecOfStrVecsE.GetVal(
00261     this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EId);
00262   } else if (EdgeHI.GetDat().Val1 == FltType) {
00263     return (this->VecOfFltVecsE.GetVal(
00264       this->KeyToIndexTypeE.GetDat(EdgeHI.GetKey()).Val2).GetVal(EId)).GetStr();
00265   }
00266   return TStr::GetNullStr();
00267 }
00268 
00269 int TNEANet::AddNode(int NId) {
00270   int i;
00271   if (NId == -1) {
00272     NId = MxNId;  MxNId++;
00273   } else {
00274     IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
00275     MxNId = TMath::Mx(NId+1, MxNId());
00276   }
00277   // update attribute columns
00278   NodeH.AddDat(NId, TNode(NId));
00279   for (i = 0; i < VecOfIntVecsN.Len(); i++) {
00280     TVec<TInt>& IntVec = VecOfIntVecsN[i];
00281     IntVec.Ins(NodeH.GetKeyId(NId), TInt::Mn);
00282   }
00283   TVec<TStr> DefIntVec = TVec<TStr>();
00284   IntDefaultsN.GetKeyV(DefIntVec);
00285   for (i = 0; i < DefIntVec.Len(); i++) {
00286     TStr attr = DefIntVec[i];
00287     TVec<TInt>& IntVec = VecOfIntVecsN[KeyToIndexTypeN.GetDat(DefIntVec[i]).Val2];
00288     IntVec[NodeH.GetKeyId(NId)] = GetIntAttrDefaultN(attr);
00289   }
00290   for (i = 0; i < VecOfStrVecsN.Len(); i++) {
00291     TVec<TStr>& StrVec = VecOfStrVecsN[i];
00292     StrVec.Ins(NodeH.GetKeyId(NId), TStr::GetNullStr());
00293   }
00294   TVec<TStr> DefStrVec = TVec<TStr>();
00295   IntDefaultsN.GetKeyV(DefStrVec);
00296   for (i = 0; i < DefStrVec.Len(); i++) {
00297     TStr attr = DefStrVec[i];
00298     TVec<TStr>& StrVec = VecOfStrVecsN[KeyToIndexTypeN.GetDat(DefStrVec[i]).Val2];
00299     StrVec[NodeH.GetKeyId(NId)] = GetStrAttrDefaultN(attr);
00300   }
00301   for (i = 0; i < VecOfFltVecsN.Len(); i++) {
00302     TVec<TFlt>& FltVec = VecOfFltVecsN[i];
00303     FltVec.Ins(NodeH.GetKeyId(NId), TFlt::Mn);
00304   }
00305   TVec<TStr> DefFltVec = TVec<TStr>();
00306   FltDefaultsN.GetKeyV(DefFltVec);
00307   for (i = 0; i < DefFltVec.Len(); i++) {
00308     TStr attr = DefFltVec[i];
00309     TVec<TFlt>& FltVec = VecOfFltVecsN[KeyToIndexTypeN.GetDat(DefFltVec[i]).Val2];
00310     FltVec[NodeH.GetKeyId(NId)] = GetFltAttrDefaultN(attr);
00311   }
00312   return NId;
00313 }
00314 
00315 void TNEANet::DelNode(const int& NId) {
00316   int i;
00317   
00318   const TNode& Node = GetNode(NId);
00319   for (int out = 0; out < Node.GetOutDeg(); out++) {
00320     const int EId = Node.GetOutEId(out);
00321     const TEdge& Edge = GetEdge(EId);
00322     IAssert(Edge.GetSrcNId() == NId);
00323     GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
00324     EdgeH.DelKey(EId);
00325     // Delete from Edge Attributes
00326     for (i = 0; i < VecOfIntVecsE.Len(); i++) {
00327       TVec<TInt>& IntVec = VecOfIntVecsE[i];
00328       IntVec.Ins(EdgeH.GetKeyId(EId), TInt::Mn);
00329     }
00330     for (i = 0; i < VecOfStrVecsE.Len(); i++) {
00331       TVec<TStr>& StrVec = VecOfStrVecsE[i];
00332       StrVec.Ins(EdgeH.GetKeyId(EId), TStr::GetNullStr());
00333     }
00334     for (i = 0; i < VecOfFltVecsE.Len(); i++) {
00335       TVec<TFlt>& FltVec = VecOfFltVecsE[i];
00336       FltVec.Ins(EdgeH.GetKeyId(EId), TFlt::Mn);
00337     }
00338   }
00339   for (int in = 0; in < Node.GetInDeg(); in++) {
00340     const int EId = Node.GetInEId(in);
00341     const TEdge& Edge = GetEdge(EId);
00342     IAssert(Edge.GetDstNId() == NId);
00343     GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
00344     EdgeH.DelKey(EId);
00345     // Delete from Edge Attributes
00346     for (i = 0; i < VecOfIntVecsE.Len(); i++) {
00347       TVec<TInt>& IntVec = VecOfIntVecsE[i];
00348       IntVec.Ins(EdgeH.GetKeyId(EId), TInt::Mn);
00349     }
00350     for (i = 0; i < VecOfStrVecsE.Len(); i++) {
00351       TVec<TStr>& StrVec = VecOfStrVecsE[i];
00352       StrVec.Ins(EdgeH.GetKeyId(EId), TStr::GetNullStr());
00353     }
00354     for (i = 0; i < VecOfFltVecsE.Len(); i++) {
00355       TVec<TFlt>& FltVec = VecOfFltVecsE[i];
00356       FltVec.Ins(EdgeH.GetKeyId(EId), TFlt::Mn);
00357     }
00358   }
00359 
00360   for (i = 0; i < VecOfIntVecsN.Len(); i++) {
00361     TVec<TInt>& IntVec = VecOfIntVecsN[i];
00362     IntVec.Ins(NodeH.GetKeyId(NId), TInt::Mn);
00363   }
00364   for (i = 0; i < VecOfStrVecsN.Len(); i++) {
00365     TVec<TStr>& StrVec = VecOfStrVecsN[i];
00366     StrVec.Ins(NodeH.GetKeyId(NId), TStr::GetNullStr());
00367   }
00368   for (i = 0; i < VecOfFltVecsN.Len(); i++) {
00369     TVec<TFlt>& FltVec = VecOfFltVecsN[i];
00370     FltVec.Ins(NodeH.GetKeyId(NId), TFlt::Mn);
00371   }
00372   NodeH.DelKey(NId);
00373 }
00374 
00375 int TNEANet::AddEdge(const int& SrcNId, const int& DstNId, int EId) {
00376   int i;
00377 
00378   if (EId == -1) { EId = MxEId;  MxEId++; }
00379   else { MxEId = TMath::Mx(EId+1, MxEId()); }
00380   IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
00381   IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
00382   EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
00383   GetNode(SrcNId).OutEIdV.AddSorted(EId);
00384   GetNode(DstNId).InEIdV.AddSorted(EId);
00385 
00386   // update attribute columns
00387   for (i = 0; i < VecOfIntVecsE.Len(); i++) {
00388     TVec<TInt>& IntVec = VecOfIntVecsE[i];
00389     IntVec.Ins(EdgeH.GetKeyId(EId), TInt::Mn);
00390   }
00391   TVec<TStr> DefIntVec = TVec<TStr>();
00392   IntDefaultsE.GetKeyV(DefIntVec);
00393   for (i = 0; i < DefIntVec.Len(); i++) {
00394     TStr attr = DefIntVec[i];
00395     TVec<TInt>& IntVec = VecOfIntVecsE[KeyToIndexTypeE.GetDat(DefIntVec[i]).Val2];
00396     IntVec[EdgeH.GetKeyId(EId)] = GetIntAttrDefaultE(attr);
00397   }
00398 
00399   for (i = 0; i < VecOfStrVecsE.Len(); i++) {
00400     TVec<TStr>& StrVec = VecOfStrVecsE[i];
00401     StrVec.Ins(EdgeH.GetKeyId(EId), TStr::GetNullStr());
00402   }
00403   TVec<TStr> DefStrVec = TVec<TStr>();
00404   IntDefaultsE.GetKeyV(DefStrVec);
00405   for (i = 0; i < DefStrVec.Len(); i++) {
00406     TStr attr = DefStrVec[i];
00407     TVec<TStr>& StrVec = VecOfStrVecsE[KeyToIndexTypeE.GetDat(DefStrVec[i]).Val2];
00408     StrVec[EdgeH.GetKeyId(EId)] = GetStrAttrDefaultE(attr);
00409   }
00410 
00411   for (i = 0; i < VecOfFltVecsE.Len(); i++) {
00412     TVec<TFlt>& FltVec = VecOfFltVecsE[i];
00413     FltVec.Ins(EdgeH.GetKeyId(EId), TFlt::Mn);
00414   }
00415   TVec<TStr> DefFltVec = TVec<TStr>();
00416   FltDefaultsE.GetKeyV(DefFltVec);
00417   for (i = 0; i < DefFltVec.Len(); i++) {
00418     TStr attr = DefFltVec[i];
00419     TVec<TFlt>& FltVec = VecOfFltVecsE[KeyToIndexTypeE.GetDat(DefFltVec[i]).Val2];
00420     FltVec[NodeH.GetKeyId(EId)] = GetFltAttrDefaultE(attr);
00421   }
00422   return EId;
00423 }
00424 
00425 void TNEANet::DelEdge(const int& EId) {
00426   int i;
00427 
00428   IAssert(IsEdge(EId));
00429   const int SrcNId = GetEdge(EId).GetSrcNId();
00430   const int DstNId = GetEdge(EId).GetDstNId();
00431   GetNode(SrcNId).OutEIdV.DelIfIn(EId);
00432   GetNode(DstNId).InEIdV.DelIfIn(EId);
00433   EdgeH.DelKey(EId);
00434 
00435   for (i = 0; i < VecOfIntVecsE.Len(); i++) {
00436     TVec<TInt>& IntVec = VecOfIntVecsE[i];
00437     IntVec.Ins(EdgeH.GetKeyId(EId), TInt::Mn);
00438   }
00439   for (i = 0; i < VecOfStrVecsE.Len(); i++) {
00440     TVec<TStr>& StrVec = VecOfStrVecsE[i];
00441     StrVec.Ins(EdgeH.GetKeyId(EId), TStr::GetNullStr());
00442   }
00443   for (i = 0; i < VecOfFltVecsE.Len(); i++) {
00444     TVec<TFlt>& FltVec = VecOfFltVecsE[i];
00445     FltVec.Ins(EdgeH.GetKeyId(EId), TFlt::Mn);
00446   }
00447 }
00448 
00449 // delete all edges between the two nodes
00450 void TNEANet::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
00451   int EId;
00452   IAssert(IsEdge(SrcNId, DstNId, EId, IsDir)); // there is at least one edge
00453   while (IsEdge(SrcNId, DstNId, EId, IsDir)) {
00454     GetNode(SrcNId).OutEIdV.DelIfIn(EId);
00455     GetNode(DstNId).InEIdV.DelIfIn(EId);
00456   }
00457   EdgeH.DelKey(EId);
00458 }
00459 
00460 bool TNEANet::IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir) const {
00461   const TNode& SrcNode = GetNode(SrcNId);
00462   for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
00463     const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
00464     if (DstNId == Edge.GetDstNId()) {
00465       EId = Edge.GetId();
00466       return true;
00467     }
00468   }
00469   if (! IsDir) {
00470     for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
00471       const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
00472       if (DstNId == Edge.GetSrcNId()) {
00473         EId = Edge.GetId();
00474         return true;
00475       }
00476     }
00477   }
00478   return false;
00479 }
00480 
00481 void TNEANet::GetNIdV(TIntV& NIdV) const {
00482   NIdV.Gen(GetNodes(), 0);
00483   for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
00484     NIdV.Add(NodeH.GetKey(N));
00485   }
00486 }
00487 
00488 void TNEANet::GetEIdV(TIntV& EIdV) const {
00489   EIdV.Gen(GetEdges(), 0);
00490   for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
00491     EIdV.Add(EdgeH.GetKey(E));
00492   }
00493 }
00494 
00495 void TNEANet::Defrag(const bool& OnlyNodeLinks) {
00496   for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid); ) {
00497     TNode& Node = NodeH[kid];
00498     Node.InEIdV.Pack();  Node.OutEIdV.Pack();
00499   }
00500   if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
00501   if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
00502 }
00503 
00504 bool TNEANet::IsOk(const bool& ThrowExcept) const {
00505   bool RetVal = true;
00506   for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
00507     const TNode& Node = NodeH[N];
00508     if (! Node.OutEIdV.IsSorted()) {
00509       const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
00510       if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00511     }
00512     if (! Node.InEIdV.IsSorted()) {
00513       const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
00514       if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00515     }
00516     // check out-edge ids
00517     int prevEId = -1;
00518     for (int e = 0; e < Node.GetOutDeg(); e++) {
00519       if (! IsEdge(Node.GetOutEId(e))) {
00520         const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.",  Node.GetOutEId(e), Node.GetId());
00521         if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00522       }
00523       if (e > 0 && prevEId == Node.GetOutEId(e)) {
00524         const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
00525         if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00526       }
00527       prevEId = Node.GetOutEId(e);
00528     }
00529     // check in-edge ids
00530     prevEId = -1;
00531     for (int e = 0; e < Node.GetInDeg(); e++) {
00532       if (! IsEdge(Node.GetInEId(e))) {
00533       const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.",  Node.GetInEId(e), Node.GetId());
00534       if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00535       }
00536       if (e > 0 && prevEId == Node.GetInEId(e)) {
00537         const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
00538         if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00539       }
00540       prevEId = Node.GetInEId(e);
00541     }
00542   }
00543   for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
00544     const TEdge& Edge = EdgeH[E];
00545     if (! IsNode(Edge.GetSrcNId())) {
00546       const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
00547       if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00548     }
00549     if (! IsNode(Edge.GetDstNId())) {
00550       const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
00551       if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
00552     }
00553   }
00554   return RetVal;
00555 }
00556 
00557 void TNEANet::Dump(FILE *OutF) const {
00558   const int NodePlaces = (int) ceil(log10((double) GetNodes()));
00559   const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
00560   fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
00561   for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
00562     fprintf(OutF, "  %*d]\n", NodePlaces, NodeI.GetId());
00563     // load node attributes
00564     TIntV IntAttrN;
00565     IntAttrValueNI(NodeI.GetId(), IntAttrN);
00566     fprintf(OutF, "    nai[%d]", IntAttrN.Len());
00567     for (int i = 0; i < IntAttrN.Len(); i++) {
00568       fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
00569     TStrV StrAttrN;
00570     StrAttrValueNI(NodeI.GetId(), StrAttrN);
00571     fprintf(OutF, "    nas[%d]", StrAttrN.Len());
00572     for (int i = 0; i < StrAttrN.Len(); i++) {
00573       fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
00574     TFltV FltAttrN;
00575     FltAttrValueNI(NodeI.GetId(), FltAttrN);
00576     fprintf(OutF, "    naf[%d]", FltAttrN.Len());
00577     for (int i = 0; i < FltAttrN.Len(); i++) {
00578       fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }
00579 
00580     fprintf(OutF, "    in[%d]", NodeI.GetInDeg());
00581     for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
00582       fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
00583     fprintf(OutF, "\n    out[%d]", NodeI.GetOutDeg());
00584     for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
00585       fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
00586    
00587     fprintf(OutF, "\n");
00588   }
00589   for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
00590     fprintf(OutF, "  %*d]  %*d  ->  %*d\n", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
00591 
00592     // load edge attributes
00593     TIntV IntAttrE;
00594     IntAttrValueEI(EdgeI.GetId(), IntAttrE);
00595     fprintf(OutF, "    eai[%d]", IntAttrE.Len());
00596     for (int i = 0; i < IntAttrE.Len(); i++) {
00597       fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]()); }
00598     TStrV StrAttrE;
00599     StrAttrValueEI(EdgeI.GetId(), StrAttrE);
00600     fprintf(OutF, "    eas[%d]", StrAttrE.Len());
00601     for (int i = 0; i < StrAttrE.Len(); i++) {
00602       fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]()); }
00603     TFltV FltAttrE;
00604     FltAttrValueEI(EdgeI.GetId(), FltAttrE);
00605     fprintf(OutF, "    eaf[%d]", FltAttrE.Len());
00606     for (int i = 0; i < FltAttrE.Len(); i++) {
00607       fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]()); }
00608   }
00609   fprintf(OutF, "\n");
00610 }
00611 
00612 // Attribute related function
00613 
00614 int TNEANet::AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr) {
00615   int i;
00616   TInt CurrLen;
00617   if (!IsNode(NId)) {
00618     // AddNode(NId);
00619     return -1;
00620   }
00621   if (KeyToIndexTypeN.IsKey(attr)) {
00622     TVec<TInt>& NewVec = VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2];
00623     NewVec[NodeH.GetKeyId(NId)] = value;
00624   } else {
00625     CurrLen = VecOfIntVecsN.Len();
00626     KeyToIndexTypeN.AddDat(attr, TIntPr(IntType, CurrLen));
00627     TVec<TInt> NewVec = TVec<TInt>();
00628     for (i = 0; i < MxNId; i++) {
00629       NewVec.Ins(i, GetIntAttrDefaultN(attr));
00630     }
00631     NewVec[NodeH.GetKeyId(NId)] = value;
00632     VecOfIntVecsN.Add(NewVec);
00633   }
00634   return 0;
00635 } 
00636 
00637 int TNEANet::AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr) {
00638   int i;
00639   TInt CurrLen;
00640   if (!IsNode(NId)) {
00641     // AddNode(NId);
00642     return -1;
00643   }
00644   if (KeyToIndexTypeN.IsKey(attr)) {
00645     TVec<TStr>& NewVec = VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2];
00646     NewVec[NodeH.GetKeyId(NId)] = value;
00647   } else {
00648     CurrLen = VecOfStrVecsN.Len();
00649     KeyToIndexTypeN.AddDat(attr, TIntPr(StrType, CurrLen));
00650     TVec<TStr> NewVec = TVec<TStr>();
00651     for (i = 0; i < MxNId; i++) {
00652         NewVec.Ins(i, GetStrAttrDefaultN(attr));
00653     }
00654     NewVec[NodeH.GetKeyId(NId)] = value;
00655     VecOfStrVecsN.Add(NewVec);
00656   }
00657   return 0;
00658 } 
00659 
00660 int TNEANet::AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr) {
00661   int i;
00662   TInt CurrLen;
00663 
00664   if (!IsNode(NId)) {
00665     // AddNode(NId);
00666     return -1;
00667   }
00668   if (KeyToIndexTypeN.IsKey(attr)) {
00669     TVec<TFlt>& NewVec = VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2];
00670     NewVec[NodeH.GetKeyId(NId)] = value;
00671   } else {
00672     CurrLen = VecOfFltVecsN.Len();
00673     KeyToIndexTypeN.AddDat(attr, TIntPr(FltType, CurrLen));
00674     TVec<TFlt> NewVec = TVec<TFlt>();
00675     for (i = 0; i < MxNId; i++) {
00676       NewVec.Ins(i, GetFltAttrDefaultN(attr));
00677     }
00678     NewVec[NodeH.GetKeyId(NId)] = value;
00679     VecOfFltVecsN.Add(NewVec);
00680   }
00681   return 0;
00682 } 
00683 
00684 int TNEANet::AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr) {
00685   int i;
00686   TInt CurrLen;
00687   if (!IsEdge(EId)) {
00688     //AddEdge(EId);
00689      return -1;
00690   }
00691   if (KeyToIndexTypeE.IsKey(attr)) {
00692     TVec<TInt>& NewVec = VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2];
00693     NewVec[EdgeH.GetKeyId(EId)] = value;
00694   } else {
00695     CurrLen = VecOfIntVecsE.Len();
00696     KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
00697     TVec<TInt> NewVec = TVec<TInt>();
00698     for (i = 0; i < MxEId; i++) {
00699       NewVec.Ins(i, GetIntAttrDefaultE(attr));
00700     }
00701     NewVec[EdgeH.GetKeyId(EId)] = value;
00702     VecOfIntVecsE.Add(NewVec);
00703   }
00704   return 0;
00705 } 
00706 
00707 int TNEANet::AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr) {
00708   int i;
00709   TInt CurrLen;
00710   if (!IsEdge(EId)) {
00711     //AddEdge(EId);
00712      return -1;
00713   }
00714   if (KeyToIndexTypeE.IsKey(attr)) {
00715     TVec<TStr>& NewVec = VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2];
00716     NewVec[EdgeH.GetKeyId(EId)] = value;
00717   } else {
00718     CurrLen = VecOfStrVecsE.Len();
00719     KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
00720     TVec<TStr> NewVec = TVec<TStr>();
00721     for (i = 0; i < MxEId; i++) {
00722       NewVec.Ins(i, GetStrAttrDefaultE(attr));
00723     }
00724     NewVec[EdgeH.GetKeyId(EId)] = value;
00725     VecOfStrVecsE.Add(NewVec);
00726   }
00727   return 0;
00728 } 
00729 
00730 int TNEANet::AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr) {
00731   int i;
00732   TInt CurrLen;
00733 
00734   if (!IsEdge(EId)) {
00735     //AddEdge(EId);
00736      return -1;
00737   }
00738   if (KeyToIndexTypeE.IsKey(attr)) {
00739     TVec<TFlt>& NewVec = VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2];
00740     NewVec[EdgeH.GetKeyId(EId)] = value;
00741   } else {
00742     CurrLen = VecOfFltVecsE.Len();
00743     KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
00744     TVec<TFlt> NewVec = TVec<TFlt>();
00745     for (i = 0; i < MxEId; i++) {
00746       NewVec.Ins(i, GetFltAttrDefaultE(attr));
00747     }
00748     NewVec[EdgeH.GetKeyId(EId)] = value;
00749     VecOfFltVecsE.Add(NewVec);
00750   }
00751   return 0;
00752 } 
00753 
00754 TInt TNEANet::GetIntAttrDatN(const int& NId, const TStr& attr) {
00755   return VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NId];
00756 }
00757 
00758 TStr TNEANet::GetStrAttrDatN(const int& NId, const TStr& attr) {
00759   return VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NId];
00760 }
00761 
00762 TFlt TNEANet::GetFltAttrDatN(const int& NId, const TStr& attr) {
00763   return VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NId];
00764 }
00765 
00766 TInt TNEANet::GetIntAttrDatE(const int& EId, const TStr& attr) {
00767   return VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EId];
00768 }
00769 
00770 TStr TNEANet::GetStrAttrDatE(const int& EId, const TStr& attr) {
00771   return VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EId];
00772 }
00773 
00774 TFlt TNEANet::GetFltAttrDatE(const int& EId, const TStr& attr) {
00775   return VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EId];
00776 }
00777 
00778 int TNEANet::DelAttrDatN(const int& NId, const TStr& attr) {
00779   TInt vecType = KeyToIndexTypeN(attr).Val1;
00780   if (vecType == IntType) {
00781     VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NId] = GetIntAttrDefaultN(attr);
00782   } else if (vecType == StrType) {
00783     VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NId] = GetStrAttrDefaultN(attr);
00784   } else if (vecType == FltType) {
00785     VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2][NId] = GetFltAttrDefaultN(attr);
00786   } else {
00787     return -1;
00788   }
00789   return 0;
00790 }
00791                                
00792 int TNEANet::DelAttrDatE(const int& EId, const TStr& attr) {
00793   // TODO(nkhadke): add error checking
00794   TInt vecType = KeyToIndexTypeE(attr).Val1;
00795   if (vecType == IntType) {
00796     VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EId] = GetIntAttrDefaultE(attr);
00797   } else if (vecType == StrType) {
00798     VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EId] = GetStrAttrDefaultE(attr);
00799   } else if (vecType == FltType) {
00800     VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2][EId] = GetFltAttrDefaultE(attr);
00801   } else {
00802     return -1;
00803   }
00804   return 0;
00805 }
00806 
00807 int TNEANet::AddIntAttrN(const TStr& attr, TInt defaultValue){
00808   int i;
00809   TInt CurrLen;
00810   TVec<TInt> NewVec;
00811   CurrLen = VecOfIntVecsN.Len();
00812   KeyToIndexTypeN.AddDat(attr, TIntPr(IntType, CurrLen));
00813   NewVec = TVec<TInt>();
00814   for (i = 0; i < MxNId; i++) {
00815     NewVec.Ins(i, defaultValue);
00816   }
00817   VecOfIntVecsN.Add(NewVec);
00818   if (!IntDefaultsN.IsKey(attr)) {
00819     IntDefaultsN.AddDat(attr, defaultValue);
00820   } else {
00821     return -1;
00822   }
00823   return 0;
00824 }
00825 
00826 int TNEANet::AddStrAttrN(const TStr& attr, TStr defaultValue) {
00827   int i;
00828   TInt CurrLen;
00829   TVec<TStr> NewVec;
00830   CurrLen = VecOfStrVecsN.Len();
00831   KeyToIndexTypeN.AddDat(attr, TIntPr(StrType, CurrLen));
00832   NewVec = TVec<TStr>();
00833   for (i = 0; i < MxNId; i++) {
00834     NewVec.Ins(i, defaultValue);
00835   }
00836   VecOfStrVecsN.Add(NewVec);
00837   if (!StrDefaultsN.IsKey(attr)) {
00838     StrDefaultsN.AddDat(attr, defaultValue);
00839   } else {
00840     return -1;
00841   }
00842   return 0;
00843 }
00844 
00845 int TNEANet::AddFltAttrN(const TStr& attr, TFlt defaultValue) {
00846   // TODO(nkhadke): add error checking
00847   int i;
00848   TInt CurrLen;
00849   TVec<TFlt> NewVec;
00850   CurrLen = VecOfStrVecsN.Len();
00851   KeyToIndexTypeN.AddDat(attr, TIntPr(FltType, CurrLen));
00852   NewVec = TVec<TFlt>();
00853   for (i = 0; i < MxNId; i++) {
00854     NewVec.Ins(i, defaultValue);
00855   }
00856   VecOfFltVecsN.Add(NewVec);
00857   if (!FltDefaultsN.IsKey(attr)) {
00858     FltDefaultsN.AddDat(attr, defaultValue);
00859   } else {
00860     return -1;
00861   }
00862   return 0;
00863 }
00864 
00865 int TNEANet::AddIntAttrE(const TStr& attr, TInt defaultValue){
00866   // TODO(nkhadke): add error checking
00867   int i;
00868   TInt CurrLen;
00869   TVec<TInt> NewVec;
00870   CurrLen = VecOfIntVecsE.Len();
00871   KeyToIndexTypeE.AddDat(attr, TIntPr(IntType, CurrLen));
00872   NewVec = TVec<TInt>();
00873   for (i = 0; i < MxEId; i++) {
00874     NewVec.Ins(i, defaultValue);
00875   }
00876   VecOfIntVecsE.Add(NewVec);
00877   if (!IntDefaultsE.IsKey(attr)) {
00878     IntDefaultsE.AddDat(attr, defaultValue);
00879   } else {
00880     return -1;
00881   }
00882   return 0;
00883 }
00884 
00885 int TNEANet::AddStrAttrE(const TStr& attr, TStr defaultValue) {
00886   int i;
00887   TInt CurrLen;
00888   TVec<TStr> NewVec;
00889   CurrLen = VecOfStrVecsE.Len();
00890   KeyToIndexTypeE.AddDat(attr, TIntPr(StrType, CurrLen));
00891   NewVec = TVec<TStr>();
00892   for (i = 0; i < MxEId; i++) {
00893     NewVec.Ins(i, defaultValue);
00894   }
00895   VecOfStrVecsE.Add(NewVec);
00896   if (!StrDefaultsE.IsKey(attr)) {
00897     StrDefaultsE.AddDat(attr, defaultValue);
00898   } else {
00899     return -1;
00900   }
00901   return 0;
00902 }
00903 
00904 int TNEANet::AddFltAttrE(const TStr& attr, TFlt defaultValue) {
00905   int i;
00906   TInt CurrLen;
00907   TVec<TFlt> NewVec;
00908   CurrLen = VecOfStrVecsE.Len();
00909   KeyToIndexTypeE.AddDat(attr, TIntPr(FltType, CurrLen));
00910   NewVec = TVec<TFlt>();
00911   for (i = 0; i < MxEId; i++) {
00912     NewVec.Ins(i, defaultValue);
00913   }
00914   VecOfFltVecsE.Add(NewVec);
00915   if (!FltDefaultsE.IsKey(attr)) {
00916     FltDefaultsE.AddDat(attr, defaultValue);
00917   } else {
00918     return -1;
00919   }
00920   return 0;
00921 }
00922 
00923 int TNEANet::DelAttrN(const TStr& attr) {
00924   TInt vecType = KeyToIndexTypeN(attr).Val1;
00925   if (vecType == IntType) {
00926     VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2] = TVec<TInt>();
00927     if (IntDefaultsN.IsKey(attr)) {
00928       IntDefaultsN.DelKey(attr);
00929     }
00930   } else if (vecType == StrType) {
00931     VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2] = TVec<TStr>();  
00932     if (StrDefaultsN.IsKey(attr)) {
00933       StrDefaultsN.DelKey(attr);
00934     }
00935   } else if (vecType == FltType) {
00936     VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2] = TVec<TFlt>();
00937     if (FltDefaultsN.IsKey(attr)) {
00938       FltDefaultsN.DelKey(attr);
00939     }
00940   } else {
00941     return -1;
00942   }
00943   KeyToIndexTypeN.DelKey(attr);
00944   return 0;
00945 }
00946 
00947 int TNEANet::DelAttrE(const TStr& attr) {
00948   TInt vecType = KeyToIndexTypeE(attr).Val1;
00949   if (vecType == IntType) {
00950     VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2] = TVec<TInt>();
00951     if (IntDefaultsE.IsKey(attr)) {
00952       IntDefaultsE.DelKey(attr);
00953     }
00954   } else if (vecType == StrType) {
00955     VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2] = TVec<TStr>();
00956     if (StrDefaultsE.IsKey(attr)) {
00957       StrDefaultsE.DelKey(attr);
00958     }  
00959   } else if (vecType == FltType) {
00960     VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2] = TVec<TFlt>();
00961     if (FltDefaultsE.IsKey(attr)) {
00962       FltDefaultsE.DelKey(attr);
00963     }
00964   } else {
00965     return -1;
00966   }
00967   KeyToIndexTypeE.DelKey(attr);
00968   return 0;
00969 }