17 const TNode& Node = NodeHI.GetDat();
27 while (!NodeHI.
IsEnd()) {
37 while (!NodeHI.
IsEnd()) {
47 while (!NodeHI.
IsEnd()) {
57 while (!NodeHI.
IsEnd()) {
68 while (!NodeHI.
IsEnd()) {
78 while (!NodeHI.
IsEnd()) {
89 while (!NodeHI.
IsEnd()) {
99 while (!NodeHI.
IsEnd()) {
110 while (!NodeHI.
IsEnd()) {
120 while (!NodeHI.
IsEnd()) {
134 return IntDel || StrDel || FltDel || IntVDel;
158 return IntDel || StrDel || FltDel || IntVDel;
209 while (!EdgeHI.
IsEnd()) {
219 while (!EdgeHI.
IsEnd()) {
229 while (!EdgeHI.
IsEnd()) {
239 while (!EdgeHI.
IsEnd()) {
250 while (!EdgeHI.
IsEnd()) {
260 while (!EdgeHI.
IsEnd()) {
271 while (!EdgeHI.
IsEnd()) {
281 while (!EdgeHI.
IsEnd()) {
292 while (!EdgeHI.
IsEnd()) {
302 while (!EdgeHI.
IsEnd()) {
316 return IntDel || StrDel || FltDel || IntVDel;
340 return IntDel || StrDel || FltDel || IntVDel;
394 if (IntVec.
Len() > KeyId) {
402 for (i = 0; i < DefIntVec.
Len(); i++) {
403 TStr attr = DefIntVec[i];
410 if (StrVec.
Len() > KeyId) {
418 for (i = 0; i < DefStrVec.
Len(); i++) {
419 TStr attr = DefStrVec[i];
426 if (FltVec.
Len() > KeyId) {
434 for (i = 0; i < DefFltVec.
Len(); i++) {
435 TStr attr = DefFltVec[i];
442 if (IntVecV.
Len() > KeyId) {
443 IntVecV[KeyId] =
TIntV();
456 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
480 for (
int in = 0; in < Node.
GetInDeg(); in++) {
539 if (IntVec.
Len() > KeyId) {
547 for (i = 0; i < DefIntVec.
Len(); i++) {
548 TStr attr = DefIntVec[i];
561 if (StrVec.
Len() > KeyId) {
569 for (i = 0; i < DefStrVec.
Len(); i++) {
570 TStr attr = DefStrVec[i];
578 if (FltVec.
Len() > KeyId) {
586 for (i = 0; i < DefFltVec.
Len(); i++) {
587 TStr attr = DefFltVec[i];
624 bool Edge =
IsEdge(SrcNId, DstNId, EId, IsDir);
628 Edge =
IsEdge(SrcNId, DstNId, EId, IsDir);
632 bool TNEANet::IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir)
const {
690 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
695 if (e > 0 && prevEId == Node.
GetOutEId(e)) {
703 for (
int e = 0; e < Node.
GetInDeg(); e++) {
708 if (e > 0 && prevEId == Node.
GetInEId(e)) {
730 const int NodePlaces = (int) ceil(log10((
double)
GetNodes()));
731 const int EdgePlaces = (int) ceil(log10((
double)
GetEdges()));
732 fprintf(OutF,
"-------------------------------------------------\nDirected Node-Edge Network with Attributes: nodes: %d, edges: %d\n",
GetNodes(),
GetEdges());
734 fprintf(OutF,
" %*d:", NodePlaces, NodeI.GetId());
735 fprintf(OutF,
" in[%d]", NodeI.GetInDeg());
737 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetInEId(
edge)); }
739 fprintf(OutF,
" out[%d]", NodeI.GetOutDeg());
741 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetOutEId(
edge)); }
747 fprintf(OutF,
" nai[%d]", IntAttrN.
Len());
748 for (
int i = 0; i < IntAttrN.
Len(); i++) {
749 fprintf(OutF,
" %*i", NodePlaces, IntAttrN[i]()); }
754 fprintf(OutF,
" nas[%d]", StrAttrN.
Len());
755 for (
int i = 0; i < StrAttrN.
Len(); i++) {
756 fprintf(OutF,
" %*s", NodePlaces, StrAttrN[i]()); }
761 fprintf(OutF,
" naf[%d]", FltAttrN.
Len());
762 for (
int i = 0; i < FltAttrN.
Len(); i++) {
763 fprintf(OutF,
" %*f", NodePlaces, FltAttrN[i]()); }
768 fprintf(OutF,
" %*d: %*d -> %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
773 fprintf(OutF,
" eai[%d]", IntAttrE.Len());
774 for (
int i = 0; i < IntAttrE.Len(); i++) {
775 fprintf(OutF,
" %*i", EdgePlaces, IntAttrE[i]());
779 fprintf(OutF,
" eas[%d]", StrAttrE.
Len());
780 for (
int i = 0; i < StrAttrE.
Len(); i++) {
781 fprintf(OutF,
" %*s", EdgePlaces, StrAttrE[i]());
785 fprintf(OutF,
" eaf[%d]", FltAttrE.
Len());
786 for (
int i = 0; i < FltAttrE.
Len(); i++) {
787 fprintf(OutF,
" %*f", EdgePlaces, FltAttrE[i]());
810 for (i = 0; i <
MxNId; i++) {
889 for (i = 0; i <
MxNId; i++) {
913 for (i = 0; i <
MxNId; i++) {
936 for (i = 0; i <
MxEId; i++) {
959 for (i = 0; i <
MxEId; i++) {
997 for (i = 0; i <
MxEId; i++) {
1021 for (i = 0; i <
MxEId; i++) {
1114 }
else if (vecType ==
StrType) {
1116 }
else if (vecType ==
FltType) {
1131 }
else if (vecType ==
StrType) {
1133 }
else if (vecType ==
FltType) {
1150 for (i = 0; i <
MxNId; i++) {
1151 NewVec.
Ins(i, defaultValue);
1179 for (i = 0; i <
MxNId; i++) {
1180 NewVec.
Ins(i, defaultValue);
1199 for (i = 0; i <
MxNId; i++) {
1200 NewVec.
Ins(i, defaultValue);
1219 for (i = 0; i <
MxEId; i++) {
1220 NewVec.
Ins(i, defaultValue);
1238 for (i = 0; i <
MxEId; i++) {
1252 for (i = 0; i <
MxEId; i++) {
1253 NewVec.
Ins(i, defaultValue);
1271 for (i = 0; i <
MxEId; i++) {
1272 NewVec.
Ins(i, defaultValue);
1290 }
else if (vecType ==
StrType) {
1295 }
else if (vecType ==
FltType) {
1316 }
else if (vecType ==
StrType) {
1321 }
else if (vecType ==
FltType) {
1336 for (
int i = 0; i < 5; i++) { Net->AddNode(i); }
1337 Net->AddEdge(0,1); Net->AddEdge(0,2);
1338 Net->AddEdge(0,3); Net->AddEdge(0,4);
1339 Net->AddEdge(1,2); Net->AddEdge(1,2);
1345 if (it.GetDat().GetVal1() ==
IntType) {
1346 IntAttrNames.
Add(it.GetKey());
1348 if (it.GetDat().GetVal1() ==
FltType) {
1349 FltAttrNames.
Add(it.GetKey());
1351 if (it.GetDat().GetVal1() ==
StrType) {
1352 StrAttrNames.
Add(it.GetKey());
1359 if (it.GetDat().GetVal1() ==
IntType) {
1360 IntAttrNames.
Add(it.GetKey());
1362 if (it.GetDat().GetVal1() ==
FltType) {
1363 FltAttrNames.
Add(it.GetKey());
1365 if (it.GetDat().GetVal1() ==
StrType) {
1366 StrAttrNames.
Add(it.GetKey());
1376 for (
int i = 0; i < len; i++) {
1384 int EId = it.GetId();
1385 int SrcId = it.GetSrcNId();
1687 Node.
NIdV = NbrNIdV;
1690 for (
int i = 0; i < NbrNIdV.
Len(); i++) {
1691 GetNode(NbrNIdV[i]).NIdV.AddSorted(NewNId);
1721 for (
int e = 0; e < Node.
GetDeg(); e++) {
1723 if (nbr == NId) {
continue; }
1727 if (n!= -1) { N.
NIdV.
Del(n); }
1744 if (
IsEdge(SrcNId, DstNId)) {
return -2; }
1745 GetNode(SrcNId).NIdV.AddSorted(DstNId);
1746 if (SrcNId!=DstNId) {
1747 GetNode(DstNId).NIdV.AddSorted(SrcNId); }
1757 TIntPr Id(SrcNId, DstNId);
1759 if (n!= -1) { N.
NIdV.
Del(n); NEdges--; } }
1760 if (SrcNId != DstNId) {
1763 if (n!= -1) { N.
NIdV.
Del(n); }
1769 if (!
IsNode(SrcNId) || !
IsNode(DstNId))
return false;
1770 return GetNode(SrcNId).IsNbrNId(DstNId);
1775 const int MnNId =
TMath::Mn(SrcNId, DstNId);
1778 const int NodeN = SrcNI.
NodeHI.GetDat().NIdV.SearchBin(MxNId);
1812 for (
int e = 0; e < Node.
GetDeg(); e++) {
1814 const TStr Msg =
TStr::Fmt(
"Edge %d --> %d: node %d does not exist.",
1819 if (e > 0 && prevNId == Node.
GetNbrNId(e)) {
1820 const TStr Msg =
TStr::Fmt(
"Node %d has duplicate edge %d --> %d.",
1831 const TStr Msg =
TStr::Fmt(
"Number of edges counter is corrupted: GetEdges():%d, EdgeCount:%d.",
GetEdges(), EdgeCnt);
1840 const int NodePlaces = (int) ceil(log10((
double)
GetNodes()));
1841 fprintf(OutF,
"-------------------------------------------------\nUndirected Node Graph: nodes: %d, edges: %d\n",
GetNodes(),
GetEdges());
1844 fprintf(OutF,
" %*d [%d] ", NodePlaces, Node.
GetId(), Node.
GetDeg());
1847 fprintf(OutF,
"\n");
1849 fprintf(OutF,
"\n");
1855 for (
int i = 0; i < 5; i++) { Graph->AddNode(i); }
1856 Graph->AddEdge(0,1); Graph->AddEdge(0,2);
1857 Graph->AddEdge(0,3); Graph->AddEdge(0,4);
1858 Graph->AddEdge(1,2);
1989 if (SrcNId < DstNId) {
1990 return TIntPr(SrcNId, DstNId);
1992 return TIntPr(DstNId, SrcNId);
1996 if (!
IsEdge(SrcNId, DstNId)) {
1999 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2004 if (!
IsEdge(SrcNId, DstNId)) {
2007 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2012 if (!
IsEdge(SrcNId, DstNId)) {
2015 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2020 if (!
IsEdge(SrcNId, DstNId)) {
2023 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2028 if (!
IsEdge(SrcNId, DstNId)) {
2031 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2036 if (!
IsEdge(SrcNId, DstNId)) {
2039 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2044 if (!
IsEdge(SrcNId, DstNId)) {
2047 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2052 if (!
IsEdge(SrcNId, DstNId)) {
2055 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2060 if (!
IsEdge(SrcNId, DstNId)) {
2063 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2068 if (!
IsEdge(SrcNId, DstNId)) {
2071 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2076 if (!
IsEdge(SrcNId, DstNId)) {
2079 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2084 if (!
IsEdge(SrcNId, DstNId)) {
2087 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2092 if (!
IsEdge(SrcNId, DstNId)) {
2095 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2100 if (!
IsEdge(SrcNId, DstNId)) {
2103 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2108 if (!
IsEdge(SrcNId, DstNId)) {
2111 TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2197 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
2199 if (nbr == NId) {
continue; }
2204 for (
int e = 0; e < Node.
GetInDeg(); e++) {
2206 if (nbr == NId) {
continue; }
2217 edges+=
NodeH[N].GetOutDeg();
2225 if (
IsEdge(SrcNId, DstNId)) {
return -2; }
2226 GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
2227 GetNode(DstNId).InNIdV.AddSorted(SrcNId);
2234 TIntPr Id(SrcNId, DstNId);
2252 if (!
IsNode(SrcNId) || !
IsNode(DstNId)) {
return false; }
2253 if (IsDir) {
return GetNode(SrcNId).IsOutNId(DstNId); }
2254 else {
return GetNode(SrcNId).IsOutNId(DstNId) ||
GetNode(DstNId).IsOutNId(SrcNId); }
2259 const int NodeN = SrcNI.
NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
2284 const TStr Msg =
TStr::Fmt(
"Out-neighbor list of node %d is not sorted.", Node.
GetId());
2288 const TStr Msg =
TStr::Fmt(
"In-neighbor list of node %d is not sorted.", Node.
GetId());
2293 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
2295 const TStr Msg =
TStr::Fmt(
"Out-edge %d --> %d: node %d does not exist.",
2299 if (e > 0 && prevNId == Node.
GetOutNId(e)) {
2300 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate out-edge %d --> %d.",
2308 for (
int e = 0; e < Node.
GetInDeg(); e++) {
2310 const TStr Msg =
TStr::Fmt(
"In-edge %d <-- %d: node %d does not exist.",
2314 if (e > 0 && prevNId == Node.
GetInNId(e)) {
2315 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate in-edge %d <-- %d.",
2326 const int NodePlaces = (int) ceil(log10((
double)
GetNodes()));
2327 fprintf(OutF,
"-------------------------------------------------\nDirected Node Graph: nodes: %d, edges: %d\n",
GetNodes(),
GetEdges());
2330 fprintf(OutF,
" %*d]\n", NodePlaces, Node.
GetId());
2331 fprintf(OutF,
" in [%d]", Node.
GetInDeg());
2333 fprintf(OutF,
" %*d", NodePlaces, Node.
GetInNId(
edge)); }
2334 fprintf(OutF,
"\n out[%d]", Node.
GetOutDeg());
2337 fprintf(OutF,
"\n");
2339 fprintf(OutF,
"\n");
2344 for (
int i = 0; i < 5; i++) { G->AddNode(i); }
2345 G->AddEdge(0,1); G->AddEdge(1,2); G->AddEdge(0,2);
2346 G->AddEdge(1,3); G->AddEdge(3,4); G->AddEdge(2,3);
2477 if (!
IsEdge(SrcNId, DstNId)) {
2480 TIntPr EId(SrcNId, DstNId);
2485 if (!
IsEdge(SrcNId, DstNId)) {
2488 TIntPr EId(SrcNId, DstNId);
2493 if (!
IsEdge(SrcNId, DstNId)) {
2496 TIntPr EId(SrcNId, DstNId);
2501 if (!
IsEdge(SrcNId, DstNId)) {
2504 TIntPr EId(SrcNId, DstNId);
2509 if (!
IsEdge(SrcNId, DstNId)) {
2512 TIntPr EId(SrcNId, DstNId);
2517 if (!
IsEdge(SrcNId, DstNId)) {
2520 TIntPr EId(SrcNId, DstNId);
2525 if (!
IsEdge(SrcNId, DstNId)) {
2528 TIntPr EId(SrcNId, DstNId);
2533 if (!
IsEdge(SrcNId, DstNId)) {
2536 TIntPr EId(SrcNId, DstNId);
2541 if (!
IsEdge(SrcNId, DstNId)) {
2544 TIntPr EId(SrcNId, DstNId);
2549 if (!
IsEdge(SrcNId, DstNId)) {
2552 TIntPr EId(SrcNId, DstNId);
2557 if (!
IsEdge(SrcNId, DstNId)) {
2560 TIntPr EId(SrcNId, DstNId);
2565 if (!
IsEdge(SrcNId, DstNId)) {
2568 TIntPr EId(SrcNId, DstNId);
2573 if (!
IsEdge(SrcNId, DstNId)) {
2576 TIntPr EId(SrcNId, DstNId);
2581 if (!
IsEdge(SrcNId, DstNId)) {
2584 TIntPr EId(SrcNId, DstNId);
2589 if (!
IsEdge(SrcNId, DstNId)) {
2592 TIntPr EId(SrcNId, DstNId);
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
TVec< TIntV > VecOfIntVecsN
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
static const T & Mn(const T &LVal, const T &RVal)
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
TPair< TInt, TInt > TIntPr
void IntVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
int GetAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr.
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
int GetEdges() const
Returns the number of edges in the network.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
int DelSAttrDat(const TInt &Id, const TStr &AttrName)
Delete attribute with name AttrName for the given id Id.
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
void GetAttrENames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of edge attributes of the given type.
int GetNodes() const
Returns the number of nodes in the graph.
bool IsKeyIdEqKeyN() const
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
#define IAssertR(Cond, Reason)
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
THash< TStr, TFlt > FltDefaultsE
int AppendIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
int AddFltAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns edge attribute value, converted to Str type.
enum TAttrType_ TAttrType
Types for tables, sparse and dense attributes.
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
TVec< TStrV > VecOfStrVecsE
THash< TStr, TInt > IntDefaultsE
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr (same as GetAttrIndN for compatibility...
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node str attr iterator.
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
Gets the sum of the weights of all the outgoing edges of the node.
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted for current node attr iterator.
bool IsStrAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Str attr exists for node NId and has default value.
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Edge iterator. Only forward iteration (operator++) is supported.
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
static const T & Mx(const T &LVal, const T &RVal)
int GetOutNId(const int &NodeN) const
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
int GetSAttrVE(const TInt &EId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with id EId.
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
TNode & GetNode(const int &NId)
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
int AddSAttrDatE(const TInt &EId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with id EId.
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
void DelNode(const int &NId)
Deletes node of ID NId from the network.
void IntVAttrValueEI(const TInt &EId, TVec< TIntV > &Values) const
Returns a vector of attr values for edge EId.
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge flt attr iterator.
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
int AddIntVAttrN(const TStr &attr)
Adds a new IntV node attribute to the hashmap.
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge attr iterator.
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
int AddIntVAttrDatE(const TEdgeI &EdgeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if attr exists for edge EId and has default value.
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Flt attr exists for edge NId and has default value.
TSizeTy Len() const
Returns the number of elements in the vector.
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int attr iterator.
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
int GetSAttrName(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Given the attribute id AttrId, get the attribute name.
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
TIntV GetIntVAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of the intv attr from the edge attr value vector.
void GenExt(TVal *_ValT, const TSizeTy &_Vals)
Constructs a vector of _Vals elements of memory array _ValT.
TStrIntPrH KeyToIndexTypeE
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
int GetNbrNId(const int &NodeN) const
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Node iterator. Only forward iteration (operator++) is supported.
void DelEdge(const int &EId)
Deletes an edge with edge ID EId from the graph.
THash< TStr, TFlt > FltDefaultsN
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
static PUndirNet GetSmallGraph()
Returns a small network on 5 nodes and 5 edges.
int AddIntAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
const TDat & GetDat(const TKey &Key) const
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
Node iterator. Only forward iteration (operator++) is supported.
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
TVec< TIntV > VecOfIntVecsE
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
bool NodeAttrIsIntVDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int vector attr iterator. ...
virtual void DelNode(const int &NId)
Deletes node of ID NId from the graph.
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
void DelSAttrId(const TInt &Id)
Delete all attributes for the given id Id.
const TKey & GetKey() const
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
void ErrNotify(const char *NotifyCStr)
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
TVec< TStrV > VecOfStrVecsN
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Int attr exists for edge EId and has default value.
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
bool IsFltAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Flt attr exists for node NId and has default value.
int AddFltAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node flt attr iterator.
void IntVAttrValueNI(const TInt &NId, TVec< TIntV > &Values) const
Returns a vector of attr values for node NId.
THash< TInt, TEdge > EdgeH
void GetAttrNNames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of node attributes of the given type.
int DelFromIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Deletes value from the TIntV attribute for the given node.
int AddIntVAttrDatN(const TNodeI &NodeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
int GetAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr.
TStr GetStrAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a string edge attr specified by edge iterator EdgeI and the attr index...
void DelEdge(const int &SrcNId, const int &DstNId)
Deletes an edge between node IDs SrcNId and DstNId from the network.
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Str attr exists for edge NId and has default value.
void DelKey(const TKey &Key)
int GetId() const
Returns ID of the current node.
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
TVec< TFltV > VecOfFltVecsE
int GetFltKeyIdE(const int &EId)
Gets keyid for edge with id EId.
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
const TDat & GetDat() const
TInt GetIntAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
int AddStrAttrDatN(const TNodeI &NodeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
int GetSAttrDatE(const TInt &EId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with id EId.
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge with ID EId between node IDs SrcNId and DstNId to the graph.
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
bool FNextKeyId(int &KeyId) const
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
THash< TStr, TStr > StrDefaultsN
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
TInt GetIntAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of an int node attr specified by node iterator NodeI and the attr index.
void IntVAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntV &IdV) const
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the network.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
void DelNode(const int &NId)
Deletes node of ID NId from the network.
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns node attribute value, converted to Str type.
TVec< TVec< TIntV > > VecOfIntVecVecsE
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Directed multigraph with node edge attributes.
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the network.
void GetSAttrV(const TInt &Id, const TAttrType AttrType, TAttrPrV &AttrV) const
Get a list of all attributes of type AttrType for the given id Id.
bool IsIntAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
bool IsIntVAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if IntV attr exists for edge EId and is an empty vector.
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
TEdge & GetEdge(const int &EId)
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
bool IsFltAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
int GetKeyId(const TKey &Key) const
Edge iterator. Only forward iteration (operator++) is supported.
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
bool EdgeAttrIsIntVDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int vector attr iterator.
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
bool IsIntAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Int attr exists for node NId and has default value.
Edge iterator. Only forward iteration (operator++) is supported.
int DelAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the network.
THash< TStr, TStr > StrDefaultsE
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
int GetEdges() const
Returns the number of edges in the graph.
void GetKeyV(TVec< TKey > &KeyV) const
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
int GetOutEId(const int &EdgeN) const
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge str attr iterator.
int GetEdges() const
Returns the number of edges in the network.
int AddStrAttrDatE(const TEdgeI &EdgeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
static TStr Fmt(const char *FmtStr,...)
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
void Pack()
Reduces vector capacity (frees memory) to match its size.
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
Fills OutWeights with the outgoing weight from each node.
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
bool IsAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if attr exists for node NId and has default value.
TVec< TFltV > VecOfFltVecsN
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
#define EAssertR(Cond, MsgStr)
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
Gets Vector for the Flt Attribute attr.
int GetSAttrId(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Given the attribute name Name, get the attribute id.
THash< TStr, TInt > IntDefaultsN
#define AssertR(Cond, Reason)
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int attr iterator.
bool IsIntVAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if IntV attr exists for node NId and is an empty vector.
THash< TInt, TNode > NodeH
int AppendIntVAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
static PDirNet New()
Static constructor that returns a pointer to the network. Call: PDirNet Graph = TDirNet::New().
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
TFlt GetFltAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a float node attr specified by node iterator NodeI and the attr index...
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
TVec< TVec< TIntV > > VecOfIntVecVecsN
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
int GetInEId(const int &EdgeN) const
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
int GetIdVSAttrE(const TStr &AttrName, TIntV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
int AddIntVAttrE(const TStr &attr)
Adds a new IntV edge attribute to the hashmap.
int GetInNId(const int &NodeN) const
bool IsKey(const TKey &Key) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
int DelSAttrDatE(const TInt &EId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with id EId.
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
bool IsStrAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
TDat & AddDat(const TKey &Key)
static PDirNet GetSmallGraph()
Returns a small network on 5 nodes and 6 edges.
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr (same as GetAttrIndE for compatibility...
TStr GetStrAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a string node attr specified by node iterator NodeI and the attr index...
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Node iterator. Only forward iteration (operator++) is supported.
const TKey & GetKey(const int &KeyId) const
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
int AddSAttr(const TStr &Name, const TAttrType &AttrType, TInt &AttrIdX)
Adds a mapping for an attribute with name Name and type AttrType.
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
TFlt GetFltAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a float edge attr specified by edge iterator EdgeI and the attr index...
TInt GetIntAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of an int edge attr specified by edge iterator EdgeI and the attr index.
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
TIter GetI(const TKey &Key) const
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.