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
|
Bipartite graph. More...
#include <graph.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 | |
enum | TNodeTy { bgsUndef, bgsLeft, bgsRight, bgsBoth } |
typedef TBPGraph | TNet |
typedef TPt< TBPGraph > | PNet |
Public Member Functions | |
TBPGraph () | |
TBPGraph (const int &Nodes, const int &Edges) | |
Constructor that reserves enough memory for a graph of Nodes (LeftNodes+RightNodes) nodes and Edges edges. More... | |
TBPGraph (const TBPGraph &BPGraph) | |
!! Reserve(Nodes, Edges); } More... | |
TBPGraph (TSIn &SIn) | |
Constructor for loading 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... | |
TBPGraph & | operator= (const TBPGraph &BPGraph) |
int | GetNodes () const |
Returns the total number of nodes in the graph. More... | |
int | GetLNodes () const |
Returns the number of nodes on the 'left' side of the biparite graph. More... | |
int | GetRNodes () const |
Returns the number of nodes on the 'right' side of the biparite graph. More... | |
int | AddNode (int NId=-1, const bool &LeftNode=true) |
Adds a node of ID NId to the graph. More... | |
int | AddNode (const TNodeI &NodeI) |
Adds a node of ID NodeI.GetId() to the graph. 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... | |
bool | IsLNode (const int &NId) const |
Tests whether ID NId is a 'left' side node. More... | |
bool | IsRNode (const int &NId) const |
Tests whether ID NId is a 'right' side node. More... | |
int | GetMxNId () const |
Returns an ID that is larger than any node ID in the graph. 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... | |
TNodeI | BegLNI () const |
Returns an iterator referring to the first 'left' node in the graph. More... | |
TNodeI | EndLNI () const |
Returns an iterator referring to the past-the-end 'left' node in the graph. More... | |
TNodeI | BegRNI () const |
Returns an iterator referring to the first 'right' node in the graph. More... | |
TNodeI | EndRNI () const |
Returns an iterator referring to the past-the-end 'right' node in the graph. More... | |
int | GetEdges () const |
Returns the number of edges in the graph. More... | |
int | AddEdge (const int &LeftNId, const int &RightNId) |
Adds an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph. More... | |
int | AddEdge (const TEdgeI &EdgeI) |
Adds an edge between EdgeI.GetLNId() and EdgeI.GetRNId() to the graph. More... | |
void | DelEdge (const int &LeftNId, const int &RightNId) |
Deletes an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph. More... | |
bool | IsEdge (const int &LeftNId, const int &RightNId) const |
Tests whether an edge between node IDs LeftNId and RightNId 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 &LeftNId, const int &RightNId) const |
Returns an iterator referring to edge (LeftNId, RightNId) in the graph. More... | |
int | GetRndNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random node in the graph. More... | |
int | GetRndLNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random 'left' node in the graph. More... | |
int | GetRndRNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random 'right' 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 bipartite graph. More... | |
void | GetLNIdV (TIntV &NIdV) const |
Gets a vector IDs of all 'left' nodes in the bipartite graph. More... | |
void | GetRNIdV (TIntV &NIdV) const |
Gets a vector IDs of all 'right' nodes in the bipartite graph. More... | |
bool | Empty () const |
Tests whether the bipartite graph is empty (has zero nodes). More... | |
void | Clr () |
Deletes all nodes and edges from the bipartite graph. More... | |
void | Reserve (const int &Nodes, const int &Edges) |
Reserves memory for a biparite graph of Nodes nodes and Edges edges. More... | |
void | Defrag (const bool &OnlyNodeLinks=false) |
Defragments the biparite graph. More... | |
bool | IsOk (const bool &ThrowExcept=true) const |
Checks the bipartite graph data structure for internal consistency. More... | |
void | Dump (FILE *OutF=stdout) const |
Print the biparite graph in a human readable form to an output stream OutF. More... | |
Static Public Member Functions | |
static PBPGraph | New () |
Static constructor that returns a pointer to the graph. Call: PBPGraph BPGraph = TBPGraph::New();. More... | |
static PBPGraph | 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 PBPGraph | Load (TSIn &SIn) |
Static constructor that loads the graph from a stream SIn and returns a pointer to it. More... | |
static PBPGraph | GetSmallGraph () |
Returns a small graph on 2 'left', 3 'right' nodes and 4 edges. More... | |
Private Attributes | |
TCRef | CRef |
TInt | MxNId |
THash< TInt, TNode > | LeftH |
THash< TInt, TNode > | RightH |
Friends | |
class | TPt< TBPGraph > |
typedef TPt<TBPGraph> TBPGraph::PNet |
typedef TBPGraph TBPGraph::TNet |
enum TBPGraph::TNodeTy |
Enumerator | |
---|---|
bgsUndef | |
bgsLeft | |
bgsRight | |
bgsBoth |
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
int TBPGraph::AddEdge | ( | const int & | LeftNId, |
const int & | RightNId | ||
) |
Adds an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph.
Definition at line 705 of file graph.cpp.
References TStr::Fmt(), and IAssertR.
Referenced by TSnap::GenRewire().
|
inline |
Adds an edge between EdgeI.GetLNId() and EdgeI.GetRNId() to the graph.
Definition at line 1119 of file graph.h.
References AddEdge(), TBPGraph::TEdgeI::GetDstNId(), and TBPGraph::TEdgeI::GetSrcNId().
Referenced by AddEdge().
int TBPGraph::AddNode | ( | int | NId = -1 , |
const bool & | LeftNode = true |
||
) |
Adds a node of ID NId to the graph.
Definition at line 671 of file graph.cpp.
References TStr::Fmt(), IAssertR, TMath::Mx(), and TNEGraph::MxNId.
Referenced by TSnap::GenRewire().
|
inline |
Adds a node of ID NodeI.GetId() to the graph.
Definition at line 1083 of file graph.h.
References AddNode(), TBPGraph::TNodeI::GetId(), and TBPGraph::TNodeI::IsLeft().
Referenced by AddNode().
|
inline |
Returns an iterator referring to the first edge in the graph.
Definition at line 1126 of file graph.h.
References BegLNI(), EndLNI(), TBPGraph::TNodeI::GetId(), TBPGraph::TNodeI::GetOutDeg(), and TBPGraph::TNodeI::GetOutNId().
|
inline |
Returns an iterator referring to the first 'left' node in the graph.
Definition at line 1105 of file graph.h.
References THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
Referenced by BegEI().
|
inline |
Returns an iterator referring to the first node in the graph.
Definition at line 1099 of file graph.h.
References THash< TKey, TDat, THashFunc >::BegI().
|
inline |
Returns an iterator referring to the first 'right' node in the graph.
Definition at line 1109 of file graph.h.
References THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
|
inline |
Deletes all nodes and edges from the bipartite graph.
Definition at line 1153 of file graph.h.
References THash< TKey, TDat, THashFunc >::Clr().
void TBPGraph::Defrag | ( | const bool & | OnlyNodeLinks = false | ) |
void TBPGraph::DelEdge | ( | const int & | LeftNId, |
const int & | RightNId | ||
) |
Deletes an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph.
Definition at line 719 of file graph.cpp.
References TVec< TVal, TSizeTy >::Del(), TStr::Fmt(), TVec< TVal, TSizeTy >::GetDat(), IAssertR, and TVec< TVal, TSizeTy >::SearchBin().
void TBPGraph::DelNode | ( | const int & | NId | ) |
Deletes node of ID NId from the graph.
Definition at line 682 of file graph.cpp.
References AssertR, TVec< TVal, TSizeTy >::Del(), THash< TKey, TDat, THashFunc >::DelKey(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::GetDat(), TBPGraph::TNode::GetOutDeg(), TBPGraph::TNode::GetOutNId(), IAssert, IAssertR, TNEGraph::IsNode(), TBPGraph::TNode::NIdV, and TVec< TVal, TSizeTy >::SearchBin().
|
inline |
Deletes node of ID NodeI.GetId() from the graph.
Definition at line 1088 of file graph.h.
References DelNode(), and TBPGraph::TNode::GetId().
Referenced by DelNode().
void TBPGraph::Dump | ( | FILE * | OutF = stdout | ) | const |
Print the biparite graph in a human readable form to an output stream OutF.
Definition at line 845 of file graph.cpp.
References edge, TBPGraph::TNode::GetDeg(), TNEGraph::GetEdges(), TBPGraph::TNode::GetId(), TBPGraph::TNode::GetNbrNId(), and TNEGraph::GetNodes().
|
inline |
Tests whether the bipartite graph is empty (has zero nodes).
Definition at line 1151 of file graph.h.
References GetNodes().
|
inline |
Returns an iterator referring to the past-the-end edge in the graph.
Definition at line 1128 of file graph.h.
References EndNI().
|
inline |
Returns an iterator referring to the past-the-end 'left' node in the graph.
Definition at line 1107 of file graph.h.
References EndNI().
Referenced by BegEI().
|
inline |
|
inline |
Returns an iterator referring to the past-the-end 'right' node in the graph.
Definition at line 1111 of file graph.h.
References EndNI().
int TBPGraph::GetEdges | ( | ) | const |
TEdgeI TBPGraph::GetEI | ( | const int & | EId | ) | const |
Not supported/implemented!
TBPGraph::TEdgeI TBPGraph::GetEI | ( | const int & | LeftNId, |
const int & | RightNId | ||
) | const |
Returns an iterator referring to edge (LeftNId, RightNId) in the graph.
Definition at line 740 of file graph.cpp.
References TNEGraph::EndNI(), TStr::Fmt(), TNEGraph::GetNI(), IAssertR, and TBPGraph::TNodeI::LeftHI.
void TBPGraph::GetLNIdV | ( | TIntV & | NIdV | ) | const |
Gets a vector IDs of all 'left' nodes in the bipartite graph.
Definition at line 778 of file graph.cpp.
References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Gen().
|
inline |
Returns the number of nodes on the 'left' side of the biparite graph.
Definition at line 1076 of file graph.h.
References THash< TKey, TDat, THashFunc >::Len().
Referenced by GetNodes().
|
inline |
|
inline |
Returns an iterator referring to the node of ID NId in the graph.
Definition at line 1103 of file graph.h.
References THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::GetI(), and IsLNode().
Referenced by GetRndNI().
void TBPGraph::GetNIdV | ( | TIntV & | NIdV | ) | const |
Gets a vector IDs of all nodes in the bipartite graph.
Definition at line 770 of file graph.cpp.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), and TNEGraph::GetNodes().
|
inline |
Returns the total number of nodes in the graph.
Definition at line 1074 of file graph.h.
References GetLNodes(), and GetRNodes().
Referenced by Empty().
Returns an ID of a random 'left' node in the graph.
Definition at line 762 of file graph.cpp.
Returns an interator referring to a random node in the graph.
Definition at line 1142 of file graph.h.
References GetNI(), and GetRndNId().
Returns an ID of a random node in the graph.
Definition at line 754 of file graph.cpp.
References TNEGraph::GetNodes(), and TRnd::GetUniDevInt().
Referenced by GetRndNI().
Returns an ID of a random 'right' node in the graph.
Definition at line 766 of file graph.cpp.
void TBPGraph::GetRNIdV | ( | TIntV & | NIdV | ) | const |
Gets a vector IDs of all 'right' nodes in the bipartite graph.
Definition at line 784 of file graph.cpp.
References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Gen().
|
inline |
Returns the number of nodes on the 'right' side of the biparite graph.
Definition at line 1078 of file graph.h.
References THash< TKey, TDat, THashFunc >::Len().
Referenced by GetNodes().
|
static |
Returns a small graph on 2 'left', 3 'right' nodes and 4 edges.
Definition at line 868 of file graph.cpp.
References New().
bool TBPGraph::HasFlag | ( | const TGraphFlag & | Flag | ) | const |
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
bool TBPGraph::IsEdge | ( | const int & | LeftNId, |
const int & | RightNId | ||
) | const |
Tests whether an edge between node IDs LeftNId and RightNId exists in the graph.
Definition at line 735 of file graph.cpp.
References TNEGraph::IsNode().
|
inline |
Tests whether ID NId is a 'left' side node.
Definition at line 1092 of file graph.h.
References THash< TKey, TDat, THashFunc >::IsKey().
Referenced by GetNI(), and IsNode().
|
inline |
Tests whether ID NId is a node.
Definition at line 1090 of file graph.h.
References IsLNode(), and IsRNode().
bool TBPGraph::IsOk | ( | const bool & | ThrowExcept = true | ) | const |
Checks the bipartite graph data structure for internal consistency.
Definition at line 803 of file graph.cpp.
References TStr::CStr(), EAssertR, ErrNotify(), and TStr::Fmt().
|
inline |
Tests whether ID NId is a 'right' side node.
Definition at line 1094 of file graph.h.
References THash< TKey, TDat, THashFunc >::IsKey().
Referenced by IsNode().
Static constructor that loads the graph from a stream SIn and returns a pointer to it.
Definition at line 1067 of file graph.h.
References TBPGraph().
|
inlinestatic |
Static constructor that returns a pointer to the graph. Call: PBPGraph BPGraph = TBPGraph::New();.
Definition at line 1062 of file graph.h.
References TBPGraph().
Referenced by TSnap::GenRewire(), TSnap::GenRndBipart(), and GetSmallGraph().
|
inlinestatic |
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and Edges edges.
Definition at line 1065 of file graph.h.
References TBPGraph().
void TBPGraph::Reserve | ( | const int & | Nodes, |
const int & | Edges | ||
) |
Reserves memory for a biparite graph of Nodes nodes and Edges edges.
Definition at line 790 of file graph.cpp.
Referenced by TSnap::GenRewire().
|
inline |
Saves the graph to a (binary) stream SOut.
Definition at line 1060 of file graph.h.
References THash< TKey, TDat, THashFunc >::Save(), and TInt::Save().
Definition at line 1047 of file graph.h.
Referenced by operator=().
|
private |
Definition at line 1046 of file graph.h.
Referenced by GetMxNId(), and operator=().
Definition at line 1048 of file graph.h.
Referenced by operator=().