SNAP Library 4.0, Developer Reference
2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
Directed graph. More...
#include <graph.h>
Classes | |
class | TEdgeI |
Edge iterator. Only forward iteration (operator++) is supported. More... | |
class | TLoadTNodeInitializer |
class | TNode |
class | TNodeI |
Node iterator. Only forward iteration (operator++) is supported. More... | |
Public Types | |
typedef TNGraph | TNet |
typedef TPt< TNGraph > | PNet |
Public Member Functions | |
TNGraph () | |
TNGraph (const int &Nodes, const int &Edges) | |
Constructor that reserves enough memory for a graph of Nodes nodes and Edges edges. More... | |
TNGraph (const TNGraph &Graph) | |
TNGraph (TSIn &SIn) | |
Constructor that loads the graph from a (binary) stream SIn. More... | |
void | Save (TSOut &SOut) const |
Saves the graph to a (binary) stream SOut. More... | |
bool | HasFlag (const TGraphFlag &Flag) const |
Allows for run-time checking the type of the graph (see the TGraphFlag for flags). More... | |
TNGraph & | operator= (const TNGraph &Graph) |
int | GetNodes () const |
Returns the number of nodes in the graph. More... | |
int | AddNode (int NId=-1) |
Adds a node of ID NId to the graph. More... | |
int | AddNodeUnchecked (int NId=-1) |
Adds a node of ID NId to the network, noop if the node already exists. More... | |
int | AddNode (const TNodeI &NodeId) |
Adds a node of ID NodeI.GetId() to the graph. More... | |
int | AddNode (const int &NId, const TIntV &InNIdV, const TIntV &OutNIdV) |
Adds a node of ID NId to the graph, creates edges to the node from all nodes in vector InNIdV, creates edges from the node to all nodes in vector OutNIdV. More... | |
int | AddNode (const int &NId, const TVecPool< TInt > &Pool, const int &SrcVId, const int &DstVId) |
Adds a node of ID NId to the graph, creates edges to the node from all nodes in vector InNIdV in the vector pool Pool, creates edges from the node to all nodes in vector OutNIdVin the vector pool Pool . More... | |
void | DelNode (const int &NId) |
Deletes node of ID NId from the graph. More... | |
void | DelNode (const TNode &NodeI) |
Deletes node of ID NodeI.GetId() from the graph. 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 graph. More... | |
TNodeI | EndNI () const |
Returns an iterator referring to the past-the-end node in the graph. More... | |
TNodeI | GetNI (const int &NId) const |
Returns an iterator referring to the node of ID NId in the graph. More... | |
int | GetMxNId () const |
Returns an ID that is larger than any node ID in the graph. More... | |
int | GetEdges () const |
Returns the number of edges in the graph. More... | |
int | AddEdge (const int &SrcNId, const int &DstNId) |
Adds an edge from node SrcNId to node DstNId to the graph. More... | |
int | AddEdgeUnchecked (const int &SrcNId, const int &DstNId) |
Adds an edge from node SrcNId to node DstNId to the graph. More... | |
int | AddEdge2 (const int &SrcNId, const int &DstNId) |
Adds an edge from node IDs SrcNId to node DstNId to the graph. If nodes do not exist, create them. More... | |
int | AddEdge (const TEdgeI &EdgeI) |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the graph. More... | |
void | DelEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true) |
Deletes an edge from node IDs SrcNId to DstNId from the graph. 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 graph. More... | |
TEdgeI | BegEI () const |
Returns an iterator referring to the first edge in the graph. More... | |
TEdgeI | EndEI () const |
Returns an iterator referring to the past-the-end edge in the graph. 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 graph. More... | |
int | GetRndNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random node in the graph. More... | |
TNodeI | GetRndNI (TRnd &Rnd=TInt::Rnd) |
Returns an interator referring to a random node in the graph. More... | |
void | GetNIdV (TIntV &NIdV) const |
Gets a vector IDs of all nodes in the graph. More... | |
bool | Empty () const |
Tests whether the graph is empty (has zero nodes). More... | |
void | Clr () |
Deletes all nodes and edges from the graph. More... | |
void | Reserve (const int &Nodes, const int &Edges) |
Reserves memory for a graph of Nodes nodes and Edges edges. More... | |
void | ReserveNIdInDeg (const int &NId, const int &InDeg) |
Reserves memory for node ID NId having InDeg in-edges. More... | |
void | ReserveNIdOutDeg (const int &NId, const int &OutDeg) |
Reserves memory for node ID NId having OutDeg out-edges. More... | |
void | SortNodeAdjV () |
Sorts the adjacency lists of each node. More... | |
void | Defrag (const bool &OnlyNodeLinks=false) |
Defragments the graph. More... | |
bool | IsOk (const bool &ThrowExcept=true) const |
Checks the graph data structure for internal consistency. More... | |
void | Dump (FILE *OutF=stdout) const |
Print the graph in a human readable form to an output stream OutF. More... | |
Static Public Member Functions | |
static PNGraph | New () |
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New(). More... | |
static PNGraph | New (const int &Nodes, const int &Edges) |
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and Edges edges. More... | |
static PNGraph | Load (TSIn &SIn) |
Static constructor that loads the graph from a stream SIn and returns a pointer to it. More... | |
static PNGraph | LoadShM (TShMIn &ShMIn) |
Static constructor that loads the graph from a shared memory stream and returns pointer to it. More... | |
static PNGraph | GetSmallGraph () |
Returns a small graph on 5 nodes and 6 edges. More... | |
Private Member Functions | |
TNode & | GetNode (const int &NId) |
const TNode & | GetNode (const int &NId) const |
void | LoadGraphShM (TShMIn &ShMIn) |
Private Attributes | |
TCRef | CRef |
TInt | MxNId |
THash< TInt, TNode > | NodeH |
Friends | |
class | TPt< TNGraph > |
class | TNGraphMtx |
Directed graph.
Node IDs can be arbitrary non-negative integers. Nodes and edges have no attributes/data associated with them. There is at most one directed edge from one source node to a destination node. There can be an edge between the same pair of nodes in the opposite direction. Self loops (one per node) are allowed but multiple (parallel) edges are not. The directed graph data structure is implemented using sorted adjacency lists. This means adding a node takes constant time, while adding an edge takes linear time (since adjacency list is kept sorted) in the node degree. Accessing arbitrary node takes constant time and accessing any edge takes logarithmic time in the node degree.
typedef TPt<TNGraph> TNGraph::PNet |
typedef TNGraph TNGraph::TNet |
|
inline |
|
inlineexplicit |
Constructor that reserves enough memory for a graph of Nodes nodes and Edges edges.
Definition at line 470 of file graph.h.
References Reserve().
|
inline |
int TNGraph::AddEdge | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Adds an edge from node SrcNId to node DstNId to the graph.
If the edge already exists return -2. If the edge was successfully added return -1. Normally the function should return an ID of the edge added but since edges in TNGraph have no IDs we return -1. Function aborts if SrcNId or DstNId are not nodes in the graph.
Definition at line 321 of file graph.cpp.
References TVec< TVal, TSizeTy >::AddSorted(), TStr::Fmt(), GetNode(), IAssertR, TNGraph::TNode::InNIdV, IsEdge(), IsNode(), and TNGraph::TNode::OutNIdV.
Referenced by TFfGGen::AddNodes(), TSnap::CascGraphSource(), TSnap::CascGraphTime(), TKronNoise::FlipEdgeNoise(), TMAGParam< TNodeAttr >::GenAttrMAG(), TSnap::GenCopyModel(), TKronMtx::GenDetKronecker(), TKronMtx::GenFastKronecker(), TKronMtx::GenKronecker(), TSnap::GenRewire(), TSnap::GenRMat(), TKronMtx::GenRndGraph(), TKronMtx::GenThreshGraph(), TSnap::GetBfsTree(), TSnap::GetEgonet(), TGraphEnumUtils::GetGraph(), TCoda::GetGraphRawNID(), TNIBs::GetGroundTruthGraphAtT(), TGraphEnumUtils::GetIndGraph(), TNIBs::GetInferredGraphAtT(), TGraphKey::GetNGraph(), TGraphEnumUtils::GetNormalizedGraph(), GetSmallGraph(), TSnap::GetSubGraph(), TBigNet< TNodeData, IsDir >::GetSubNGraph(), TNetInfBs::GreedyOpt(), TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), TNetInfBs::LoadGroundTruthTxt(), main(), TCodaAnalyzer::Net2ModeCommunities(), TSnap::ReebRefine(), TSnap::ReebSimplify(), and TKroneckerLL::SetRandomEdges().
|
inline |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the graph.
Definition at line 576 of file graph.h.
References AddEdge(), TNGraph::TEdgeI::GetDstNId(), and TNGraph::TEdgeI::GetSrcNId().
Referenced by AddEdge().
int TNGraph::AddEdge2 | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Adds an edge from node IDs SrcNId to node DstNId to the graph. If nodes do not exist, create them.
Definition at line 336 of file graph.cpp.
References AddNode(), TVec< TVal, TSizeTy >::AddSorted(), GetNode(), TNGraph::TNode::InNIdV, IsNode(), and TNGraph::TNode::OutNIdV.
int TNGraph::AddEdgeUnchecked | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Adds an edge from node SrcNId to node DstNId to the graph.
Returns -1. The method assumes that SrcNId and DstNId are existing nodes in the graph and adds new neighbor values at the end of their adjacency vectors. No checks are performed to verify these assumptions. Adjacency vectors must be sorted and have duplicates removed after a sequence of these operations to assure consistency of data structures.
Definition at line 330 of file graph.cpp.
References TVec< TVal, TSizeTy >::Add(), GetNode(), TNGraph::TNode::InNIdV, and TNGraph::TNode::OutNIdV.
int TNGraph::AddNode | ( | int | NId = -1 | ) |
Adds a node of ID NId to the graph.
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 236 of file graph.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), TStr::Fmt(), IAssertR, IsNode(), TMath::Mx(), MxNId, and NodeH.
Referenced by AddEdge2(), TFfGGen::AddNodes(), TKroneckerLL::AppendIsoNodes(), TSnap::CascGraphSource(), TSnap::CascGraphTime(), TMAGParam< TNodeAttr >::GenAttrMAG(), TSnap::GenCopyModel(), TKronMtx::GenDetKronecker(), TKronMtx::GenFastKronecker(), TKronMtx::GenKronecker(), TSnap::GenRewire(), TSnap::GenRMat(), TKronMtx::GenRndGraph(), TKronMtx::GenThreshGraph(), TSnap::GetBfsTree(), TSnap::GetEgonet(), TGraphEnumUtils::GetGraph(), TCoda::GetGraphRawNID(), TNIBs::GetGroundTruthGraphAtT(), TGraphEnumUtils::GetIndGraph(), TNIBs::GetInferredGraphAtT(), TGraphKey::GetNGraph(), TBigNet< TNodeData, IsDir >::GetNGraph(), TGraphEnumUtils::GetNormalizedGraph(), GetSmallGraph(), TSnap::GetSubGraph(), TBigNet< TNodeData, IsDir >::GetSubNGraph(), TNetInfBs::Init(), TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), TNetInfBs::LoadGroundTruthTxt(), main(), TCodaAnalyzer::Net2ModeCommunities(), TSnap::ReebRefine(), and TSnap::ReebSimplify().
|
inline |
Adds a node of ID NodeI.GetId() to the graph.
Definition at line 513 of file graph.h.
References AddNode(), and TNGraph::TNodeI::GetId().
Referenced by AddNode().
Adds a node of ID NId to the graph, creates edges to the node from all nodes in vector InNIdV, creates edges from the node to all nodes in vector OutNIdV.
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.
The operation can create inconsistent graphs when the neighboring nodes in vectors InNIdV and OutNIdV do not exist. Use TNGraph::IsOk to check that the resulting graph is consistent after the operation.
Definition at line 256 of file graph.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), TStr::Fmt(), IAssertR, TNGraph::TNode::Id, TNGraph::TNode::InNIdV, IsNode(), TMath::Mx(), MxNId, NodeH, TNGraph::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Sort().
int TNGraph::AddNode | ( | const int & | NId, |
const TVecPool< TInt > & | Pool, | ||
const int & | SrcVId, | ||
const int & | DstVId | ||
) |
Adds a node of ID NId to the graph, creates edges to the node from all nodes in vector InNIdV in the vector pool Pool, creates edges from the node to all nodes in vector OutNIdVin the vector pool Pool .
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.
The operation can create inconsistent graphs when the neighboring nodes stored in the Pool vector are not explicitly added to the graph. Use TNGraph::IsOk to check that the resulting graph is consistent.
Definition at line 276 of file graph.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), TStr::Fmt(), TVec< TVal, TSizeTy >::GenExt(), TVecPool< TVal, TSizeTy >::GetValVPt(), TVecPool< TVal, TSizeTy >::GetVLen(), IAssertR, TNGraph::TNode::Id, TNGraph::TNode::InNIdV, IsNode(), TMath::Mx(), MxNId, NodeH, TNGraph::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Sort().
int TNGraph::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 247 of file graph.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), IsNode(), TMath::Mx(), MxNId, and NodeH.
|
inline |
Returns an iterator referring to the first edge in the graph.
Definition at line 586 of file graph.h.
References BegNI(), EndNI(), and TNGraph::TNodeI::GetOutDeg().
Referenced by TempMotifCounter::Count3TEdge2Node(), TempMotifCounter::Count3TEdgeTriads(), ProcessedGraph::countDirTriadMotif(), MotifCluster::EdgeMotifAdjacency(), TKronNoise::FlipEdgeNoise(), TGraphEnumUtils::GetIsoGraphs(), TGraphEnumUtils::GetNormalizedGraph(), TMAGFitBern::GradApxAffMtx(), TGraphEnumUtils::GraphId(), node2vec(), TKronNoise::RemoveEdgeNoise(), TNetInfBs::SaveGroundTruth(), TNetInfBs::SavePajek(), TNetInfBs::SavePlaneTextNet(), and TKroneckerLL::SetGraph().
|
inline |
Returns an iterator referring to the first node in the graph.
Definition at line 544 of file graph.h.
References THash< TKey, TDat, THashFunc >::BegI(), and NodeH.
Referenced by BegEI(), MotifCluster::BifanMotifAdjacency(), TSnap::CascFind(), TSnap::CascFindMP(), ProcessedGraph::countDirTriadMotif(), MotifCluster::DegreeOrdering(), TCodaAnalyzer::Draw2ModeCommunity(), TSnap::EventImportance(), TSnap::EventImportance1(), TSubGraphsEnum::Gen2Graphs(), TSnap::GenRewire(), TempMotifCounter::GetAllNodes(), TCoda::GetGraphRawNID(), TGHash< TDat >::GetNodeMap(), TGraphEnumUtils::GetNormalizedMap(), TSnap::GetSngVals(), TSnap::GetSngVec(), TForestFire::InfectAll(), TForestFire::InfectRnd(), TNetInfBs::Init(), main(), TFfGGen::PlotFireSize(), TTimeNet::PlotMedianDegOverTm(), TSubGraphsEnum::RecurBfs(), TSubGraphsEnum::RecurBfs1(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TNetInfBs::SaveCascades(), TNetInfBs::SaveGroundTruth(), TKroneckerLL::SetDegPerm(), SortNodeAdjV(), TGraphKey::TakeGraph(), TGraphKey::TakeSig(), MotifCluster::TriangleMotifAdjacency(), and MotifCluster::WedgeMotifAdjacency().
|
inline |
Deletes all nodes and edges from the graph.
Definition at line 604 of file graph.h.
References THash< TKey, TDat, THashFunc >::Clr(), MxNId, and NodeH.
Referenced by TFfGGen::Clr(), and TGraphEnumUtils::GetGraph().
void TNGraph::Defrag | ( | const bool & | OnlyNodeLinks = false | ) |
Defragments the graph.
After performing many node and edge insertions and deletions to a graph, the graph data structure will be fragmented in memory. This function compacts down the graph data structure and frees unneeded memory.
Definition at line 382 of file graph.cpp.
References THash< TKey, TDat, THashFunc >::Defrag(), THash< TKey, TDat, THashFunc >::FFirstKeyId(), THash< TKey, TDat, THashFunc >::FNextKeyId(), TNGraph::TNode::InNIdV, THash< TKey, TDat, THashFunc >::IsKeyIdEqKeyN(), NodeH, TNGraph::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Pack().
Referenced by TSnap::GenRMat(), and TGraphKey::GetNGraph().
void TNGraph::DelEdge | ( | const int & | SrcNId, |
const int & | DstNId, | ||
const bool & | IsDir = true |
||
) |
Deletes an edge from node IDs SrcNId to DstNId from the graph.
If the edge (SrcNId, DstNId) does not exist in the graph function still completes. But the function aborts if SrcNId or DstNId are not nodes in the graph.
Definition at line 345 of file graph.cpp.
References TVec< TVal, TSizeTy >::Del(), TStr::Fmt(), GetNode(), IAssertR, TNGraph::TNode::InNIdV, IsNode(), TNGraph::TNode::OutNIdV, and TVec< TVal, TSizeTy >::SearchBin().
Referenced by TKronNoise::FlipEdgeNoise(), TKroneckerLL::MetroGibbsSampleNext(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TKronNoise::RemoveEdgeNoise(), and TKroneckerLL::RestoreGraph().
void TNGraph::DelNode | ( | const int & | NId | ) |
Deletes node of ID NId from the graph.
If the node of ID NId does not exist the function aborts.
Definition at line 294 of file graph.cpp.
References TVec< TVal, TSizeTy >::Del(), THash< TKey, TDat, THashFunc >::DelKey(), TNGraph::TNode::GetInDeg(), TNGraph::TNode::GetInNId(), GetNode(), TNGraph::TNode::GetOutDeg(), TNGraph::TNode::GetOutNId(), TNGraph::TNode::InNIdV, NodeH, TNGraph::TNode::OutNIdV, and TVec< TVal, TSizeTy >::SearchBin().
Referenced by TCodaAnalyzer::Net2ModeCommunities(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TKronNoise::RemoveNodeNoise(), and TKroneckerLL::RestoreGraph().
|
inline |
Deletes node of ID NodeI.GetId() from the graph.
Definition at line 540 of file graph.h.
References DelNode(), and TNGraph::TNode::GetId().
Referenced by DelNode().
void TNGraph::Dump | ( | FILE * | OutF = stdout | ) | const |
Print the graph in a human readable form to an output stream OutF.
Definition at line 437 of file graph.cpp.
References edge, THash< TKey, TDat, THashFunc >::FFirstKeyId(), THash< TKey, TDat, THashFunc >::FNextKeyId(), GetEdges(), TNGraph::TNode::GetId(), TNGraph::TNode::GetInDeg(), TNGraph::TNode::GetInNId(), GetNodes(), TNGraph::TNode::GetOutDeg(), TNGraph::TNode::GetOutNId(), and NodeH.
|
inline |
Tests whether the graph is empty (has zero nodes).
Definition at line 602 of file graph.h.
References GetNodes().
|
inline |
Returns an iterator referring to the past-the-end edge in the graph.
Definition at line 588 of file graph.h.
References EndNI().
Referenced by TempMotifCounter::Count3TEdge2Node(), TempMotifCounter::Count3TEdgeTriads(), ProcessedGraph::countDirTriadMotif(), MotifCluster::EdgeMotifAdjacency(), TKronNoise::FlipEdgeNoise(), TGraphEnumUtils::GetIsoGraphs(), TGraphEnumUtils::GetNormalizedGraph(), TMAGFitBern::GradApxAffMtx(), TGraphEnumUtils::GraphId(), node2vec(), TKronNoise::RemoveEdgeNoise(), TNetInfBs::SaveGroundTruth(), TNetInfBs::SavePajek(), TNetInfBs::SavePlaneTextNet(), and TKroneckerLL::SetGraph().
|
inline |
Returns an iterator referring to the past-the-end node in the graph.
Definition at line 546 of file graph.h.
References THash< TKey, TDat, THashFunc >::EndI(), and NodeH.
Referenced by BegEI(), MotifCluster::BifanMotifAdjacency(), TSnap::CascFind(), TSnap::CascFindMP(), ProcessedGraph::countDirTriadMotif(), MotifCluster::DegreeOrdering(), TCodaAnalyzer::Draw2ModeCommunity(), EndEI(), TSnap::EventImportance(), TSnap::EventImportance1(), TSubGraphsEnum::Gen2Graphs(), TSnap::GenRewire(), TempMotifCounter::GetAllNodes(), GetEI(), TCoda::GetGraphRawNID(), TGraphEnumUtils::GetNormalizedMap(), TSnap::GetSngVals(), TSnap::GetSngVec(), TForestFire::InfectAll(), TForestFire::InfectRnd(), TNetInfBs::Init(), main(), TFfGGen::PlotFireSize(), TTimeNet::PlotMedianDegOverTm(), TSubGraphsEnum::RecurBfs(), TSubGraphsEnum::RecurBfs1(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TNetInfBs::SaveCascades(), TNetInfBs::SaveGroundTruth(), TKroneckerLL::SetDegPerm(), SortNodeAdjV(), TGraphKey::TakeGraph(), TGraphKey::TakeSig(), MotifCluster::TriangleMotifAdjacency(), and MotifCluster::WedgeMotifAdjacency().
int TNGraph::GetEdges | ( | ) | const |
Returns the number of edges in the graph.
Definition at line 313 of file graph.cpp.
References THash< TKey, TDat, THashFunc >::FFirstKeyId(), THash< TKey, TDat, THashFunc >::FNextKeyId(), and NodeH.
Referenced by TFfGGen::AddNodes(), Dump(), TKronNoise::FlipEdgeNoise(), TSubGraphsEnum::Gen2Graphs(), TKronMtx::GenFastKronecker(), TKronMtx::GenKronecker(), TSnap::GenRewire(), TKroneckerLL::GetAbsErr(), TNetInfBs::GetBestEdge(), TNetInfBs::GetBound(), TCoda::GetGraphRawNID(), TSnap::GetSngVals(), TSnap::GetSngVec(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), TNetInfBs::GreedyOpt(), TNetInfBs::LoadGroundTruthTxt(), TCodaAnalyzer::Net2ModeCommunities(), TMAGFitBern::NormalizeAffMtxV(), TKronMtx::PlotCmpGraphs(), TForestFire::PlotFire(), TFfGGen::PlotFireSize(), TTimeNet::PlotMedianDegOverTm(), TMAGFitBern::PlotProperties(), TSnap::PlotSngValDistr(), TSnap::PlotSngValRank(), TSnap::PlotSngVec(), TKronNoise::RemoveEdgeNoise(), TKroneckerLL::RunMStep(), TKroneckerLL::SetGraph(), TGraphKey::TakeSig(), TGStat::TakeStat(), TCodaAnalyzer::TCodaAnalyzer(), TKroneckerLL::TestBicCriterion(), TKroneckerLL::TestGradDescent(), TKroneckerLL::TestSamplePerm(), and TMAGFitBern::UnNormalizeAffMtxV().
TEdgeI TNGraph::GetEI | ( | const int & | EId | ) | const |
Not supported/implemented!
TNGraph::TEdgeI TNGraph::GetEI | ( | const int & | SrcNId, |
const int & | DstNId | ||
) | const |
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition at line 369 of file graph.cpp.
References EndNI(), GetNI(), IAssert, and TNGraph::TNodeI::NodeHI.
|
inline |
Returns an ID that is larger than any node ID in the graph.
Definition at line 552 of file graph.h.
References MxNId.
Referenced by TempMotifCounter::Count3TEdgeTriads(), MotifCluster::DegreeOrdering(), TempMotifCounter::GetAllStaticTriangles(), MotifCluster::MotifAdjacency(), and TempMotifCounter::TempMotifCounter().
|
inline |
Returns an iterator referring to the node of ID NId in the graph.
Definition at line 548 of file graph.h.
References THash< TKey, TDat, THashFunc >::GetI(), and NodeH.
Referenced by MotifCluster::BifanMotifAdjacency(), TForestFire::BurnExpFire(), TForestFire::BurnGeoFire(), TKroneckerLL::CalcApxGraphDLL(), TKroneckerLL::CalcApxGraphLL(), TKroneckerLL::CalcGraphLL(), TSnap::CascFind(), TSnap::CascFindMP(), TempMotifCounter::Count3TEdge3NodeStars(), TSnap::EventImportance(), TSnap::EventImportance1(), TNetInfBs::GenCascade(), TSnap::GenCopyModel(), TempMotifCounter::GetAllNeighbors(), TSnap::GetEgonet(), GetEI(), TGraphEnumUtils::GetIndGraph(), TCascade::GetProb(), GetRndNI(), TSnap::GetSubGraph(), TCoda::GradientForNode(), higherDeg(), TSnap::TSnapDetail::inComp(), KNNJaccard(), KNNJaccardParallel(), TCoda::LikelihoodForNode(), TCoda::MLEGradAscent(), TCoda::MLEGradAscentParallel(), TCoda::NeighborComInit(), TCodaAnalyzer::Net2ModeCommunities(), TKroneckerLL::NodeDLLDelta(), TKroneckerLL::NodeLLDelta(), TCoda::RandomInit(), TSubGraphsEnum::RecurBfs(), TSubGraphsEnum::RecurBfs1(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TKroneckerLL::SetBestDegPerm(), and TMAGFitBern::UpdateApxPhiMI().
void TNGraph::GetNIdV | ( | TIntV & | NIdV | ) | const |
Gets a vector IDs of all nodes in the graph.
Definition at line 376 of file graph.cpp.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::FFirstKeyId(), THash< TKey, TDat, THashFunc >::FNextKeyId(), TVec< TVal, TSizeTy >::Gen(), THash< TKey, TDat, THashFunc >::GetKey(), GetNodes(), and NodeH.
Referenced by TKronNoise::FlipEdgeNoise(), TCoda::GetNonEdgePairScores(), KNNJaccard(), KNNJaccardParallel(), TCodaAnalyzer::Net2ModeCommunities(), TKronNoise::RemoveNodeNoise(), TCoda::SetGraph(), TKroneckerLL::SetGraph(), and TMAGFitBern::SetGraph().
|
inlineprivate |
Definition at line 459 of file graph.h.
References THash< TKey, TDat, THashFunc >::GetDat(), and NodeH.
Referenced by AddEdge(), AddEdge2(), AddEdgeUnchecked(), DelEdge(), DelNode(), IsEdge(), ReserveNIdInDeg(), and ReserveNIdOutDeg().
|
inlineprivate |
Definition at line 460 of file graph.h.
References THash< TKey, TDat, THashFunc >::GetDat(), and NodeH.
|
inline |
Returns the number of nodes in the graph.
Definition at line 499 of file graph.h.
References THash< TKey, TDat, THashFunc >::Len(), and NodeH.
Referenced by TGStatVec::Add(), TFfGGen::AddNodes(), TKroneckerLL::AppendIsoNodes(), TNGraphMtx::CheckNodeIds(), Dump(), TCoda::DumpMemberships(), Empty(), TCoda::FindComsByCV(), TKronNoise::FlipEdgeNoise(), TNetInfBs::GenCascade(), TFfGGen::GenGraph(), TSnap::GenRewire(), TCoda::GetCmtyS(), TCoda::GetCmtyVV(), TCoda::GetCmtyVVUnSorted(), TCoda::GetGraphRawNID(), TGraphEnumUtils::GetIsoGraphs(), GetNIdV(), TGHash< TDat >::GetNodeMap(), TNetInfBs::GetNodes(), TCoda::GetNonEdgePairScores(), TGraphEnumUtils::GetNormalizedGraph(), TKronMtx::GetNZeroK(), TSnap::GetSngVals(), TSnap::GetSngVec(), TSubGraphEnum< TGraphCounter >::GetSubGraphs(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), TGraphEnumUtils::GraphId(), TForestFire::InfectAll(), TForestFire::InfectRnd(), KNNJaccard(), TNetInfBs::LoadGroundTruthTxt(), TCoda::MLEGradAscent(), TCoda::MLEGradAscentParallel(), TCoda::NeighborComInit(), TCodaAnalyzer::Net2ModeCommunities(), TNGraphMtx::PGetCols(), TNGraphMtx::PGetRows(), TKronMtx::PlotCmpGraphs(), TTimeNENet::PlotEffDiam(), TForestFire::PlotFire(), TFfGGen::PlotFireSize(), TTimeNet::PlotMedianDegOverTm(), TSnap::PlotSngValDistr(), TSnap::PlotSngValRank(), TSnap::PlotSngVec(), TCoda::RandomInit(), TKronNoise::RemoveNodeNoise(), TKroneckerLL::RestoreGraph(), TKroneckerLL::RunMStep(), TCoda::SetCmtyVV(), TCoda::SetGraph(), TKroneckerLL::SetGraph(), TMAGFitBern::SetGraph(), TKroneckerLL::SetOrderPerm(), TKroneckerLL::SetRndPerm(), TGraphKey::TakeGraph(), TGraphKey::TakeSig(), TGStat::TakeSpectral(), TGStat::TakeStat(), TCodaAnalyzer::TCodaAnalyzer(), TKroneckerLL::TestBicCriterion(), TKroneckerLL::TestGradDescent(), TKroneckerLL::TestSamplePerm(), and TMAGFitBern::TMAGFitBern().
Returns an interator referring to a random node in the graph.
Definition at line 597 of file graph.h.
References GetNI(), and GetRndNId().
Returns an ID of a random node in the graph.
Definition at line 595 of file graph.h.
References THash< TKey, TDat, THashFunc >::GetKey(), THash< TKey, TDat, THashFunc >::GetRndKeyId(), and NodeH.
Referenced by TNetInfBs::GenCascade(), TSnap::GenCopyModel(), and GetRndNI().
|
static |
Returns a small graph on 5 nodes and 6 edges.
/// Edges: 0 -> 1, 1 -> 2, 0 -> 2, 1 -> 3, 3 -> 4, 2 -> 3 ///
Definition at line 454 of file graph.cpp.
References AddEdge(), AddNode(), and New().
bool TNGraph::HasFlag | ( | const TGraphFlag & | Flag | ) | const |
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
Definition at line 232 of file graph.cpp.
References HasGraphFlag.
bool TNGraph::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 graph.
Definition at line 363 of file graph.cpp.
References GetNode(), IsNode(), and TNGraph::TNode::IsOutNId().
Referenced by AddEdge(), TKroneckerLL::CalcFullApxGraphDLL(), TKroneckerLL::CalcGraphDLL(), TSnap::CascGraphSource(), TSnap::CascGraphTime(), checkEdge(), checkTriadMotif(), TMAGFitBern::ComputeApxAdjLL(), TMAGFitBern::ComputeApxLL(), TMAGFitBern::ComputeJointAdjLL(), TMAGFitBern::ComputeJointOneLL(), ProcessedGraph::countDirTriadMotif(), TSnap::TSnapDetail::edgeIntersect(), MotifCluster::EdgeMotifAdjacency(), TKronNoise::FlipEdgeNoise(), TKronMtx::GenFastKronecker(), TSnap::GenRMat(), TempMotifCounter::GetAllStaticTriangles(), TNetInfBs::GetBestEdge(), TNetInfBs::GetBound(), TCoda::GetNonEdgePairScores(), TMAGFitBern::GradAffMtx(), TNetInfBs::GreedyOpt(), MotifCluster::IsBidirEdge(), TGraphEnumUtils::IsEdge(), MotifCluster::IsNoEdge(), MotifCluster::IsUnidirEdge(), TCoda::LikelihoodHoldOut(), TKroneckerLL::NodeDLLDelta(), TKroneckerLL::NodeLLDelta(), TKroneckerLL::SetRandomEdges(), TKroneckerLL::SwapNodesLL(), MotifCluster::TriangleMotifAdjacency(), TKroneckerLL::UpdateGraphDLL(), TMAGFitBern::UpdatePhi(), and TMAGFitBern::UpdatePhiMI().
|
inline |
Tests whether ID NId is a node.
Definition at line 542 of file graph.h.
References THash< TKey, TDat, THashFunc >::IsKey(), and NodeH.
Referenced by AddEdge(), AddEdge2(), AddNode(), AddNodeUnchecked(), TNGraphMtx::CheckNodeIds(), DelEdge(), TSnap::GetBfsTree(), TSnap::GetEgonet(), TCoda::GetGraphRawNID(), TGraphEnumUtils::GetIndGraph(), TSnap::GetSubGraph(), TBigNet< TNodeData, IsDir >::GetSubNGraph(), TSnap::TSnapDetail::inComp(), TNetInfBs::Init(), IsEdge(), IsOk(), TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), TCodaAnalyzer::Net2ModeCommunities(), TKroneckerLL::NodeDLLDelta(), TKroneckerLL::NodeLLDelta(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TCoda::SetCmtyVV(), TCoda::SetGraph(), TKroneckerLL::SetGraph(), and TMAGFitBern::SetGraph().
bool TNGraph::IsOk | ( | const bool & | ThrowExcept = true | ) | const |
Checks the graph data structure for internal consistency.
For each node in the graph check that its neighbors are also nodes in the graph.
Definition at line 391 of file graph.cpp.
References TStr::CStr(), EAssertR, ErrNotify(), THash< TKey, TDat, THashFunc >::FFirstKeyId(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::FNextKeyId(), TNGraph::TNode::GetId(), TNGraph::TNode::GetInDeg(), TNGraph::TNode::GetInNId(), TNGraph::TNode::GetOutDeg(), TNGraph::TNode::GetOutNId(), TNGraph::TNode::InNIdV, IsNode(), TVec< TVal, TSizeTy >::IsSorted(), NodeH, and TNGraph::TNode::OutNIdV.
Static constructor that loads the graph from a stream SIn and returns a pointer to it.
Definition at line 483 of file graph.h.
References TNGraph().
Referenced by TCoda::Load(), and TKronMomentsFit::Test().
|
inlineprivate |
Definition at line 461 of file graph.h.
References THash< TKey, TDat, THashFunc >::LoadShM(), MxNId, and NodeH.
Referenced by LoadShM().
Static constructor that loads the graph from a shared memory stream and returns pointer to it.
static constructor to load the graph from memory. Cannot perform operations that edit the edge vectors of nodes or perform illegal operations on the NodeH (deletion or swapping keys)
Definition at line 488 of file graph.h.
References LoadGraphShM(), and TNGraph().
|
inlinestatic |
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition at line 477 of file graph.h.
References TNGraph().
Referenced by TSnap::CascGraphSource(), TSnap::CascGraphTime(), TMAGParam< TNodeAttr >::GenAttrMAG(), TSnap::GenCopyModel(), TKronMtx::GenDetKronecker(), TKronMtx::GenFastKronecker(), TKronMtx::GenKronecker(), TSnap::GenRewire(), TSnap::GenRMat(), TKronMtx::GenRndGraph(), TKronMtx::GenThreshGraph(), TSnap::GetBfsTree(), TSnap::GetEgonet(), TD34GraphCounter::GetGraph(), TCoda::GetGraphRawNID(), TNIBs::GetGroundTruthGraphAtT(), TNIBs::GetInferredGraphAtT(), TGraphEnumUtils::GetIsoGraphs(), TGraphKey::GetNGraph(), TBigNet< TNodeData, IsDir >::GetNGraph(), GetSmallGraph(), TSnap::GetSubGraph(), TBigNet< TNodeData, IsDir >::GetSubNGraph(), TNetInfBs::Init(), TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), TNetInfBs::LoadGroundTruthTxt(), main(), TCodaAnalyzer::Net2ModeCommunities(), TDGHashGraphCounter::operator()(), TSnap::ReebRefine(), TSnap::ReebSimplify(), TCoda::TCoda(), and TCodaAnalyzer::TCodaAnalyzer().
|
inlinestatic |
|
inline |
Reserves memory for a graph of Nodes nodes and Edges edges.
Definition at line 606 of file graph.h.
References THash< TKey, TDat, THashFunc >::Gen(), and NodeH.
Referenced by TSnap::GenCopyModel(), TSnap::GenRewire(), TSnap::GenRMat(), TBigNet< TNodeData, IsDir >::GetNGraph(), TSnap::GetSubGraph(), and TNGraph().
|
inline |
Reserves memory for node ID NId having InDeg in-edges.
Definition at line 608 of file graph.h.
References GetNode(), TNGraph::TNode::InNIdV, and TVec< TVal, TSizeTy >::Reserve().
Referenced by TBigNet< TNodeData, IsDir >::GetSubNGraph().
|
inline |
Reserves memory for node ID NId having OutDeg out-edges.
Definition at line 610 of file graph.h.
References GetNode(), TNGraph::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Reserve().
Referenced by TBigNet< TNodeData, IsDir >::GetSubNGraph().
|
inline |
Saves the graph to a (binary) stream SOut.
Definition at line 475 of file graph.h.
References MxNId, NodeH, THash< TKey, TDat, THashFunc >::Save(), and TInt::Save().
Referenced by TCoda::Save().
|
inline |
Sorts the adjacency lists of each node.
Definition at line 612 of file graph.h.
References BegNI(), and EndNI().
|
friend |
|
private |
Definition at line 450 of file graph.h.
Referenced by AddNode(), AddNodeUnchecked(), Clr(), GetMxNId(), LoadGraphShM(), operator=(), and Save().
Definition at line 451 of file graph.h.
Referenced by AddNode(), AddNodeUnchecked(), BegNI(), Clr(), Defrag(), DelNode(), Dump(), EndNI(), GetEdges(), GetNI(), GetNIdV(), GetNode(), GetNodes(), GetRndNId(), IsNode(), IsOk(), LoadGraphShM(), operator=(), TNGraphMtx::PMultiply(), TNGraphMtx::PMultiplyT(), Reserve(), and Save().