4 if (! Desc.
Empty()) { printf(
"%s:\n", Desc.
CStr()); }
5 for (
int cc = 0; cc < CnComV.
Len(); cc++) {
7 printf(
"%d : ", NIdV.
Len());
8 for (
int i = 0; i < NIdV.
Len(); i++) { printf(
" %d", NIdV[i].Val); }
14 FILE *F = fopen(FNm.
CStr(),
"wt");
15 if (! Desc.
Empty()) { fprintf(F,
"# %s\n", Desc.
CStr()); }
16 fprintf(F,
"# Connected Components:\t%d\n", CnComV.
Len());
17 fprintf(F,
"# Connected components (format: <Size>\\t<NodeId1>\\t<NodeId2>...)\n");
18 for (
int cc = 0; cc < CnComV.
Len(); cc++) {
20 fprintf(F,
"%d", NIdV.
Len());
21 for (
int i = 0; i < NIdV.
Len(); i++) { fprintf(F,
"\t%d", NIdV[i].Val); }
35 for (
int c =0; c < BiCnComV.
Len(); c++) {
36 SzCntH.
AddDat(BiCnComV[c].Len()) += 1;
45 BiCnComV = Visitor.CnComV;
51 Visitor.ArtSet.GetKeyV(ArtNIdV);
59 for (
int c = 0; c < BiCnComV.
Len(); c++) {
60 const TIntV& NIdV = BiCnComV[c].NIdV;
61 if (NIdV.
Len() == 2) {
74 if (EdgeV.
Empty()) { SzCntV.
Clr(
false);
return; }
77 for (
int e = 0; e < EdgeV.
Len(); e++) {
78 TmpG->
DelEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
81 const TIntV& MxWcc = CnComV[0].NIdV;
83 for (
int i = 0; i < MxWcc.Len(); i++) {
84 MxCcSet.
AddKey(MxWcc[i]); }
86 for (
int e = 0; e < EdgeV.
Len(); e++) {
87 if (! MxCcSet.IsKey(EdgeV[e].Val1) && ! MxCcSet.IsKey(EdgeV[e].Val2)) {
88 TmpG->
AddEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
91 for (
int c = 0; c < SzCntV.
Len(); c++) {
92 if (SzCntV[c].Val1 == MxCcSet.
Len()) {
93 SzCntV.
Del(c);
break; }
102 if (EdgeV.
Empty()) { Cn1ComV.
Clr(
false);
return; }
105 for (
int e = 0; e < EdgeV.
Len(); e++) {
106 TmpG->
DelEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
109 const TIntV& MxWcc = CnComV[0].NIdV;
111 for (
int i = 0; i < MxWcc.Len(); i++) {
112 MxCcSet.
AddKey(MxWcc[i]); }
114 for (
int e = 0; e < EdgeV.
Len(); e++) {
115 if (! MxCcSet.IsKey(EdgeV[e].Val1) && ! MxCcSet.IsKey(EdgeV[e].Val2)) {
116 TmpG->
AddEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
120 for (
int c = 0; c < Cn1ComV.
Len(); c++) {
121 if (MxCcSet.IsKey(Cn1ComV[c].NIdV[0])) {
122 Cn1ComV.
Del(c);
break; }
129 if (CnComV.
Empty()) {
132 int CcId = 0, MxSz = 0;
133 for (
int i = 0; i < CnComV.
Len(); i++) {
134 if (MxSz < CnComV[i].Len()) {
135 MxSz = CnComV[i].
Len();
static void Dump(const TCnComV &CnComV, const TStr &Desc=TStr())
static const T & Mn(const T &LVal, const T &RVal)
TPair< TInt, TInt > TIntPr
Main namespace for all the Snap global entities.
PUNGraph GetMxBiCon(const PUNGraph &Graph, const bool &RenumberNodes)
Returns a graph representing the largest bi-connected component on an undirected Graph.
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
static const T & Mx(const T &LVal, const T &RVal)
void GetArtPoints(const PUNGraph &Graph, TIntV &ArtNIdV)
Returns articulation points of a Graph.
TSizeTy Len() const
Returns the number of elements in the vector.
void GetKeyV(TVec< TKey > &KeyV) const
void GetBiConSzCnt(const PUNGraph &Graph, TIntPrV &SzCntV)
Returns a distribution of bi-connected component sizes.
int GetNodes() const
Returns the number of nodes in the graph.
bool Empty() const
Tests whether the vector is empty.
static void GetDfsVisitor(const PGraph &Graph, TVisitor &Visitor)
Biconnected componetns Depth-First-Search visitor class.
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
PUNGraph GetSubGraph(const PUNGraph &Graph, const TIntV &NIdV, const bool &RenumberNodes)
Returns an induced subgraph of an undirected graph Graph with NIdV nodes with an optional node renumb...
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New().
int AddKey(const TKey &Key)
void DelEdge(const int &SrcNId, const int &DstNId)
Deletes an edge between node IDs SrcNId and DstNId from the graph.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
void Get1CnCom(const PUNGraph &Graph, TCnComV &Cn1ComV)
Returns 1-components: maximal connected components of that can be disconnected from the Graph by remo...
void Get1CnComSzCnt(const PUNGraph &Graph, TIntPrV &SzCntV)
Distribution of sizes of 1-components, maximal number of components that can be disconnected from the...
void GetBiCon(const PUNGraph &Graph, TCnComV &BiCnComV)
Returns all bi-connected components of a Graph.
void GetEdgeBridges(const PUNGraph &Graph, TIntPrV &EdgeV)
Returns bridge edges of a Graph.
Articulation point Depth-First-Search visitor class.
void GetKeyDatPrV(TVec< TPair< TKey, TDat > > &KeyDatPrV) const
TDat & AddDat(const TKey &Key)
void GetWccSzCnt(const PGraph &Graph, TIntPrV &WccSzCnt)
Returns a distribution of weakly connected component sizes.
void GetWccs(const PGraph &Graph, TCnComV &CnComV)
Returns all weakly connected components in a Graph.
static void SaveTxt(const TCnComV &CnComV, const TStr &FNm, const TStr &Desc=TStr())
TPt< TUNGraph > PUNGraph
Pointer to an undirected graph (TUNGraph)