SNAP Library, Developer Reference
2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
|
#include <network.h>
Classes | |
class | TEdgeI |
Edge iterator. Only forward iteration (operator++) is supported. More... | |
class | TNode |
class | TNodeI |
Node iterator. Only forward iteration (operator++) is supported. More... | |
Public Types | |
typedef TNodeData | TNodeDat |
typedef TEdgeData | TEdgeDat |
typedef TNodeEDatNet < TNodeData, TEdgeData > | TNet |
typedef TPt< TNet > | PNet |
typedef TVec< TPair< TInt, TEdgeData > > | TNIdDatPrV |
Public Member Functions | |
TNodeEDatNet () | |
TNodeEDatNet (const int &Nodes, const int &Edges) | |
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges. | |
TNodeEDatNet (const TNodeEDatNet &NodeNet) | |
TNodeEDatNet (TSIn &SIn) | |
Constructor that loads the network from a (binary) stream SIn. | |
virtual | ~TNodeEDatNet () |
virtual void | Save (TSOut &SOut) const |
Saves the network to a (binary) stream SOut. | |
bool | HasFlag (const TGraphFlag &Flag) const |
Allows for run-time checking the type of the network (see the TGraphFlag for flags). | |
TNodeEDatNet & | operator= (const TNodeEDatNet &NodeNet) |
int | GetNodes () const |
Returns the number of nodes in the network. | |
int | AddNode (int NId=-1) |
Adds a node of ID NId to the network. | |
int | AddNode (int NId, const TNodeData &NodeDat) |
Adds a node of ID NId and node data NodeDat to the network. | |
int | AddNode (const TNodeI &NodeId) |
Adds a node NodeId and its node data to the network. | |
void | DelNode (const int &NId) |
Deletes node of ID NId from the network. | |
void | DelNode (const TNode &NodeI) |
Deletes node of ID NodeI.GetId() from the network. | |
bool | IsNode (const int &NId) const |
Tests whether ID NId is a node. | |
TNodeI | BegNI () const |
Returns an iterator referring to the first node in the network. | |
TNodeI | EndNI () const |
Returns an iterator referring to the past-the-end node in the network. | |
TNodeI | GetNI (const int &NId) const |
Returns an iterator referring to the node of ID NId in the network. | |
const TNode & | GetNode (const int &NId) const |
Returns node element for the node of ID NId in the network. | |
void | SetNDat (const int &NId, const TNodeData &NodeDat) |
Sets node data for the node of ID NId in the network. | |
TNodeData & | GetNDat (const int &NId) |
Returns node data for the node of ID NId in the network. | |
const TNodeData & | GetNDat (const int &NId) const |
Returns node data for the node of ID NId in the network. | |
int | GetMxNId () const |
Returns the maximum id of a any node in the network. | |
int | GetEdges () const |
Returns the number of edges in the network. | |
int | AddEdge (const int &SrcNId, const int &DstNId) |
Adds an edge from node IDs SrcNId to node DstNId to the network. | |
int | AddEdge (const int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat) |
Adds an edge and edge data from node IDs SrcNId to node DstNId. | |
int | AddEdge (const TEdgeI &EdgeI) |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network. | |
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 | 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. | |
TEdgeI | BegEI () const |
Returns an iterator referring to the first edge in the network. | |
TEdgeI | EndEI () const |
Returns an iterator referring to the past-the-end edge in the network. | |
TEdgeI | GetEI (const int &EId) const |
Not supported/implemented! | |
TEdgeI | GetEI (const int &SrcNId, const int &DstNId) const |
Returns an iterator referring to edge (SrcNId, DstNId) in the network. | |
void | SetEDat (const int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat) |
Sets edge data for the edge between nodes SrcNId and DstNId in the network. | |
bool | GetEDat (const int &SrcNId, const int &DstNId, TEdgeData &EdgeDat) const |
Returns edge data in Data for the edge from node IDs SrcNId to DstNId. | |
TEdgeData & | GetEDat (const int &SrcNId, const int &DstNId) |
Returns edge data for the edge from node IDs SrcNId to DstNId. | |
const TEdgeData & | GetEDat (const int &SrcNId, const int &DstNId) const |
Returns edge data for the edge from node IDs SrcNId to DstNId. | |
void | SetAllEDat (const TEdgeData &EdgeDat) |
Sets edge data for all the edges in the network to EDat. | |
int | GetRndNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random node in the network. | |
TNodeI | GetRndNI (TRnd &Rnd=TInt::Rnd) |
Returns an interator referring to a random node in the network. | |
void | GetNIdV (TIntV &NIdV) const |
Gets a vector IDs of all nodes in the network. | |
bool | Empty () const |
Tests whether the network is empty (has zero nodes). | |
void | Clr (const bool &DoDel=true, const bool &ResetDat=true) |
Deletes all nodes and edges from the network. | |
void | Reserve (const int &Nodes, const int &Edges) |
Reserves memory for a network of Nodes nodes and Edges edges. | |
void | SortNIdById (const bool &Asc=true) |
Sorts nodes by node IDs. | |
void | SortNIdByDat (const bool &Asc=true) |
Sorts nodes by node data. | |
void | Defrag (const bool &OnlyNodeLinks=false) |
Defragments the network. | |
bool | IsOk (const bool &ThrowExcept=true) const |
Checks the network data structure for internal consistency. | |
Static Public Member Functions | |
static PNet | New () |
Static constructor that returns a pointer to the network. Call: TPt <TNodeEDatNet<TNodeData, TEdgeData> > Net = TNodeEDatNet<TNodeData, TEdgeData>::New(). | |
static PNet | Load (TSIn &SIn) |
Static constructor that loads the network from a stream SIn and returns a pointer to it. | |
Protected Member Functions | |
TNode & | GetNode (const int &NId) |
Static Protected Member Functions | |
static int | GetNIdPos (const TVec< TPair< TInt, TEdgeData > > &NIdV, const int &NId) |
Protected Attributes | |
TCRef | CRef |
TInt | MxNId |
THash< TInt, TNode > | NodeH |
Friends | |
class | TPt< TNodeEDatNet< TNodeData, TEdgeData > > |
Node Edge Network (directed graph, TNGraph with data on nodes and edges).
typedef TPt<TNet> TNodeEDatNet< TNodeData, TEdgeData >::PNet |
typedef TEdgeData TNodeEDatNet< TNodeData, TEdgeData >::TEdgeDat |
typedef TNodeEDatNet<TNodeData, TEdgeData> TNodeEDatNet< TNodeData, TEdgeData >::TNet |
typedef TVec<TPair<TInt, TEdgeData> > TNodeEDatNet< TNodeData, TEdgeData >::TNIdDatPrV |
typedef TNodeData TNodeEDatNet< TNodeData, TEdgeData >::TNodeDat |
TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet | ( | ) | [inline] |
TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet | ( | const int & | Nodes, |
const int & | Edges | ||
) | [inline, explicit] |
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition at line 585 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::Reserve().
TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet | ( | const TNodeEDatNet< TNodeData, TEdgeData > & | NodeNet | ) | [inline] |
TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet | ( | TSIn & | SIn | ) | [inline] |
virtual TNodeEDatNet< TNodeData, TEdgeData >::~TNodeEDatNet | ( | ) | [inline, virtual] |
int TNodeEDatNet< TNodeData, TEdgeData >::AddEdge | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Adds an edge from node IDs SrcNId to node DstNId to the network.
If the edge already exists return -2. If the edge does not exist and was successfully added return -1. Normally the function should return an ID of the edge added but since edges in TNodeEDatNet have no IDs we return -1. Function aborts if SrcNId or DstNId are not nodes in the network.
Definition at line 810 of file network.h.
{ return AddEdge(SrcNId, DstNId, TEdgeData()); }
int TNodeEDatNet< TNodeData, TEdgeData >::AddEdge | ( | const int & | SrcNId, |
const int & | DstNId, | ||
const TEdgeData & | EdgeDat | ||
) |
Adds an edge and edge data from node IDs SrcNId to node DstNId.
If the edge already exists, set edges data and returns -2. If the edge does not exist and was successfully added returns -1. Normally the function should return an ID of the edge added but since edges in TNodeEDatNet have no IDs it returns -1. Function aborts if SrcNId or DstNId are not nodes in the network.
Definition at line 815 of file network.h.
References TStr::Fmt(), and IAssertR.
{ IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr()); //IAssert(! IsEdge(SrcNId, DstNId)); if (IsEdge(SrcNId, DstNId)) { GetEDat(SrcNId, DstNId) = EdgeDat; return -2; } GetNode(SrcNId).OutNIdV.AddSorted(TPair<TInt, TEdgeData>(DstNId, EdgeDat)); GetNode(DstNId).InNIdV.AddSorted(SrcNId); return -1; // edge id }
int TNodeEDatNet< TNodeData, TEdgeData >::AddEdge | ( | const TEdgeI & | EdgeI | ) | [inline] |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network.
Definition at line 662 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::AddEdge(), TNodeEDatNet< TNodeData, TEdgeData >::TEdgeI::GetDstNId(), and TNodeEDatNet< TNodeData, TEdgeData >::TEdgeI::GetSrcNId().
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::AddEdge().
{ return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI()); }
int TNodeEDatNet< TNodeData, TEdgeData >::AddNode | ( | int | NId = -1 | ) |
Adds a node of ID NId to the network.
Returns the ID of the node being added. If NId is -1, node ID is automatically assigned. Aborts, if a node with ID NId already exists.
Definition at line 752 of file network.h.
References TStr::Fmt(), IAssertR, and TMath::Mx().
{ if (NId == -1) { NId = MxNId; MxNId++; } else { IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); MxNId = TMath::Mx(NId+1, MxNId()); } NodeH.AddDat(NId, TNode(NId)); return NId; }
int TNodeEDatNet< TNodeData, TEdgeData >::AddNode | ( | int | NId, |
const TNodeData & | NodeDat | ||
) |
Adds a node of ID NId and node data NodeDat to the network.
Returns the ID of the node being added. If NId is -1, node ID is automatically assigned. Aborts, if a node with ID NId already exists.
Definition at line 764 of file network.h.
References TStr::Fmt(), IAssertR, and TMath::Mx().
{ if (NId == -1) { NId = MxNId; MxNId++; } else { IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); MxNId = TMath::Mx(NId+1, MxNId()); } NodeH.AddDat(NId, TNode(NId, NodeDat)); return NId; }
int TNodeEDatNet< TNodeData, TEdgeData >::AddNode | ( | const TNodeI & | NodeId | ) | [inline] |
Adds a node NodeId and its node data to the network.
Definition at line 616 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::AddNode(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetId().
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::AddNode().
{ return AddNode(NodeId.GetId(), NodeId.GetDat()); }
TEdgeI TNodeEDatNet< TNodeData, TEdgeData >::BegEI | ( | ) | const [inline] |
Returns an iterator referring to the first edge in the network.
Definition at line 672 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::BegNI(), TNodeEDatNet< TNodeData, TEdgeData >::EndNI(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetOutDeg().
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::BegNI | ( | ) | const [inline] |
Returns an iterator referring to the first node in the network.
Definition at line 626 of file network.h.
References THash< TKey, TDat, THashFunc >::BegI(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::BegEI().
void TNodeEDatNet< TNodeData, TEdgeData >::Clr | ( | const bool & | DoDel = true , |
const bool & | ResetDat = true |
||
) | [inline] |
Deletes all nodes and edges from the network.
Definition at line 702 of file network.h.
References THash< TKey, TDat, THashFunc >::Clr(), TNodeEDatNet< TNodeData, TEdgeData >::MxNId, and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
void TNodeEDatNet< TNodeData, TEdgeData >::Defrag | ( | const bool & | OnlyNodeLinks = false | ) |
Defragments the network.
After performing many node and edge insertions and deletions to a network, the network data structure will be fragmented in memory. This function compacts down the network data structure and frees unneeded memory.
Definition at line 909 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::TNode::InNIdV, TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV, and TVec< TVal >::Pack().
{ for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n);) { TNode& Node = NodeH[n]; Node.InNIdV.Pack(); Node.OutNIdV.Pack(); } if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); } }
void TNodeEDatNet< TNodeData, TEdgeData >::DelEdge | ( | const int & | SrcNId, |
const int & | DstNId, | ||
const bool & | IsDir = true |
||
) |
Deletes an edge from node IDs SrcNId to DstNId from the network.
If the edge (SrcNId, DstNId) does not exist in the network function still completes. But the function aborts if SrcNId or DstNId are not nodes in the network.
Definition at line 828 of file network.h.
References TStr::Fmt(), and IAssertR.
{ IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr()); int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId); if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); } pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId); if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); } if (! IsDir) { pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId); if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); } pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId); if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); } } }
void TNodeEDatNet< TNodeData, TEdgeData >::DelNode | ( | const int & | NId | ) |
Deletes node of ID NId from the network.
If the node of ID NId does not exist the function aborts.
Definition at line 782 of file network.h.
References TVec< TVal >::Del(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInNId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutNId(), and TVec< TVal >::SearchBin().
{ const TNode& Node = GetNode(NId); for (int out = 0; out < Node.GetOutDeg(); out++) { const int nbr = Node.GetOutNId(out); if (nbr == NId) { continue; } TIntV& NIdV = GetNode(nbr).InNIdV; const int pos = NIdV.SearchBin(NId); if (pos != -1) { NIdV.Del(pos); } } for (int in = 0; in < Node.GetInDeg(); in++) { const int nbr = Node.GetInNId(in); if (nbr == NId) { continue; } TNIdDatPrV& NIdDatV = GetNode(nbr).OutNIdV; const int pos = GetNIdPos(NIdDatV, NId); if (pos != -1) { NIdDatV.Del(pos); } } NodeH.DelKey(NId); }
void TNodeEDatNet< TNodeData, TEdgeData >::DelNode | ( | const TNode & | NodeI | ) | [inline] |
Deletes node of ID NodeI.GetId() from the network.
Definition at line 622 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::DelNode(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetId().
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::DelNode().
{ DelNode(NodeI.GetId()); }
bool TNodeEDatNet< TNodeData, TEdgeData >::Empty | ( | ) | const [inline] |
Tests whether the network is empty (has zero nodes).
Definition at line 700 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::GetNodes().
{ return GetNodes()==0; }
TEdgeI TNodeEDatNet< TNodeData, TEdgeData >::EndEI | ( | ) | const [inline] |
Returns an iterator referring to the past-the-end edge in the network.
Definition at line 674 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::EndNI().
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::EndNI | ( | ) | const [inline] |
Returns an iterator referring to the past-the-end node in the network.
Definition at line 628 of file network.h.
References THash< TKey, TDat, THashFunc >::EndI(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::BegEI(), and TNodeEDatNet< TNodeData, TEdgeData >::EndEI().
bool TNodeEDatNet< TNodeData, TEdgeData >::GetEDat | ( | const int & | SrcNId, |
const int & | DstNId, | ||
TEdgeData & | EdgeDat | ||
) | const |
Returns edge data in Data for the edge from node IDs SrcNId to DstNId.
Returns true, if the edge was found. Otherwise, returns false.
Definition at line 857 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetInEDat().
{ if (! IsEdge(SrcNId, DstNId)) { return false; } const TNode& N = GetNode(SrcNId); EdgeDat = N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId)); return true; }
TEdgeData & TNodeEDatNet< TNodeData, TEdgeData >::GetEDat | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Returns edge data for the edge from node IDs SrcNId to DstNId.
Definition at line 865 of file network.h.
References Assert, TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
{ Assert(IsEdge(SrcNId, DstNId)); TNode& N = GetNode(SrcNId); return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId)); }
const TEdgeData & TNodeEDatNet< TNodeData, TEdgeData >::GetEDat | ( | const int & | SrcNId, |
const int & | DstNId | ||
) | const |
Returns edge data for the edge from node IDs SrcNId to DstNId.
Definition at line 872 of file network.h.
References Assert, TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
{ Assert(IsEdge(SrcNId, DstNId)); const TNode& N = GetNode(SrcNId); return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId)); }
int TNodeEDatNet< TNodeData, TEdgeData >::GetEdges | ( | ) | const |
Returns the number of edges in the network.
Definition at line 802 of file network.h.
{ int edges=0; for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) { edges+=NodeH[N].GetOutDeg(); } return edges; }
TEdgeI TNodeEDatNet< TNodeData, TEdgeData >::GetEI | ( | const int & | EId | ) | const |
Not supported/implemented!
TNodeEDatNet< TNodeData, TEdgeData >::TEdgeI TNodeEDatNet< TNodeData, TEdgeData >::GetEI | ( | const int & | SrcNId, |
const int & | DstNId | ||
) | const |
Returns an iterator referring to edge (SrcNId, DstNId) in the network.
Definition at line 886 of file network.h.
References TVec< TVal >::Len(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::NodeHI.
{ const TNodeI SrcNI = GetNI(SrcNId); int NodeN = -1; //SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId); const TNIdDatPrV& NIdDatV = SrcNI.NodeHI.GetDat().OutNIdV; int LValN=0, RValN=NIdDatV.Len()-1; while (RValN>=LValN){ int ValN=(LValN+RValN)/2; if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN; break; } if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;} else {LValN=ValN+1;} } if (NodeN == -1) { return EndEI(); } else { return TEdgeI(SrcNI, EndNI(), NodeN); } }
int TNodeEDatNet< TNodeData, TEdgeData >::GetMxNId | ( | ) | const [inline] |
Returns the maximum id of a any node in the network.
Definition at line 640 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::MxNId.
{ return MxNId; }
TNodeData& TNodeEDatNet< TNodeData, TEdgeData >::GetNDat | ( | const int & | NId | ) | [inline] |
Returns node data for the node of ID NId in the network.
Definition at line 636 of file network.h.
References THash< TKey, TDat, THashFunc >::GetDat(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::NodeDat, and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetInNDat(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetNbrNDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetOutNDat().
const TNodeData& TNodeEDatNet< TNodeData, TEdgeData >::GetNDat | ( | const int & | NId | ) | const [inline] |
Returns node data for the node of ID NId in the network.
Definition at line 638 of file network.h.
References THash< TKey, TDat, THashFunc >::GetDat(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::NodeDat, and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::GetNI | ( | const int & | NId | ) | const [inline] |
Returns an iterator referring to the node of ID NId in the network.
Definition at line 630 of file network.h.
References THash< TKey, TDat, THashFunc >::GetI(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::GetRndNI().
int TNodeEDatNet< TNodeData, TEdgeData >::GetNIdPos | ( | const TVec< TPair< TInt, TEdgeData > > & | NIdV, |
const int & | NId | ||
) | [static, protected] |
Definition at line 739 of file network.h.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNode::IsOutNId().
{ int LValN=0, RValN = NIdV.Len()-1; while (RValN >= LValN) { const int ValN = (LValN+RValN)/2; const int CurNId = NIdV[ValN].Val1; if (NId == CurNId) { return ValN; } if (NId < CurNId) { RValN=ValN-1; } else { LValN=ValN+1; } } return -1; }
void TNodeEDatNet< TNodeData, TEdgeData >::GetNIdV | ( | TIntV & | NIdV | ) | const |
Gets a vector IDs of all nodes in the network.
Definition at line 902 of file network.h.
References TVec< TVal >::Add(), and TVec< TVal >::Reserve().
{ NIdV.Reserve(GetNodes(), 0); for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) { NIdV.Add(NodeH.GetKey(N)); } }
TNode& TNodeEDatNet< TNodeData, TEdgeData >::GetNode | ( | const int & | NId | ) | [inline, protected] |
Definition at line 576 of file network.h.
References THash< TKey, TDat, THashFunc >::GetDat(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
const TNode& TNodeEDatNet< TNodeData, TEdgeData >::GetNode | ( | const int & | NId | ) | const [inline] |
Returns node element for the node of ID NId in the network.
Definition at line 632 of file network.h.
References THash< TKey, TDat, THashFunc >::GetDat(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
int TNodeEDatNet< TNodeData, TEdgeData >::GetNodes | ( | ) | const [inline] |
Returns the number of nodes in the network.
Definition at line 602 of file network.h.
References THash< TKey, TDat, THashFunc >::Len(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::Empty().
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::GetRndNI | ( | TRnd & | Rnd = TInt::Rnd | ) | [inline] |
Returns an interator referring to a random node in the network.
Definition at line 695 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::GetNI(), and TNodeEDatNet< TNodeData, TEdgeData >::GetRndNId().
int TNodeEDatNet< TNodeData, TEdgeData >::GetRndNId | ( | TRnd & | Rnd = TInt::Rnd | ) | [inline] |
Returns an ID of a random node in the network.
Definition at line 693 of file network.h.
References THash< TKey, TDat, THashFunc >::GetKey(), THash< TKey, TDat, THashFunc >::GetRndKeyId(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::GetRndNI().
{ return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
bool TNodeEDatNet< TNodeData, TEdgeData >::HasFlag | ( | const TGraphFlag & | Flag | ) | const |
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition at line 734 of file network.h.
References HasGraphFlag.
{ return HasGraphFlag(typename TNet, Flag); }
bool TNodeEDatNet< TNodeData, TEdgeData >::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 TNodeEDatNet< TNodeData, TEdgeData >::IsNode | ( | const int & | NId | ) | const [inline] |
Tests whether ID NId is a node.
Definition at line 624 of file network.h.
References THash< TKey, TDat, THashFunc >::IsKey(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
bool TNodeEDatNet< TNodeData, TEdgeData >::IsOk | ( | const bool & | ThrowExcept = true | ) | const |
Checks the network data structure for internal consistency.
For each node in the network check that its neighbors are also nodes in the network.
Definition at line 920 of file network.h.
References TStr::CStr(), EAssertR, ErrNotify(), TStr::Fmt(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInNId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutNId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::InNIdV, TVec< TVal >::IsSorted(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
{ bool RetVal = true; for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) { const TNode& Node = NodeH[N]; if (! Node.OutNIdV.IsSorted()) { const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (! Node.InNIdV.IsSorted()) { const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } // check out-edges int prevNId = -1; for (int e = 0; e < Node.GetOutDeg(); e++) { if (! IsNode(Node.GetOutNId(e))) { const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.", Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (e > 0 && prevNId == Node.GetOutNId(e)) { const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.", Node.GetId(), Node.GetId(), Node.GetOutNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } prevNId = Node.GetOutNId(e); } // check in-edges prevNId = -1; for (int e = 0; e < Node.GetInDeg(); e++) { if (! IsNode(Node.GetInNId(e))) { const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.", Node.GetId(), Node.GetInNId(e), Node.GetInNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (e > 0 && prevNId == Node.GetInNId(e)) { const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.", Node.GetId(), Node.GetId(), Node.GetInNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } prevNId = Node.GetInNId(e); } } return RetVal; }
static PNet TNodeEDatNet< TNodeData, TEdgeData >::Load | ( | TSIn & | SIn | ) | [inline, static] |
static PNet TNodeEDatNet< TNodeData, TEdgeData >::New | ( | ) | [inline, static] |
TNodeEDatNet& TNodeEDatNet< TNodeData, TEdgeData >::operator= | ( | const TNodeEDatNet< TNodeData, TEdgeData > & | NodeNet | ) | [inline] |
Definition at line 598 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::MxNId, and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
void TNodeEDatNet< TNodeData, TEdgeData >::Reserve | ( | const int & | Nodes, |
const int & | Edges | ||
) | [inline] |
Reserves memory for a network of Nodes nodes and Edges edges.
Definition at line 705 of file network.h.
References THash< TKey, TDat, THashFunc >::Gen(), and TNodeEDatNet< TNodeData, TEdgeData >::NodeH.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet().
virtual void TNodeEDatNet< TNodeData, TEdgeData >::Save | ( | TSOut & | SOut | ) | const [inline, virtual] |
Saves the network to a (binary) stream SOut.
Definition at line 591 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::MxNId, TNodeEDatNet< TNodeData, TEdgeData >::NodeH, THash< TKey, TDat, THashFunc >::Save(), and TInt::Save().
void TNodeEDatNet< TNodeData, TEdgeData >::SetAllEDat | ( | const TEdgeData & | EdgeDat | ) |
void TNodeEDatNet< TNodeData, TEdgeData >::SetEDat | ( | const int & | SrcNId, |
const int & | DstNId, | ||
const TEdgeData & | EdgeDat | ||
) |
Sets edge data for the edge between nodes SrcNId and DstNId in the network.
Definition at line 850 of file network.h.
References TStr::Fmt(), and IAssertR.
{ IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr()); IAssertR(IsEdge(SrcNId, DstNId), TStr::Fmt("Edge between %d and %d does not exist.", SrcNId, DstNId).CStr()); GetEDat(SrcNId, DstNId) = EdgeDat; }
void TNodeEDatNet< TNodeData, TEdgeData >::SetNDat | ( | const int & | NId, |
const TNodeData & | NodeDat | ||
) |
void TNodeEDatNet< TNodeData, TEdgeData >::SortNIdByDat | ( | const bool & | Asc = true | ) | [inline] |
Sorts nodes by node data.
Definition at line 709 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::NodeH, and THash< TKey, TDat, THashFunc >::SortByDat().
void TNodeEDatNet< TNodeData, TEdgeData >::SortNIdById | ( | const bool & | Asc = true | ) | [inline] |
Sorts nodes by node IDs.
Definition at line 707 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::NodeH, and THash< TKey, TDat, THashFunc >::SortByKey().
friend class TPt< TNodeEDatNet< TNodeData, TEdgeData > > [friend] |
TCRef TNodeEDatNet< TNodeData, TEdgeData >::CRef [protected] |
TInt TNodeEDatNet< TNodeData, TEdgeData >::MxNId [protected] |
Definition at line 580 of file network.h.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::Clr(), TNodeEDatNet< TNodeData, TEdgeData >::GetMxNId(), TNodeEDatNet< TNodeData, TEdgeData >::operator=(), and TNodeEDatNet< TNodeData, TEdgeData >::Save().
THash<TInt, TNode> TNodeEDatNet< TNodeData, TEdgeData >::NodeH [protected] |
Definition at line 581 of file network.h.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::BegNI(), TNodeEDatNet< TNodeData, TEdgeData >::Clr(), TNodeEDatNet< TNodeData, TEdgeData >::EndNI(), TNodeEDatNet< TNodeData, TEdgeData >::GetNDat(), TNodeEDatNet< TNodeData, TEdgeData >::GetNI(), TNodeEDatNet< TNodeData, TEdgeData >::GetNode(), TNodeEDatNet< TNodeData, TEdgeData >::GetNodes(), TNodeEDatNet< TNodeData, TEdgeData >::GetRndNId(), TNodeEDatNet< TNodeData, TEdgeData >::IsNode(), TNodeEDatNet< TNodeData, TEdgeData >::operator=(), TNodeEDatNet< TNodeData, TEdgeData >::Reserve(), TNodeEDatNet< TNodeData, TEdgeData >::Save(), TNodeEDatNet< TNodeData, TEdgeData >::SortNIdByDat(), and TNodeEDatNet< TNodeData, TEdgeData >::SortNIdById().