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;
149 while (!EdgeHI.
IsEnd()) {
159 while (!EdgeHI.
IsEnd()) {
169 while (!EdgeHI.
IsEnd()) {
179 while (!EdgeHI.
IsEnd()) {
190 while (!EdgeHI.
IsEnd()) {
200 while (!EdgeHI.
IsEnd()) {
211 while (!EdgeHI.
IsEnd()) {
221 while (!EdgeHI.
IsEnd()) {
234 return IntDel || StrDel || FltDel;
285 for (i = 0; i < DefIntVec.
Len(); i++) {
286 TStr attr = DefIntVec[i];
296 for (i = 0; i < DefStrVec.
Len(); i++) {
297 TStr attr = DefStrVec[i];
307 for (i = 0; i < DefFltVec.
Len(); i++) {
308 TStr attr = DefFltVec[i];
319 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
339 for (
int in = 0; in < Node.
GetInDeg(); in++) {
393 for (i = 0; i < DefIntVec.
Len(); i++) {
394 TStr attr = DefIntVec[i];
405 for (i = 0; i < DefStrVec.
Len(); i++) {
406 TStr attr = DefStrVec[i];
417 for (i = 0; i < DefFltVec.
Len(); i++) {
418 TStr attr = DefFltVec[i];
452 bool Edge =
IsEdge(SrcNId, DstNId, EId, IsDir);
456 Edge =
IsEdge(SrcNId, DstNId, EId, IsDir);
460 bool TNEANet::IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir)
const {
462 for (
int edge = 0; edge < SrcNode.
GetOutDeg(); edge++) {
470 for (
int edge = 0; edge < SrcNode.
GetInDeg(); edge++) {
518 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
523 if (e > 0 && prevEId == Node.
GetOutEId(e)) {
531 for (
int e = 0; e < Node.
GetInDeg(); e++) {
536 if (e > 0 && prevEId == Node.
GetInEId(e)) {
558 const int NodePlaces = (int) ceil(log10((
double)
GetNodes()));
559 const int EdgePlaces = (int) ceil(log10((
double)
GetEdges()));
560 fprintf(OutF,
"-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n",
GetNodes(),
GetEdges());
562 fprintf(OutF,
" %*d]\n", NodePlaces, NodeI.GetId());
566 fprintf(OutF,
" nai[%d]", IntAttrN.Len());
567 for (
int i = 0; i < IntAttrN.Len(); i++) {
568 fprintf(OutF,
" %*i", NodePlaces, IntAttrN[i]()); }
571 fprintf(OutF,
" nas[%d]", StrAttrN.
Len());
572 for (
int i = 0; i < StrAttrN.
Len(); i++) {
573 fprintf(OutF,
" %*s", NodePlaces, StrAttrN[i]()); }
576 fprintf(OutF,
" naf[%d]", FltAttrN.
Len());
577 for (
int i = 0; i < FltAttrN.
Len(); i++) {
578 fprintf(OutF,
" %*f", NodePlaces, FltAttrN[i]()); }
580 fprintf(OutF,
" in[%d]", NodeI.GetInDeg());
581 for (
int edge = 0; edge < NodeI.GetInDeg(); edge++) {
582 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetInEId(edge)); }
584 fprintf(OutF,
" out[%d]", NodeI.GetOutDeg());
585 for (
int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
586 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
590 fprintf(OutF,
" %*d] %*d -> %*d\n", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
595 fprintf(OutF,
" eai[%d]", IntAttrE.Len());
596 for (
int i = 0; i < IntAttrE.Len(); i++) {
597 fprintf(OutF,
" %*i", EdgePlaces, IntAttrE[i]()); }
600 fprintf(OutF,
" eas[%d]", StrAttrE.
Len());
601 for (
int i = 0; i < StrAttrE.
Len(); i++) {
602 fprintf(OutF,
" %*s", EdgePlaces, StrAttrE[i]()); }
605 fprintf(OutF,
" eaf[%d]", FltAttrE.
Len());
606 for (
int i = 0; i < FltAttrE.
Len(); i++) {
607 fprintf(OutF,
" %*f", EdgePlaces, FltAttrE[i]()); }
628 for (i = 0; i <
MxNId; i++) {
651 for (i = 0; i <
MxNId; i++) {
675 for (i = 0; i <
MxNId; i++) {
698 for (i = 0; i <
MxEId; i++) {
721 for (i = 0; i <
MxEId; i++) {
745 for (i = 0; i <
MxEId; i++) {
798 }
else if (vecType ==
StrType) {
800 }
else if (vecType ==
FltType) {
813 }
else if (vecType ==
StrType) {
815 }
else if (vecType ==
FltType) {
830 for (i = 0; i <
MxNId; i++) {
831 NewVec.
Ins(i, defaultValue);
849 for (i = 0; i <
MxNId; i++) {
850 NewVec.
Ins(i, defaultValue);
869 for (i = 0; i <
MxNId; i++) {
870 NewVec.
Ins(i, defaultValue);
889 for (i = 0; i <
MxEId; i++) {
890 NewVec.
Ins(i, defaultValue);
908 for (i = 0; i <
MxEId; i++) {
909 NewVec.
Ins(i, defaultValue);
927 for (i = 0; i <
MxEId; i++) {
928 NewVec.
Ins(i, defaultValue);
946 }
else if (vecType ==
StrType) {
951 }
else if (vecType ==
FltType) {
970 }
else if (vecType ==
StrType) {
975 }
else if (vecType ==
FltType) {
990 for (
int i = 0; i < 5; i++) { Net->AddNode(i); }
991 Net->AddEdge(0,1); Net->AddEdge(0,2);
992 Net->AddEdge(0,3); Net->AddEdge(0,4);
993 Net->AddEdge(1,2); Net->AddEdge(1,2);
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
TVec< TIntV > VecOfIntVecsN
TPair< TInt, TInt > TIntPr
int AddIntAttrDatE(const TEdgeI &EdgeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
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.
int GetNodes() const
Returns the number of nodes in the graph.
bool IsKeyIdEqKeyN() const
#define IAssertR(Cond, Reason)
int AddStrAttrDatN(const TNodeI &NodeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
THash< TStr, TFlt > FltDefaultsE
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
int DelAttrDatN(const TNodeI &NodeId, const TStr &attr)
Deletes the node attribute for NodeId.
TVec< TStrV > VecOfStrVecsE
TStr GetStrAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
THash< TStr, TInt > IntDefaultsE
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by str attr.
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
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)
TInt GetIntAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of int attr from the node attr value vector.
int AddFltAttrDatN(const TNodeI &NodeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
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
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
TInt GetIntAttrIndDatN(const TNodeI &NodeId, const int &index)
Gets the value of node int attr specified by the attr index.
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.
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.
TInt GetIntAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
int AddStrAttrDatE(const TEdgeI &EdgeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
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
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 NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
THash< TInt, TEdge > EdgeH
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
void DelKey(const TKey &Key)
int AddIntAttrDatN(const TNodeI &NodeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
TVec< TFltV > VecOfFltVecsE
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
const TDat & GetDat() const
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.
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.
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.
int AddFltAttrDatE(const TEdgeI &EdgeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
TInt GetIntAttrIndDatE(const TEdgeI &EdgeId, const int &index)
Gets the value of edge int attr specified by the attr index.
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.
Edge iterator. Only forward iteration (operator++) is supported.
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
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.
int DelAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Deletes the edge attribute for NodeId.
TVec< TFltV > VecOfFltVecsN
#define EAssertR(Cond, MsgStr)
THash< TStr, TInt > IntDefaultsN
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TFlt GetFltAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
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.
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 GetFltAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
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().
TDat & AddDat(const TKey &Key)
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by str attr.
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.
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
TStr GetStrAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of str attr from the node attr value vector.