9 for (
int edge = 0; edge < Node.
GetInDeg(); edge++) {
17 const TNode& Node = NodeHI.GetDat();
18 for (
int edge = 0; edge < Node.
GetOutDeg(); edge++) {
19 if (NId == Graph->GetEdge(Node.
GetOutEId(edge)).GetDstNId())
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()) {
112 return IntDel || StrDel || FltDel;
131 return IntDel || StrDel || FltDel;
174 while (!EdgeHI.
IsEnd()) {
184 while (!EdgeHI.
IsEnd()) {
194 while (!EdgeHI.
IsEnd()) {
204 while (!EdgeHI.
IsEnd()) {
215 while (!EdgeHI.
IsEnd()) {
225 while (!EdgeHI.
IsEnd()) {
236 while (!EdgeHI.
IsEnd()) {
246 while (!EdgeHI.
IsEnd()) {
259 return IntDel || StrDel || FltDel;
278 return IntDel || StrDel || FltDel;
329 for (i = 0; i < DefIntVec.
Len(); i++) {
330 TStr attr = DefIntVec[i];
340 for (i = 0; i < DefStrVec.
Len(); i++) {
341 TStr attr = DefStrVec[i];
351 for (i = 0; i < DefFltVec.
Len(); i++) {
352 TStr attr = DefFltVec[i];
363 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
383 for (
int in = 0; in < Node.
GetInDeg(); in++) {
437 for (i = 0; i < DefIntVec.
Len(); i++) {
438 TStr attr = DefIntVec[i];
449 for (i = 0; i < DefStrVec.
Len(); i++) {
450 TStr attr = DefStrVec[i];
461 for (i = 0; i < DefFltVec.
Len(); i++) {
462 TStr attr = DefFltVec[i];
496 bool Edge =
IsEdge(SrcNId, DstNId, EId, IsDir);
500 Edge =
IsEdge(SrcNId, DstNId, EId, IsDir);
504 bool TNEANet::IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir)
const {
506 for (
int edge = 0; edge < SrcNode.
GetOutDeg(); edge++) {
514 for (
int edge = 0; edge < SrcNode.
GetInDeg(); edge++) {
562 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
567 if (e > 0 && prevEId == Node.
GetOutEId(e)) {
575 for (
int e = 0; e < Node.
GetInDeg(); e++) {
580 if (e > 0 && prevEId == Node.
GetInEId(e)) {
602 const int NodePlaces = (int) ceil(log10((
double)
GetNodes()));
603 const int EdgePlaces = (int) ceil(log10((
double)
GetEdges()));
604 fprintf(OutF,
"-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n",
GetNodes(),
GetEdges());
606 fprintf(OutF,
" %*d]\n", NodePlaces, NodeI.GetId());
610 fprintf(OutF,
" nai[%d]", IntAttrN.Len());
611 for (
int i = 0; i < IntAttrN.Len(); i++) {
612 fprintf(OutF,
" %*i", NodePlaces, IntAttrN[i]()); }
615 fprintf(OutF,
" nas[%d]", StrAttrN.
Len());
616 for (
int i = 0; i < StrAttrN.
Len(); i++) {
617 fprintf(OutF,
" %*s", NodePlaces, StrAttrN[i]()); }
620 fprintf(OutF,
" naf[%d]", FltAttrN.
Len());
621 for (
int i = 0; i < FltAttrN.
Len(); i++) {
622 fprintf(OutF,
" %*f", NodePlaces, FltAttrN[i]()); }
624 fprintf(OutF,
" in[%d]", NodeI.GetInDeg());
625 for (
int edge = 0; edge < NodeI.GetInDeg(); edge++) {
626 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetInEId(edge)); }
628 fprintf(OutF,
" out[%d]", NodeI.GetOutDeg());
629 for (
int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
630 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
634 fprintf(OutF,
" %*d] %*d -> %*d\n", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
639 fprintf(OutF,
" eai[%d]", IntAttrE.Len());
640 for (
int i = 0; i < IntAttrE.Len(); i++) {
641 fprintf(OutF,
" %*i", EdgePlaces, IntAttrE[i]()); }
644 fprintf(OutF,
" eas[%d]", StrAttrE.
Len());
645 for (
int i = 0; i < StrAttrE.
Len(); i++) {
646 fprintf(OutF,
" %*s", EdgePlaces, StrAttrE[i]()); }
649 fprintf(OutF,
" eaf[%d]", FltAttrE.
Len());
650 for (
int i = 0; i < FltAttrE.
Len(); i++) {
651 fprintf(OutF,
" %*f", EdgePlaces, FltAttrE[i]()); }
672 for (i = 0; i <
MxNId; i++) {
695 for (i = 0; i <
MxNId; i++) {
719 for (i = 0; i <
MxNId; i++) {
742 for (i = 0; i <
MxEId; i++) {
765 for (i = 0; i <
MxEId; i++) {
789 for (i = 0; i <
MxEId; i++) {
866 }
else if (vecType ==
StrType) {
868 }
else if (vecType ==
FltType) {
881 }
else if (vecType ==
StrType) {
883 }
else if (vecType ==
FltType) {
898 for (i = 0; i <
MxNId; i++) {
899 NewVec.
Ins(i, defaultValue);
917 for (i = 0; i <
MxNId; i++) {
918 NewVec.
Ins(i, defaultValue);
937 for (i = 0; i <
MxNId; i++) {
938 NewVec.
Ins(i, defaultValue);
957 for (i = 0; i <
MxEId; i++) {
958 NewVec.
Ins(i, defaultValue);
976 for (i = 0; i <
MxEId; i++) {
977 NewVec.
Ins(i, defaultValue);
995 for (i = 0; i <
MxEId; i++) {
996 NewVec.
Ins(i, defaultValue);
1014 }
else if (vecType ==
StrType) {
1019 }
else if (vecType ==
FltType) {
1038 }
else if (vecType ==
StrType) {
1043 }
else if (vecType ==
FltType) {
1058 for (
int i = 0; i < 5; i++) { Net->AddNode(i); }
1059 Net->AddEdge(0,1); Net->AddEdge(0,2);
1060 Net->AddEdge(0,3); Net->AddEdge(0,4);
1061 Net->AddEdge(1,2); Net->AddEdge(1,2);
1067 if (it.GetDat().GetVal1() ==
IntType) {
1068 IntAttrNames.
Add(it.GetKey());
1070 if (it.GetDat().GetVal1() ==
FltType) {
1071 FltAttrNames.
Add(it.GetKey());
1073 if (it.GetDat().GetVal1() ==
StrType) {
1074 StrAttrNames.
Add(it.GetKey());
1081 if (it.GetDat().GetVal1() ==
IntType) {
1082 IntAttrNames.
Add(it.GetKey());
1084 if (it.GetDat().GetVal1() ==
FltType) {
1085 FltAttrNames.
Add(it.GetKey());
1087 if (it.GetDat().GetVal1() ==
StrType) {
1088 StrAttrNames.
Add(it.GetKey());
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
TVec< TIntV > VecOfIntVecsN
TPair< TInt, TInt > TIntPr
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.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
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
#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 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
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
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
bool IsStrAttrDeletedN(const int &NId, const TStr &attr) const
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)
TNode & GetNode(const int &NId)
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
TInt GetIntAttrDefaultE(const TStr &attribute) const
Get Int edge attribute val. If not a proper attr, return default.
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
TSizeTy Len() const
Returns the number of elements in the vector.
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
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.
TStrIntPrH KeyToIndexTypeE
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
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.
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
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.
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
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)
TVec< TStrV > VecOfStrVecsN
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
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
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
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.
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...
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
void DelKey(const TKey &Key)
TVec< TFltV > VecOfFltVecsE
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.
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.
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
Get 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.
bool FNextKeyId(int &KeyId) const
THash< TStr, TStr > StrDefaultsN
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
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.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
TStr GetStrAttrDefaultN(const TStr &attribute) const
Get Str node attribute val. If not a proper attr, return default.
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
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.
Directed multigraph with node edge attributes.
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
TEdge & GetEdge(const int &EId)
int GetKeyId(const TKey &Key) const
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.
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
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
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.
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
Get 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 GetOutEId(const int &EdgeN) const
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
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()
The vector reduces its capacity (frees memory) to match its size.
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
bool IsAttrDeletedN(const int &NId, const TStr &attr) const
TVec< TFltV > VecOfFltVecsN
#define EAssertR(Cond, MsgStr)
THash< TStr, TInt > IntDefaultsN
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
THash< TInt, TNode > NodeH
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
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.
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Get Flt node attribute val. If not a proper attr, return default.
int GetInEId(const int &EdgeN) const
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
TInt GetIntAttrDefaultN(const TStr &attribute) const
Get Int node attribute val. If not a proper attr, return default.
bool IsKey(const TKey &Key) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
TDat & AddDat(const TKey &Key)
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
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...
const TKey & GetKey(const int &KeyId) const
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Vector is a sequence TVal objects representing an array that can change in size.
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.
TIter GetI(const TKey &Key) const
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.