SNAP Library 6.0, Developer Reference
2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
Node Edge Network (directed graph, TNGraph with data on nodes and edges). More...
#include <network.h>
Classes | |
class | TEdgeI |
Edge iterator. Only forward iteration (operator++) is supported. More... | |
class | TNode |
class | TNodeFunctor |
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. More... | |
TNodeEDatNet (const TNodeEDatNet &NodeNet) | |
TNodeEDatNet (TSIn &SIn) | |
Constructor that loads the network from a (binary) stream SIn. More... | |
virtual | ~TNodeEDatNet () |
virtual void | Save (TSOut &SOut) const |
Saves the network to a (binary) stream SOut. More... | |
bool | HasFlag (const TGraphFlag &Flag) const |
Allows for run-time checking the type of the network (see the TGraphFlag for flags). More... | |
TNodeEDatNet & | operator= (const TNodeEDatNet &NodeNet) |
int | GetNodes () const |
Returns the number of nodes in the network. More... | |
int | AddNode (int NId=-1) |
Adds a node of ID NId to the network. More... | |
int | AddNodeUnchecked (int NId=-1) |
Adds a node of ID NId to the network, noop if the node already exists. More... | |
int | AddNode (int NId, const TNodeData &NodeDat) |
Adds a node of ID NId and node data NodeDat to the network. More... | |
int | AddNode (const TNodeI &NodeI) |
Adds a node NodeI and its node data to the network. More... | |
void | DelNode (const int &NId) |
Deletes node of ID NId from the network. More... | |
void | DelNode (const TNode &NodeI) |
Deletes node of ID NodeI.GetId() from the network. More... | |
bool | IsNode (const int &NId) const |
Tests whether ID NId is a node. More... | |
TNodeI | BegNI () const |
Returns an iterator referring to the first node in the network. More... | |
TNodeI | EndNI () const |
Returns an iterator referring to the past-the-end node in the network. More... | |
TNodeI | GetNI (const int &NId) const |
Returns an iterator referring to the node of ID NId in the network. More... | |
const TNode & | GetNode (const int &NId) const |
Returns node element for the node of ID NId in the network. More... | |
void | SetNDat (const int &NId, const TNodeData &NodeDat) |
Sets node data for the node of ID NId in the network. More... | |
TNodeData & | GetNDat (const int &NId) |
Returns node data for the node of ID NId in the network. More... | |
const TNodeData & | GetNDat (const int &NId) const |
Returns node data for the node of ID NId in the network. More... | |
int | GetMxNId () const |
Returns an ID that is larger than any node ID in the network. More... | |
int | GetEdges () const |
Returns the number of edges in the network. More... | |
int | AddEdge (const int &SrcNId, const int &DstNId) |
Adds an edge from node SrcNId to node DstNId to the network. More... | |
int | AddEdge (const int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat) |
Adds an edge and edge data from node IDs SrcNId to node DstNId. More... | |
int | AddEdge (const TEdgeI &EdgeI) |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network. More... | |
void | DelEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true) |
Deletes an edge from node IDs SrcNId to DstNId from the network. More... | |
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. More... | |
TEdgeI | BegEI () const |
Returns an iterator referring to the first edge in the network. More... | |
TEdgeI | EndEI () const |
Returns an iterator referring to the past-the-end edge in the network. More... | |
TEdgeI | GetEI (const int &EId) const |
Not supported/implemented! More... | |
TEdgeI | GetEI (const int &SrcNId, const int &DstNId) const |
Returns an iterator referring to edge (SrcNId, DstNId) in the network. More... | |
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. More... | |
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. More... | |
TEdgeData & | GetEDat (const int &SrcNId, const int &DstNId) |
Returns edge data for the edge from node IDs SrcNId to DstNId. More... | |
const TEdgeData & | GetEDat (const int &SrcNId, const int &DstNId) const |
Returns edge data for the edge from node IDs SrcNId to DstNId. More... | |
void | SetAllEDat (const TEdgeData &EdgeDat) |
Sets edge data for all the edges in the network to EDat. More... | |
int | GetRndNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random node in the network. More... | |
TNodeI | GetRndNI (TRnd &Rnd=TInt::Rnd) |
Returns an interator referring to a random node in the network. More... | |
void | GetNIdV (TIntV &NIdV) const |
Gets a vector IDs of all nodes in the network. More... | |
bool | Empty () const |
Tests whether the network is empty (has zero nodes). More... | |
void | Clr (const bool &DoDel=true, const bool &ResetDat=true) |
Deletes all nodes and edges from the network. More... | |
void | Reserve (const int &Nodes, const int &Edges) |
Reserves memory for a network of Nodes nodes and Edges edges. More... | |
void | SortNIdById (const bool &Asc=true) |
Sorts nodes by node IDs. More... | |
void | SortNIdByDat (const bool &Asc=true) |
Sorts nodes by node data. More... | |
void | Defrag (const bool &OnlyNodeLinks=false) |
Defragments the network. More... | |
bool | IsOk (const bool &ThrowExcept=true) const |
Checks the network data structure for internal consistency. More... | |
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(). More... | |
static PNet | Load (TSIn &SIn) |
Static constructor that loads the network from a stream SIn and returns a pointer to it. More... | |
static PNet | LoadShM (TShMIn &ShMIn) |
Static constructor that loads the network from shared memory. More... | |
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 |
Private Member Functions | |
void | LoadNetworkShM (TShMIn &ShMIn) |
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 |
|
inline |
|
inlineexplicit |
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition at line 653 of file network.h.
|
inline |
|
inline |
|
inlinevirtual |
int TNodeEDatNet< TNodeData, TEdgeData >::AddEdge | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Adds an edge from node 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 906 of file network.h.
Referenced by TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredTxt(), and TNIBs::UpdateDiff().
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 911 of file network.h.
References TStr::Fmt(), and IAssertR.
|
inline |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network.
Definition at line 746 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::AddEdge().
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 836 of file network.h.
References TStr::Fmt(), IAssertR, and TMath::Mx().
Referenced by TNIBs::Init(), TNIBs::LoadGroundTruthNodesTxt(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredNodesTxt(), and TNIBs::LoadInferredTxt().
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 860 of file network.h.
References TStr::Fmt(), IAssertR, and TMath::Mx().
|
inline |
Adds a node NodeI and its node data to the network.
Definition at line 700 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::AddNode().
int TNodeEDatNet< TNodeData, TEdgeData >::AddNodeUnchecked | ( | int | NId = -1 | ) |
Adds a node of ID NId to the network, noop if the node already exists.
Returns -1, if the node NId already exists. Otherwise, it returns the ID of the node being added. If NId is -1, node ID is automatically assigned.
Definition at line 848 of file network.h.
References TMath::Mx().
|
inline |
Returns an iterator referring to the first edge in the network.
Definition at line 756 of file network.h.
Referenced by TNIBs::BSG(), TNIBs::FG(), TNIBs::GetGroundTruthGraphAtT(), TNIBs::GetGroundTruthNetworkAtT(), TNIBs::GetInferredGraphAtT(), TNIBs::GetInferredNetworkAtT(), TNIBs::SaveGroundTruth(), TNIBs::SaveGroundTruthPajek(), TNIBs::SaveInferred(), TNIBs::SaveInferredEdges(), TNIBs::SaveInferredPajek(), and TNIBs::SG().
|
inline |
Returns an iterator referring to the first node in the network.
Definition at line 710 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::BegEI().
|
inline |
Deletes all nodes and edges from the network.
Definition at line 786 of file network.h.
Referenced by TNIBs::Init(), TNIBs::LoadGroundTruthNodesTxt(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredNodesTxt(), and TNIBs::LoadInferredTxt().
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 1005 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::TNode::InNIdV, TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Pack().
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 924 of file network.h.
References TStr::Fmt(), and IAssertR.
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 878 of file network.h.
References TVec< TVal, TSizeTy >::Del(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInNId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutNId(), and TVec< TVal, TSizeTy >::SearchBin().
|
inline |
Deletes node of ID NodeI.GetId() from the network.
Definition at line 706 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::DelNode().
|
inline |
Tests whether the network is empty (has zero nodes).
Definition at line 784 of file network.h.
|
inline |
Returns an iterator referring to the past-the-end edge in the network.
Definition at line 758 of file network.h.
Referenced by TNIBs::BSG(), TNIBs::FG(), TNIBs::GetGroundTruthGraphAtT(), TNIBs::GetGroundTruthNetworkAtT(), TNIBs::GetInferredGraphAtT(), TNIBs::GetInferredNetworkAtT(), TNIBs::SaveGroundTruth(), TNIBs::SaveGroundTruthPajek(), TNIBs::SaveInferred(), TNIBs::SaveInferredEdges(), TNIBs::SaveInferredPajek(), and TNIBs::SG().
|
inline |
Returns an iterator referring to the past-the-end node in the network.
Definition at line 712 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::BegEI(), and TNodeEDatNet< TStr, TFltFltH >::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 953 of file network.h.
References TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
Referenced by TNIBs::BSG(), TNIBs::ComputePerformanceNId(), TNIBs::FG(), TNIBs::GenCascade(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetInEDat(), TNIBs::LabelBurstAutomaton(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredTxt(), TNIBs::SG(), and TNIBs::UpdateDiff().
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 961 of file network.h.
References Assert, TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
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 968 of file network.h.
References Assert, TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
int TNodeEDatNet< TNodeData, TEdgeData >::GetEdges | ( | ) | const |
Returns the number of edges in the network.
Definition at line 898 of file network.h.
Referenced by TNIBs::LoadGroundTruthTxt(), and TNIBs::LoadInferredTxt().
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 982 of file network.h.
References TVec< TVal, TSizeTy >::Len(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::NodeHI.
|
inline |
|
inline |
Returns node data for the node of ID NId in the network.
Definition at line 720 of file network.h.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetInNDat(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetNbrNDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetOutNDat().
|
inline |
|
inline |
Returns an iterator referring to the node of ID NId in the network.
Definition at line 714 of file network.h.
Referenced by TNIBs::ComputePerformanceNId(), TNIBs::GenCascade(), and TNodeEDatNet< TStr, TFltFltH >::GetRndNI().
|
staticprotected |
Definition at line 823 of file network.h.
Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNode::IsOutNId().
void TNodeEDatNet< TNodeData, TEdgeData >::GetNIdV | ( | TIntV & | NIdV | ) | const |
Gets a vector IDs of all nodes in the network.
Definition at line 998 of file network.h.
References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Reserve().
|
inlineprotected |
|
inline |
|
inline |
Returns the number of nodes in the network.
Definition at line 680 of file network.h.
Referenced by TNIBs::BSG(), TNIBs::ComputePerformanceNId(), TNodeEDatNet< TStr, TFltFltH >::Empty(), TNIBs::FG(), TNIBs::GenCascade(), TNIBs::GetNodes(), TNIBs::LoadGroundTruthNodesTxt(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredNodesTxt(), and TNIBs::LoadInferredTxt().
|
inline |
Returns an interator referring to a random node in the network.
Definition at line 779 of file network.h.
|
inline |
Returns an ID of a random node in the network.
Definition at line 777 of file network.h.
Referenced by TNIBs::GenCascade(), and TNodeEDatNet< TStr, TFltFltH >::GetRndNI().
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 818 of file network.h.
References HasGraphFlag.
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.
Definition at line 939 of file network.h.
Referenced by TNIBs::BSG(), TNIBs::ComputePerformanceNId(), TNIBs::FG(), TNIBs::SG(), and TNIBs::UpdateDiff().
|
inline |
Tests whether ID NId is a node.
Definition at line 708 of file network.h.
Referenced by TNIBs::UpdateDiff().
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 1016 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, TSizeTy >::IsSorted(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.
|
inlinestatic |
|
inlineprivate |
Definition at line 645 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::LoadShM().
|
inlinestatic |
|
inlinestatic |
Static constructor that returns a pointer to the network. Call: TPt <TNodeEDatNet<TNodeData, TEdgeData> > Net = TNodeEDatNet<TNodeData, TEdgeData>::New().
Definition at line 661 of file network.h.
Referenced by TNIBs::GetGroundTruthNetworkAtT(), TNIBs::GetInferredNetworkAtT(), and main().
|
inline |
|
inline |
Reserves memory for a network of Nodes nodes and Edges edges.
Definition at line 789 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::TNodeEDatNet().
|
inlinevirtual |
Saves the network to a (binary) stream SOut.
Definition at line 659 of file network.h.
Referenced by TNIBs::Save().
void TNodeEDatNet< TNodeData, TEdgeData >::SetAllEDat | ( | const TEdgeData & | EdgeDat | ) |
Sets edge data for all the edges in the network to EDat.
Definition at line 975 of file network.h.
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 946 of file network.h.
References TStr::Fmt(), and IAssertR.
void TNodeEDatNet< TNodeData, TEdgeData >::SetNDat | ( | const int & | NId, |
const TNodeData & | NodeDat | ||
) |
Sets node data for the node of ID NId in the network.
Definition at line 872 of file network.h.
References TStr::Fmt(), and IAssertR.
|
inline |
|
inline |
|
friend |
|
protected |
|
protected |
Definition at line 636 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::GetMxNId(), and TNodeEDatNet< TStr, TFltFltH >::operator=().
|
protected |
Definition at line 637 of file network.h.
Referenced by TNodeEDatNet< TStr, TFltFltH >::GetNode(), and TNodeEDatNet< TStr, TFltFltH >::operator=().