12 template <
class PGraph> 
double GetClustCf(
const PGraph& Graph, 
int SampleNodes=-1);
 
   18 template <
class PGraph> 
double GetClustCf(
const PGraph& Graph, 
TFltPrV& DegToCCfV, 
int SampleNodes=-1);
 
   26 template <
class PGraph> 
double GetClustCf(
const PGraph& Graph, 
TFltPrV& DegToCCfV, 
int64& ClosedTriads, 
int64& OpenTriads, 
int SampleNodes=-1);
 
   35 template <
class PGraph> 
double GetClustCfAll(
const PGraph& Graph, 
TFltPrV& DegToCCfV, 
int64& ClosedTriadsX, 
int64& OpenTriadsX, 
int SampleNodes=-1);
 
   39 template <
class PGraph> 
double GetNodeClustCf(
const PGraph& Graph, 
const int& NId);
 
   50 template <
class PGraph> 
int64 GetTriads(
const PGraph& Graph, 
int SampleNodes=-1);
 
   55 template <
class PGraph> 
int64 GetTriads(
const PGraph& Graph, 
int64& ClosedTriadsX, 
int64& OpenTriadsX, 
int SampleNodes);
 
   67 template <
class PGraph> 
void GetTriads(
const PGraph& Graph, 
TIntTrV& NIdCOTriadV, 
int SampleNodes=-1);
 
   72 template <
class PGraph> 
int GetTriadEdges(
const PGraph& Graph, 
int SampleEdges=-1);
 
   79 template <
class PGraph> 
int GetNodeTriads(
const PGraph& Graph, 
const int& NId);
 
   87 template <
class PGraph> 
int GetNodeTriads(
const PGraph& Graph, 
const int& NId, 
int& ClosedNTriadsX, 
int& OpenNTriadsX);
 
   96 template <
class PGraph> 
int GetNodeTriadsAll(
const PGraph& Graph, 
const int& NId, 
int& ClosedNTriadsX, 
int& OpenNTriadsX);
 
  106 template <
class PGraph>
 
  107 int GetNodeTriads(
const PGraph& Graph, 
const int& NId, 
const TIntSet& GroupSet, 
int& InGroupEdgesX, 
int& InOutGroupEdgesX, 
int& OutGroupEdgesX);
 
  114 template<
class PGraph> 
int GetCmnNbrs(
const PGraph& Graph, 
const int& NId1, 
const int& NId2);
 
  116 template<
class PGraph> 
int GetCmnNbrs(
const PGraph& Graph, 
const int& NId1, 
const int& NId2, 
TIntV& NbrV);
 
  118 template<
class PGraph> 
int GetLen2Paths(
const PGraph& Graph, 
const int& NId1, 
const int& NId2);
 
  122 template<
class PGraph> 
int GetLen2Paths(
const PGraph& Graph, 
const int& NId1, 
const int& NId2, 
TIntV& NbrV);
 
  126 template<
class PGraph> 
void MergeNbrs(
TIntV& NeighbourV, 
const typename PGraph::TObj::TNodeI& NI);
 
  129 template <
class PGraph> 
void GetUniqueNbrV(
const PGraph& Graph, 
const int& NId, 
TIntV& NbrV);
 
  137 template <
class PGraph> 
double GetClustCf(
const PGraph& Graph, 
int SampleNodes) {
 
  139   GetTriads(Graph, NIdCOTriadV, SampleNodes);
 
  140   if (NIdCOTriadV.
Empty()) { 
return 0.0; }
 
  142   for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
 
  143     const double OpenCnt = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
 
  145       SumCcf += NIdCOTriadV[i].Val2() / OpenCnt; }
 
  148   return SumCcf / double(NIdCOTriadV.
Len());
 
  151 template <
