19 const TNode& Node = NodeHI.GetDat();
29 while (!NodeHI.
IsEnd()) {
39 while (!NodeHI.
IsEnd()) {
49 while (!NodeHI.
IsEnd()) {
59 while (!NodeHI.
IsEnd()) {
70 while (!NodeHI.
IsEnd()) {
80 while (!NodeHI.
IsEnd()) {
91 while (!NodeHI.
IsEnd()) {
101 while (!NodeHI.
IsEnd()) {
114 return IntDel || StrDel || FltDel;
151 while (!EdgeHI.
IsEnd()) {
161 while (!EdgeHI.
IsEnd()) {
171 while (!EdgeHI.
IsEnd()) {
181 while (!EdgeHI.
IsEnd()) {
192 while (!EdgeHI.
IsEnd()) {
202 while (!EdgeHI.
IsEnd()) {
213 while (!EdgeHI.
IsEnd()) {
223 while (!EdgeHI.
IsEnd()) {
236 return IntDel || StrDel || FltDel;
287 for (i = 0; i < DefIntVec.
Len(); i++) {
288 TStr attr = DefIntVec[i];
298 for (i = 0; i < DefStrVec.
Len(); i++) {
299 TStr attr = DefStrVec[i];
309 for (i = 0; i < DefFltVec.
Len(); i++) {
310 TStr attr = DefFltVec[i];
324 NodeH[NodeKeyId].InEIdV.MoveFrom(InEIdV);
325 NodeH[NodeKeyId].OutEIdV.MoveFrom(OutEIdV);
406 for (i = 0; i < DefIntVec.
Len(); i++) {
407 TStr attr = DefIntVec[i];
418 for (i = 0; i < DefStrVec.
Len(); i++) {
419 TStr attr = DefStrVec[i];
430 for (i = 0; i < DefFltVec.
Len(); i++) {
431 TStr attr = DefFltVec[i];
480 bool TNEANetMP::IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir)
const {
521 if (! OnlyNodeLinks && !
NodeH.IsKeyIdEqKeyN()) {
NodeH.Defrag(); }
522 if (! OnlyNodeLinks && !
EdgeH.IsKeyIdEqKeyN()) {
EdgeH.Defrag(); }
540 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
545 if (e > 0 && prevEId == Node.
GetOutEId(e)) {
553 for (
int e = 0; e < Node.
GetInDeg(); e++) {
558 if (e > 0 && prevEId == Node.
GetInEId(e)) {
580 const int NodePlaces = (int) ceil(log10((
double)
GetNodes()));
581 const int EdgePlaces = (int) ceil(log10((
double)
GetEdges()));
582 fprintf(OutF,
"-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n",
GetNodes(),
GetEdges());
584 fprintf(OutF,
" %*d]\n", NodePlaces, NodeI.GetId());
588 fprintf(OutF,
" nai[%d]", IntAttrN.Len());
589 for (
int i = 0; i < IntAttrN.Len(); i++) {
590 fprintf(OutF,
" %*i", NodePlaces, IntAttrN[i]()); }
593 fprintf(OutF,
" nas[%d]", StrAttrN.
Len());
594 for (
int i = 0; i < StrAttrN.
Len(); i++) {
595 fprintf(OutF,
" %*s", NodePlaces, StrAttrN[i]()); }
598 fprintf(OutF,
" naf[%d]", FltAttrN.
Len());
599 for (
int i = 0; i < FltAttrN.
Len(); i++) {
600 fprintf(OutF,
" %*f", NodePlaces, FltAttrN[i]()); }
602 fprintf(OutF,
" in[%d]", NodeI.GetInDeg());
604 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetInEId(
edge)); }
606 fprintf(OutF,
" out[%d]", NodeI.GetOutDeg());
608 fprintf(OutF,
" %*d", EdgePlaces, NodeI.GetOutEId(
edge)); }
612 fprintf(OutF,
" %*d] %*d -> %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
617 fprintf(OutF,
" eai[%d]", IntAttrE.Len());
618 for (
int i = 0; i < IntAttrE.Len(); i++) {
619 fprintf(OutF,
" %*i", EdgePlaces, IntAttrE[i]());
623 fprintf(OutF,
" eas[%d]", StrAttrE.
Len());
624 for (
int i = 0; i < StrAttrE.
Len(); i++) {
625 fprintf(OutF,
" %*s", EdgePlaces, StrAttrE[i]());
629 fprintf(OutF,
" eaf[%d]", FltAttrE.
Len());
630 for (
int i = 0; i < FltAttrE.
Len(); i++) {
631 fprintf(OutF,
" %*f", EdgePlaces, FltAttrE[i]());
654 for (i = 0; i <
MxNId; i++) {
677 for (i = 0; i <
MxNId; i++) {
701 for (i = 0; i <
MxNId; i++) {
725 for (i = 0; i <
MxEId; i++) {
749 for (i = 0; i <
MxEId; i++) {
773 for (i = 0; i <
MxEId; i++) {
834 }
else if (vecType ==
StrType) {
836 }
else if (vecType ==
FltType) {
849 }
else if (vecType ==
StrType) {
851 }
else if (vecType ==
FltType) {
866 for (i = 0; i <
MxNId; i++) {
867 NewVec.
Ins(i, defaultValue);
885 for (i = 0; i <
MxNId; i++) {
886 NewVec.
Ins(i, defaultValue);
905 for (i = 0; i <
MxNId; i++) {
906 NewVec.
Ins(i, defaultValue);
925 for (i = 0; i <
MxEId; i++) {
926 NewVec.
Ins(i, defaultValue);
944 for (i = 0; i <
MxEId; i++) {
945 NewVec.
Ins(i, defaultValue);
963 for (i = 0; i <
MxEId; i++) {
964 NewVec.
Ins(i, defaultValue);
1028 for (
int i = 0; i < len; i++) {
1036 int EId = it.GetId();
1037 int SrcId = it.GetSrcNId();
1057 #endif // GCC_ATOMIC
int GetPrimHashCd() const
TPair< TInt, TInt > TIntPr
TFlt GetFltAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
#define IAssertR(Cond, Reason)
int GetId() const
Returns ID of the current node.
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int GetNodes() const
Returns the number of nodes in the graph.
Directed multigraph with node edge attributes.
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
TStrIntPrH KeyToIndexTypeE
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
static const T & Mx(const T &LVal, const T &RVal)
TInt GetIntAttrDefaultE(const TStr &attribute) const
Get Int edge attribute val. If not a proper attr, return default.
int GetEdges() const
Returns the number of edges in the graph.
TVec< TIntV > VecOfIntVecsN
TStr GetStrAttrDefaultN(const TStr &attribute) const
Get Str node attribute val. If not a proper attr, return default.
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
TSizeTy Len() const
Returns the number of elements in the vector.
int AddIntAttrDatE(const TEdgeI &EdgeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
TVec< TFltV > VecOfFltVecsN
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
THashMP< TStr, TStr > StrDefaultsN
int DelAttrDatN(const TNodeI &NodeId, const TStr &attr)
Deletes the node attribute for NodeId.
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
void GetKeyV(TVec< TKey > &KeyV) const
TStr GetStrAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
int AddFltAttrDatN(const TNodeI &NodeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
int Reserved() const
Returns the number of nodes reserved in the network.
const TDat & GetDat(const TKey &Key) const
TInt GetIntAttrIndDatN(const TNodeI &NodeId, const int &index)
Gets the value of node int attr specified by the attr index.
TEdge & GetEdge(const int &EId)
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
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)
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
bool IsIntAttrE(const TStr &attr)
THashMP< TStr, TInt > IntDefaultsN
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
THashMP< TInt, TEdge > EdgeH
TInt GetIntAttrDefaultN(const TStr &attribute) const
Get Int node attribute val. If not a proper attr, return default.
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
bool IsStrAttrE(const TStr &attr)
THashMP< TStr, TStr > StrDefaultsE
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
const TVal & GetVal(const TSizeTy &ValN) const
Returns a reference to the element at position ValN in the vector.
TVec< TStrV > VecOfStrVecsE
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by str attr.
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
const TDat & GetDat() const
#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 GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
TNode & GetNode(const int &NId)
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
bool IsFltAttrE(const TStr &attr)
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
TVec< TIntV > VecOfIntVecsE
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by str attr.
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Get Flt edge attribute val. If not a proper attr, return default.
bool IsNode(const int &NId) const
If the node of ID NId does not exist the function aborts.
TStr GetStrAttrDefaultE(const TStr &attribute) const
Get Str edge attribute val. If not a proper attr, return default.
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
int AddStrAttrDatE(const TEdgeI &EdgeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
bool IsKey(const TKey &Key) const
TInt GetIntAttrIndDatE(const TEdgeI &EdgeId, const int &index)
Gets the value of edge int attr specified by the attr index.
bool FNextKeyId(int &KeyId) const
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Get Flt node attribute val. If not a proper attr, return default.
THashMP< TStr, TInt > IntDefaultsE
Node iterator. Only forward iteration (operator++) is supported.
int GetInEId(const int &EdgeN) const
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 AddStrAttrDatN(const TNodeI &NodeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
void AddNodeWithEdges(const TInt &NId, TIntV &InEIdV, TIntV &OutEIdV)
Adds a node along with its neighbor edges.
Edge iterator. Only forward iteration (operator++) is supported.
TStr GetStrAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of str attr from the node attr value vector.
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
int DelAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Deletes the edge attribute for NodeId.
TInt GetIntAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of int attr from the node attr value vector.
THashMP< TInt, TNode > NodeH
TFlt GetFltAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
TVec< TFltV > VecOfFltVecsE
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
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.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
int ReservedE() const
Returns the number of edges reserved in the network.
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
#define EAssertR(Cond, MsgStr)
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
int AddIntAttrDatN(const TNodeI &NodeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
TInt GetIntAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
THashMP< TStr, TFlt > FltDefaultsE
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
int AddKey13(const int &Idx, const TKey &Key)
int GetOutEId(const int &EdgeN) const
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
bool IsKey(const TKey &Key) const
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TDat & AddDat(const TKey &Key)
THashMP< TStr, TFlt > FltDefaultsN
void Defrag(const bool &OnlyNodeLinks=false)
int GetKeyId(const TKey &Key) const
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
int AddFltAttrDatE(const TEdgeI &EdgeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
TDat & AddDat(const TKey &Key)
int GetFltKeyIdE(const int &EId)
TVec< TStrV > VecOfStrVecsN
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
Vector is a sequence TVal objects representing an array that can change in size.
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
const TKey & GetKey(const int &KeyId) const
void AddEdgeUnchecked(const TInt &EId, const int SrcNId, const int DstNId)
Adds an edge without checking its adjacent nodes' neighborhood.