class PGraph> 
double GetClustCf(
const PGraph& Graph, 
TFltPrV& DegToCCfV, 
int SampleNodes) {
 
  153   GetTriads(Graph, NIdCOTriadV, SampleNodes);
 
  154   if (NIdCOTriadV.
Empty()) {
 
  155     DegToCCfV.
Clr(
false);
 
  160   for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
 
  161     const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
 
  162     const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
 
  163     TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
 
  169   DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
 
  170   for (
int d = 0; d  < DegSumCnt.
Len(); d++) {
 
  171     DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, double(DegSumCnt[d].Val1()/DegSumCnt[d].Val2())));
 
  174   return SumCcf / double(NIdCOTriadV.
Len());
 
  177 template <
class PGraph>
 
  180   GetTriads(Graph, NIdCOTriadV, SampleNodes);
 
  181   if (NIdCOTriadV.
Empty()) {
 
  182     DegToCCfV.
Clr(
false);
 
  189   int64 closedTriads = 0;
 
  190   int64 openTriads = 0;
 
  191   for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
 
  192     const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
 
  193     const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
 
  194     closedTriads += NIdCOTriadV[i].Val2;
 
  195     openTriads += NIdCOTriadV[i].Val3;
 
  196     TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
 
  202   DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
 
  203   for (
int d = 0; d  < DegSumCnt.
Len(); d++) {
 
  204     DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, DegSumCnt[d].Val1()/DegSumCnt[d].Val2()));
 
  208   ClosedTriads = closedTriads/
int64(3); 
 
  209   OpenTriads = openTriads;
 
  211   return SumCcf / double(NIdCOTriadV.
Len());
 
  214 template <
class PGraph>
 
  216   return GetClustCf(Graph, DegToCCfV, ClosedTriads, OpenTriads, SampleNodes);
 
  219 template <
class PGraph>
 
  224   return (Open+Closed)==0 ? 0 : double(Open)/double(Open+Closed);
 
  227 template <
class PGraph>
 
  232   for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
 
  233     const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
 
  234     const double CCf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
 
  235     NIdCCfH.
AddDat(NIdCOTriadV[i].Val1, CCf);
 
  239 template <
class PGraph>
 
  241   int64 OpenTriads, ClosedTriads;
 
  242   return GetTriads(Graph, ClosedTriads, OpenTriads, SampleNodes);
 
  245 template <
class PGraph>
 
  248   GetTriads(Graph, NIdCOTriadV, SampleNodes);
 
  251   for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
 
  252     closedTriads += NIdCOTriadV[i].Val2;
 
  253     openTriads += NIdCOTriadV[i].Val3;
 
  257   ClosedTriads = 
int64(closedTriads/3); 
 
  258   OpenTriads = 
int64(openTriads);
 
  262 template <
class PGraph>
 
  264   return GetTriads(Graph, ClosedTriads, OpenTriads, SampleNodes);
 
  269 template <
class PGraph>
 
  271   const bool IsDir = Graph->HasFlag(
gfDirected);
 
  276   Graph->GetNIdV(NIdV);
 
  278   if (SampleNodes == -1) {
 
  279     SampleNodes = Graph->GetNodes(); }
 
  280   NIdCOTriadV.
Clr(
false);
 
  281   NIdCOTriadV.
Reserve(SampleNodes);
 
  282   for (
int node = 0; node < SampleNodes; node++) {
 
  283     typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
 
  284     if (NI.GetDeg() < 2) {
 
  285       NIdCOTriadV.
Add(
TIntTr(NI.GetId(), 0, 0)); 
 
  290     for (
int e = 0; e < NI.GetOutDeg(); e++) {
 
  291       if (NI.GetOutNId(e) != NI.GetId()) {
 
  292         NbrH.
AddKey(NI.GetOutNId(e)); }
 
  295       for (
int e = 0; e < NI.GetInDeg(); e++) {
 
  296         if (NI.GetInNId(e) != NI.GetId()) {
 
  297           NbrH.
AddKey(NI.GetInNId(e)); }
 
  301     int OpenCnt=0, CloseCnt=0;
 
  302     for (
int srcNbr = 0; srcNbr < NbrH.
Len(); srcNbr++) {
 
  303       const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrH.
GetKey(srcNbr));
 
  304       for (
int dstNbr = srcNbr+1; dstNbr < NbrH.
Len(); dstNbr++) {
 
  305         const int dstNId = NbrH.
GetKey(dstNbr);
 
  306         if (SrcNode.IsNbrNId(dstNId)) { CloseCnt++; } 
 
  311     NIdCOTriadV.
Add(
TIntTr(NI.GetId(), CloseCnt, OpenCnt));
 
  317 template <
class PGraph>
 
  319   const bool IsDir = Graph->HasFlag(
gfDirected);
 
  332   NNodes = Graph->GetNodes();
 
  333   Graph->GetNIdV(NIdV);
 
  335   if (SampleNodes == -1) {
 
  336     SampleNodes = NNodes;
 
  340   for (
int i = 0; i < NNodes; i++) {
 
  341     if (NIdV[i] > MxId) {
 
  350     for (
int node = 0; node < NNodes; node++) {
 
  351       int NId = NIdV[node];
 
  357     for (
int node = 0; node < NNodes; node++) {
 
  358       int NId = NIdV[node];
 
  359       typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
 
  361       NbrV[NId].
Reserve(NI.GetOutDeg());
 
  363       for (
int i = 0; i < NI.GetOutDeg(); i++) {
 
  364         NbrV[NId].
Add(NI.GetOutNId(i));
 
  369   NIdCOTriadV.
Clr(
false);
 
  370   NIdCOTriadV.
Reserve(SampleNodes);
 
  371   for (
int node = 0; node < SampleNodes; node++) {
 
  372     typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
 
  377     if (NI.GetDeg() < 2) {
 
  386     int OpenCnt1 = 0, CloseCnt1 = 0;
 
  387     for (
int srcNbr = 0; srcNbr < NLen; srcNbr++) {
 
  388       int Count = 
GetCommon(NbrV[NbrV[NId][srcNbr]],Nbrs);
 
  392     OpenCnt1 = (NLen*(NLen-1))/2 - CloseCnt1;
 
  393     NIdCOTriadV.
Add(
TIntTr(NId, CloseCnt1, OpenCnt1));
 
  399 template<
class PGraph>
 
  400 int64 CountTriangles(
const PGraph& Graph) {
 
  405   for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++)   {
 
  406     H.
AddDat(NI.GetId(), ind);
 
  407     MapV.
Add(NI.GetId());
 
  414 #pragma omp parallel for schedule(dynamic) 
  416   for (
int i = 0; i < ind; i++) {
 
  417     typename PGraph::TObj::TNodeI NI = Graph->GetNI(MapV[i]);
 
  420     MergeNbrs<PGraph>(NbrV, NI);
 
  423     for (
int j = 0; j < NbrV.Len(); j++) {
 
  425       TInt Deg = Graph->GetNI(Vert).GetDeg();
 
  426       if (Deg > NI.GetDeg() ||
 
  427          (Deg == NI.GetDeg() && Vert > NI.GetId())) {
 
  432     HigherDegNbrV[i] = V;
 
  438 #pragma omp parallel for schedule(dynamic) reduction(+:cnt) 
  440   for (
int i = 0; i < HigherDegNbrV.Len(); i++) {
 
  441     for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
 
  453 template<
class PGraph>
 
  455   const int NNodes = Graph->GetNodes();
 
  463   for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++)   {
 
  475   for (
int j = 0; j < NNodes; j++) {
 
  483   for (
int i = 0; i < ind; i++) {
 
  485     HigherDegNbrV[i].
Reserve(NV[i].GetDeg());
 
  486     HigherDegNbrV[i].
Reduce(0);
 
  490 #pragma omp parallel for schedule(dynamic) 
  492   for (
int i = 0; i < ind; i++) {
 
  493     typename PGraph::TObj::TNodeI NI = NV[i];
 
  494     MergeNbrs<PGraph>(HigherDegNbrV[i], NI);
 
  497     for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
 
  498       TInt Vert = HigherDegNbrV[i][j];
 
  499       TInt Deg = NV[IndV[Vert]].GetDeg();
 
  500       if (Deg > NI.GetDeg() ||
 
  501          (Deg == NI.GetDeg() && Vert > NI.GetId())) {
 
  502         HigherDegNbrV[i][k] = Vert;
 
  506     HigherDegNbrV[i].Reduce(k);
 
  511 #pragma omp parallel for schedule(dynamic) reduction(+:cnt) 
  513   for (
int i = 0; i < HigherDegNbrV.
Len(); i++) {
 
  514     for (
int j = 0; j < HigherDegNbrV[i].
Len(); j++) {
 
  515       TInt NbrInd = IndV[HigherDegNbrV[i][j]];
 
  525 template<
class PGraph>
 
  530   int indeg = NI.GetInDeg();
 
  531   int outdeg = NI.GetOutDeg();
 
  532   if (indeg > 0  &&  outdeg > 0) {
 
  533     int v1 = NI.GetInNId(j);
 
  534     int v2 = NI.GetOutNId(k);
 
  555         v2 = NI.GetOutNId(k);
 
  560     int v = NI.GetInNId(j);
 
  568     int v = NI.GetOutNId(k);
 
  578 template <
class PGraph>
 
  580   const bool IsDir = Graph->HasFlag(
gfDirected);
 
  583   for(
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
 
  585     for (
int e = 0; e < NI.GetOutDeg(); e++) {
 
  586       if (NI.GetOutNId(e) != NI.GetId()) {
 
  587         NbrH.
AddKey(NI.GetOutNId(e)); }
 
  590       for (
int e = 0; e < NI.GetInDeg(); e++) {
 
  591         if (NI.GetInNId(e) != NI.GetId()) {
 
  592           NbrH.
AddKey(NI.GetInNId(e)); }
 
  595     for (
int e = 0; e < NI.GetOutDeg(); e++) {
 
  596       if (!IsDir && NI.GetId()<NI.GetOutNId(e)) { 
continue; } 
 
  597       const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NI.GetOutNId(e));
 
  599       for (
int e1 = 0; e1 < SrcNode.GetOutDeg(); e1++) {
 
  600         if (NbrH.
IsKey(SrcNode.GetOutNId(e1))) { Triad=
true; 
break; }
 
  602       if (IsDir && ! Triad) {
 
  603         for (
int e1 = 0; e1 < SrcNode.GetInDeg(); e1++) {
 
  604           if (NbrH.
IsKey(SrcNode.GetInNId(e1))) { Triad=
true; 
break; }
 
  607       if (Triad) { TriadEdges++; }
 
  614 template <
class PGraph>
 
  616   int ClosedTriads=0, OpenTriads=0;
 
  621 template <
class PGraph>
 
  622 int GetNodeTriads(
const PGraph& Graph, 
const int& NId, 
int& ClosedTriads, 
int& OpenTriads) {
 
  623   const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
 
  624   ClosedTriads=0;  OpenTriads=0;
 
  625   if (NI.GetDeg() < 2) { 
return 0; }
 
  628   for (
int e = 0; e < NI.GetOutDeg(); e++) {
 
  629     if (NI.GetOutNId(e) != NI.GetId()) { 
 
  630       NbrSet.
AddKey(NI.GetOutNId(e)); }
 
  633     for (
int e = 0; e < NI.GetInDeg(); e++) {
 
  634       if (NI.GetInNId(e) != NI.GetId()) { 
 
  635         NbrSet.AddKey(NI.GetInNId(e)); }
 
  639   for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
 
  640     const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrSet.GetKey(srcNbr));
 
  641     for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
 
  642       const int dstNId = NbrSet.GetKey(dstNbr);
 
  643       if (SrcNode.IsNbrNId(dstNId)) { ClosedTriads++; }
 
  644       else { OpenTriads++; }
 
  650 template <
class PGraph>
 
  651 int GetNodeTriadsAll(
const PGraph& Graph, 
const int& NId, 
int& ClosedTriads, 
int& OpenTriads) {
 
  659 template <
class PGraph>
 
  660 int GetNodeTriads(
const PGraph& Graph, 
const int& NId, 
const TIntSet& GroupSet, 
int& InGroupEdges, 
int& InOutGroupEdges, 
int& OutGroupEdges) {
 
  661   const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
 
  662   const bool IsDir = Graph->HasFlag(
gfDirected);
 
  663   InGroupEdges=0;  InOutGroupEdges=0;  OutGroupEdges=0;
 
  664   if (NI.GetDeg() < 2) { 
return 0; }
 
  667   for (
int e = 0; e < NI.GetOutDeg(); e++) {
 
  668     if (NI.GetOutNId(e) != NI.GetId()) { 
 
  669       NbrSet.
AddKey(NI.GetOutNId(e)); }
 
  672     for (
int e = 0; e < NI.GetInDeg(); e++) {
 
  673       if (NI.GetInNId(e) != NI.GetId()) {
 
  674         NbrSet.AddKey(NI.GetInNId(e)); }
 
  678   for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
 
  679     const int NbrId = NbrSet.GetKey(srcNbr);
 
  680     const bool NbrIn = GroupSet.
IsKey(NbrId);
 
  681     const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrId);
 
  682     for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
 
  683       const int DstNId = NbrSet.GetKey(dstNbr);
 
  684       if (SrcNode.IsNbrNId(DstNId)) { 
 
  685         bool DstIn = GroupSet.
IsKey(DstNId);
 
  686         if (NbrIn && DstIn) { InGroupEdges++; }
 
  687         else if (NbrIn || DstIn) { InOutGroupEdges++; }
 
  688         else { OutGroupEdges++; }
 
  696 template <
class PGraph>
 
  699   for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
 
  701     TriadCntH.
AddDat(Triads) += 1;
 
  707 template<
class PGraph>
 
  708 int GetCmnNbrs(
const PGraph& Graph, 
const int& NId1, 
const int& NId2) {
 
  714 template<
class PGraph>
 
  716   if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.
Clr(
false); 
return 0; }
 
  717   typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
 
  718   typename PGraph::TObj::TNodeI NI2 = Graph->GetNI(NId2);
 
  721   TIntSet NSet1(NI1.GetDeg()), NSet2(NI2.GetDeg());
 
  722   for (
int i = 0; i < NI1.GetDeg(); i++) {
 
  723     const int nid = NI1.GetNbrNId(i);
 
  724     if (nid!=NId1 && nid!=NId2) {
 
  727   for (
int i = 0; i < NI2.GetDeg(); i++) {
 
  728     const int nid = NI2.GetNbrNId(i);
 
  729     if (NSet1.IsKey(nid)) {
 
  739   if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.Clr(
false); 
return 0; }
 
  748     if (j < NI2.
GetDeg() && nid==NI2.
GetNbrNId(j) && nid!=NId1 && nid!=NId2) {
 
  749       IAssert(NbrV.Empty() || NbrV.Last() < nid);
 
  760 template<
class PGraph>
 
  761 int GetLen2Paths(
const PGraph& Graph, 
const int& NId1, 
const int& NId2) {
 
  768 template<
class PGraph>
 
  770   const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId1);
 
  773   for (
int e = 0; e < NI.GetOutDeg(); e++) {
 
  774     const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(NI.GetOutNId(e));
 
  775     if (MidNI.IsOutNId(NId2)) {
 
  776       NbrV.
Add(MidNI.GetId());
 
  782 template <
class PGraph>
 
  784   typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
 
  791   int InDeg = NI.GetInDeg();
 
  792   int OutDeg = NI.GetOutDeg();
 
  793   if (InDeg > 0  &&  OutDeg > 0) {
 
  794     int v1 = NI.GetInNId(j);
 
  795     int v2 = NI.GetOutNId(k);
 
  820         v2 = NI.GetOutNId(k);
 
  825     int v = NI.GetInNId(j);
 
  835     int v = NI.GetOutNId(k);
 
  851 template <
class PGraph>
 
  858   int Len()
 const { 
return NodePrCH.
Len(); }
 
  859   double GetC(
const int& ConstraintN)
 const { 
return NodePrCH[ConstraintN]; }
 
  861   double GetEdgeC(
const int& NId1, 
const int& NId2) 
const;
 
  862   double GetNodeC(
const int& NId) 
const;
 
  870 template <
class PGraph>
 
  878 template <
class PGraph>
 
  880   if (NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
 
  881     return NodePrCH.GetDat(
TIntPr(NId1, NId2)); }
 
  886 template <
class PGraph>
 
  888   typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
 
  889   if (NI1.GetOutDeg() == 0) { 
return 0.0; }
 
  891   for (
int k = 0; k<NI1.GetOutDeg(); k++) {
 
  892     KeyId = NodePrCH.GetKeyId(
TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
 
  893     if (KeyId > -1) { 
break; }
 
  895   if (KeyId < 0) { 
return 0.0; }
 
  896   double Constraint = NodePrCH[KeyId];
 
  897   for (
int i = KeyId-1; i >-1 && NodePrCH.GetKey(i).Val1()==NId; i--) {
 
  898     Constraint += NodePrCH[i];
 
  900   for (
int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
 
  901     Constraint += NodePrCH[i];
 
  906 template <
class PGraph>
 
  908   if (NId1==NId2 || NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
 
  911   typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
 
  912   double Constraint = 0.0;
 
  913   if (NI1.IsOutNId(NId2)) { 
 
  914     Constraint += 1.0/(double) NI1.GetOutDeg();
 
  916   const double SrcC = 1.0/(double) NI1.GetOutDeg();
 
  917   for (
int e = 0; e < NI1.GetOutDeg(); e++) {
 
  918     const int MidNId = NI1.GetOutNId(e);
 
  919     if (MidNId == NId1 || MidNId == NId2) { 
continue; }
 
  920     const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(MidNId);
 
  921     if (MidNI.IsOutNId(NId2)) {
 
  922       Constraint += SrcC * (1.0/(double)MidNI.GetOutDeg());
 
  925   if (Constraint==0) { 
return; }
 
  927   NodePrCH.AddDat(
TIntPr(NId1, NId2), Constraint);
 
  930 template <
class PGraph>
 
  933   for (
typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
 
  934     AddConstraint(EI.GetSrcNId(), EI.GetDstNId());
 
  935     AddConstraint(EI.GetDstNId(), EI.GetSrcNId());
 
  938   for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
 
  939     for (
int i = 0; i < NI.GetDeg();  i++) {
 
  940       const int NId1 = NI.GetNbrNId(i);
 
  941       for (
int j = 0; j < NI.GetDeg();  j++) {
 
  942         const int NId2 = NI.GetNbrNId(j);
 
  943         AddConstraint(NId1, NId2);
 
  947   NodePrCH.SortByKey();
 
  951 template <
class PGraph>
 
  953   typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
 
  955   for (
int e = 0; e < StartNI.GetOutDeg(); e++) {
 
  956     typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(StartNI.GetOutNId(e));
 
  957     AddConstraint(NId, MidNI.GetId());
 
  958     for (
int i = 0; i < MidNI.GetOutDeg();  i++) {
 
  959       const int EndNId = MidNI.GetOutNId(i);
 
  960       if (! SeenSet.
IsKey(EndNId)) {
 
  961         AddConstraint(NId, EndNId);
 
  968 template <
class PGraph>
 
  970   printf(
"Edge network constraint: (%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
 
  971   for (
int e = 0; e < NodePrCH.Len(); e++) {
 
  972     printf(
"  %4d %4d  :  %f\n", NodePrCH.GetKey(e).Val1(), NodePrCH.GetKey(e).Val2(), NodePrCH[e].Val);
 
  979 template <
class PGraph>
 
  989   NetConstraint.
Dump();
 
  990   printf(
"middle node network constraint: %f\n", NetConstraint.
GetNodeC(0));
 
void Clr(const bool &DoDel=true, const int &NoDelLim=-1)
 
static const T & Mn(const T &LVal, const T &RVal)
 
void GetUniqueNbrV(const PGraph &Graph, const int &NId, TIntV &NbrV)
Returns sorted vector NbrV containing unique in or out neighbors of node NId in graph Graph...
 
TPair< TInt, TInt > TIntPr
 
Main namespace for all the Snap global entities. 
 
int64 GetTriads(const PGraph &Graph, int64 &ClosedTriads, int64 &OpenTriads, int SampleNodes=-1)
Computes the number of Closed and Open triads. 
 
int64 GetTriangleCnt(const PGraph &Graph)
Returns the number of triangles in graph Graph. 
 
double GetNodeClustCf(const PGraph &Graph, const int &NId)
Returns clustering coefficient of a particular node. 
 
int GetLen2Paths(const PGraph &Graph, const int &NId1, const int &NId2)
Returns the number of length 2 directed paths between a pair of nodes NId1, NId2 (NId1 –> U –> NId2...
 
int AddNode(int NId=-1)
Adds a node of ID NId to the graph. 
 
TSizeTy Len() const 
Returns the number of elements in the vector. 
 
Node iterator. Only forward iteration (operator++) is supported. 
 
int GetCmnNbrs< PUNGraph >(const PUNGraph &Graph, const int &NId1, const int &NId2, TIntV &NbrV)
 
void MergeNbrs(TIntV &NeighbourV, const typename PGraph::TObj::TNodeI &NI)
Merges neighbors by removing duplicates and produces one sorted vector of neighbors. 
 
const TDat & GetDat(const TKey &Key) const 
 
static double Sqr(const double &x)
 
TNetConstraint(const PGraph &GraphPt, const bool &CalcaAll=true)
 
void Reduce(const TSizeTy &_Vals=-1)
Reduces the vector's length to _Vals elements, which must be less than the current length...
 
bool IsKey(const TKey &Key) const 
 
const TKey & GetKey(const int &KeyId) const 
 
bool Empty() const 
Tests whether the vector is empty. 
 
have explicit edges (multigraph): TNEGraph, TNodeEdgeNet 
 
int GetDeg() const 
Returns degree of the current node. 
 
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. 
 
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
 
unsigned long long uint64
 
void GetTriads_v0(const PGraph &Graph, TIntTrV &NIdCOTriadV, int SampleNodes)
 
void AddConstraint(const int &NId1, const int &NId2)
 
int GetNodeTriadsAll(const PGraph &Graph, const int &NId, int &ClosedNTriadsX, int &OpenNTriadsX)
Returns number of Open and Closed triads a node NId participates in. 
 
double GetNodeC(const int &NId) const 
 
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New(). 
 
int AddKey(const TKey &Key)
 
int GetNodeTriads(const PGraph &Graph, const int &NId)
Returns the number of undirected triads a node NId participates in. 
 
double GetClustCfAll(const PGraph &Graph, TFltPrV &DegToCCfV, int64 &ClosedTriadsX, int64 &OpenTriadsX, int SampleNodes=-1)
Computes the distribution of average clustering coefficient as well as the number of open and closed ...
 
int64 GetTriadsAll(const PGraph &Graph, int64 &ClosedTriadsX, int64 &OpenTriadsX, int SampleNodes=-1)
Computes the number of Closed and Open triads. 
 
double GetC(const int &ConstraintN) const 
 
TPair< TFlt, TFlt > TFltPr
 
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph. 
 
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph 
 
double GetEdgeC(const int &NId1, const int &NId2) const 
 
int GetTriadEdges(const PGraph &Graph, int SampleEdges=-1)
Counts the number of edges that participate in at least one triad. 
 
int GetCommon(TIntV &A, TIntV &B)
Returns the number of common elements in two sorted TInt vectors. 
 
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector. 
 
void GetTriadParticip(const PGraph &Graph, TIntPrV &TriadCntV)
Triangle Participation Ratio: For each node counts how many triangles it participates in and then ret...
 
void GetKeyDatPrV(TVec< TPair< TKey, TDat > > &KeyDatPrV) const 
 
double GetClustCf(const PGraph &Graph, int SampleNodes=-1)
Computes the average clustering coefficient as defined in Watts and Strogatz, Collective dynamics of ...
 
int GetNbrNId(const int &NodeN) const 
Returns ID of NodeN-th neighboring node. 
 
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
 
TIntPr GetNodePr(const int &ConstraintN) const 
 
TTriple< TInt, TInt, TInt > TIntTr
 
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements. 
 
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements. 
 
THash< TIntPr, TFlt > NodePrCH
 
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element. 
 
TDat & AddDat(const TKey &Key)
 
int GetCmnNbrs(const PGraph &Graph, const int &NId1, const int &NId2)
Returns a number of shared neighbors between a pair of nodes NId1 and NId2. 
 
const TKey & GetKey(const int &KeyId) const 
 
Vector is a sequence TVal objects representing an array that can change in size.