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);
24 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
TFltPrV& DegToCCfV,
int64& ClosedTriadsX,
int64& OpenTriadsX,
int SampleNodes=-1);
31 template <
class PGraph>
double GetClustCfAll(
const PGraph& Graph,
TFltPrV& DegToCCfV,
int64& ClosedTriadsX,
int64& OpenTriadsX,
int SampleNodes=-1);
35 template <
class PGraph>
double GetNodeClustCf(
const PGraph& Graph,
const int& NId);
48 template <
class PGraph>
int64 GetTriads(
const PGraph& Graph,
int SampleNodes=-1);
53 template <
class PGraph>
int64 GetTriads(
const PGraph& Graph,
int64& ClosedTriadsX,
int64& OpenTriadsX,
int SampleNodes);
65 template <
class PGraph>
void GetTriads(
const PGraph& Graph,
TIntTrV& NIdCOTriadV,
int SampleNodes=-1);
70 template <
class PGraph>
int GetTriadEdges(
const PGraph& Graph,
int SampleEdges=-1);
77 template <
class PGraph>
int GetNodeTriads(
const PGraph& Graph,
const int& NId);
85 template <
class PGraph>
int GetNodeTriads(
const PGraph& Graph,
const int& NId,
int& ClosedNTriadsX,
int& OpenNTriadsX);
94 template <
class PGraph>
int GetNodeTriadsAll(
const PGraph& Graph,
const int& NId,
int& ClosedNTriadsX,
int& OpenNTriadsX);
104 template <
class PGraph>
105 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
const TIntSet& GroupSet,
int& InGroupEdgesX,
int& InOutGroupEdgesX,
int& OutGroupEdgesX);
112 template<
class PGraph>
int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2);
114 template<
class PGraph>
int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2,
TIntV& NbrV);
116 template<
class PGraph>
int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2);
120 template<
class PGraph>
int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2,
TIntV& NbrV);
124 template<
class PGraph>
void MergeNbrs(
TIntV& NeighbourV,
const typename PGraph::TObj::TNodeI& NI);
127 template <
class PGraph>
void GetUniqueNbrV(
const PGraph& Graph,
const int& NId,
TIntV& NbrV);
135 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
int SampleNodes) {
137 GetTriads(Graph, NIdCOTriadV, SampleNodes);
138 if (NIdCOTriadV.
Empty()) {
return 0.0; }
140 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
141 const double OpenCnt = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
143 SumCcf += NIdCOTriadV[i].Val2() / OpenCnt; }
146 return SumCcf / double(NIdCOTriadV.
Len());
149 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
TFltPrV& DegToCCfV,
int SampleNodes) {
151 GetTriads(Graph, NIdCOTriadV, SampleNodes);
154 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
155 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
156 const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
157 TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
163 DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
164 for (
int d = 0; d < DegSumCnt.
Len(); d++) {
165 DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, double(DegSumCnt[d].Val1()/DegSumCnt[d].Val2())));
168 return SumCcf / double(NIdCOTriadV.
Len());
171 template <
class PGraph>
174 GetTriads(Graph, NIdCOTriadV, SampleNodes);
177 int64 closedTriads = 0;
178 int64 openTriads = 0;
179 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
180 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
181 const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
182 closedTriads += NIdCOTriadV[i].Val2;
183 openTriads += NIdCOTriadV[i].Val3;
184 TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
190 DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
191 for (
int d = 0; d < DegSumCnt.
Len(); d++) {
192 DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, DegSumCnt[d].Val1()/DegSumCnt[d].Val2()));
196 ClosedTriads = closedTriads/
int64(3);
197 OpenTriads = openTriads;
199 return SumCcf / double(NIdCOTriadV.
Len());
202 template <
class PGraph>
204 return GetClustCf(Graph, DegToCCfV, ClosedTriads, OpenTriads, SampleNodes);
207 template <
class PGraph>
212 return (Open+Closed)==0 ? 0 : double(Open)/double(Open+Closed);
215 template <
class PGraph>
220 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
221 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
222 const double CCf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
223 NIdCCfH.
AddDat(NIdCOTriadV[i].Val1, CCf);
227 template <
class PGraph>
229 int64 OpenTriads, ClosedTriads;
230 return GetTriads(Graph, ClosedTriads, OpenTriads, SampleNodes);
233 template <
class PGraph>
236 GetTriads(Graph, NIdCOTriadV, SampleNodes);
239 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
240 closedTriads += NIdCOTriadV[i].Val2;
241 openTriads += NIdCOTriadV[i].Val3;
245 ClosedTriads =
int64(closedTriads/3);
246 OpenTriads =
int64(openTriads);
250 template <
class PGraph>
252 return GetTriads(Graph, ClosedTriads, OpenTriads, SampleNodes);
257 template <
class PGraph>
259 const bool IsDir = Graph->HasFlag(
gfDirected);
264 Graph->GetNIdV(NIdV);
266 if (SampleNodes == -1) {
267 SampleNodes = Graph->GetNodes(); }
268 NIdCOTriadV.
Clr(
false);
269 NIdCOTriadV.
Reserve(SampleNodes);
270 for (
int node = 0; node < SampleNodes; node++) {
271 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
272 if (NI.GetDeg() < 2) {
273 NIdCOTriadV.
Add(
TIntTr(NI.GetId(), 0, 0));
278 for (
int e = 0; e < NI.GetOutDeg(); e++) {
279 if (NI.GetOutNId(e) != NI.GetId()) {
280 NbrH.
AddKey(NI.GetOutNId(e)); }
283 for (
int e = 0; e < NI.GetInDeg(); e++) {
284 if (NI.GetInNId(e) != NI.GetId()) {
285 NbrH.
AddKey(NI.GetInNId(e)); }
289 int OpenCnt=0, CloseCnt=0;
290 for (
int srcNbr = 0; srcNbr < NbrH.
Len(); srcNbr++) {
291 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrH.
GetKey(srcNbr));
292 for (
int dstNbr = srcNbr+1; dstNbr < NbrH.
Len(); dstNbr++) {
293 const int dstNId = NbrH.
GetKey(dstNbr);
294 if (SrcNode.IsNbrNId(dstNId)) { CloseCnt++; }
299 NIdCOTriadV.
Add(
TIntTr(NI.GetId(), CloseCnt, OpenCnt));
305 template <
class PGraph>
307 const bool IsDir = Graph->HasFlag(
gfDirected);
320 NNodes = Graph->GetNodes();
321 Graph->GetNIdV(NIdV);
323 if (SampleNodes == -1) {
324 SampleNodes = NNodes;
328 for (
int i = 0; i < NNodes; i++) {
329 if (NIdV[i] > MxId) {
338 for (
int node = 0; node < NNodes; node++) {
339 int NId = NIdV[node];
345 for (
int node = 0; node < NNodes; node++) {
346 int NId = NIdV[node];
347 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
349 NbrV[NId].
Reserve(NI.GetOutDeg());
351 for (
int i = 0; i < NI.GetOutDeg(); i++) {
352 NbrV[NId].
Add(NI.GetOutNId(i));
357 NIdCOTriadV.
Clr(
false);
358 NIdCOTriadV.
Reserve(SampleNodes);
359 for (
int node = 0; node < SampleNodes; node++) {
360 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
365 if (NI.GetDeg() < 2) {
374 int OpenCnt1 = 0, CloseCnt1 = 0;
375 for (
int srcNbr = 0; srcNbr < NLen; srcNbr++) {
376 int Count =
GetCommon(NbrV[NbrV[NId][srcNbr]],Nbrs);
380 OpenCnt1 = (NLen*(NLen-1))/2 - CloseCnt1;
381 NIdCOTriadV.
Add(
TIntTr(NId, CloseCnt1, OpenCnt1));
387 template<
class PGraph>
388 int64 CountTriangles(
const PGraph& Graph) {
393 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
394 H.
AddDat(NI.GetId(), ind);
395 MapV.
Add(NI.GetId());
402 #pragma omp parallel for schedule(dynamic)
404 for (
int i = 0; i < ind; i++) {
405 typename PGraph::TObj::TNodeI NI = Graph->GetNI(MapV[i]);
408 MergeNbrs<PGraph>(NbrV, NI);
411 for (
int j = 0; j < NbrV.Len(); j++) {
413 TInt Deg = Graph->GetNI(Vert).GetDeg();
414 if (Deg > NI.GetDeg() ||
415 (Deg == NI.GetDeg() && Vert > NI.GetId())) {
420 HigherDegNbrV[i] = V;
426 #pragma omp parallel for schedule(dynamic) reduction(+:cnt)
428 for (
int i = 0; i < HigherDegNbrV.Len(); i++) {
429 for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
441 template<
class PGraph>
443 const int NNodes = Graph->GetNodes();
451 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
463 for (
int j = 0; j < NNodes; j++) {
471 for (
int i = 0; i < ind; i++) {
473 HigherDegNbrV[i].
Reserve(NV[i].GetDeg());
474 HigherDegNbrV[i].
Reduce(0);
478 #pragma omp parallel for schedule(dynamic)
480 for (
int i = 0; i < ind; i++) {
481 typename PGraph::TObj::TNodeI NI = NV[i];
482 MergeNbrs<PGraph>(HigherDegNbrV[i], NI);
485 for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
486 TInt Vert = HigherDegNbrV[i][j];
487 TInt Deg = NV[IndV[Vert]].GetDeg();
488 if (Deg > NI.GetDeg() ||
489 (Deg == NI.GetDeg() && Vert > NI.GetId())) {
490 HigherDegNbrV[i][k] = Vert;
494 HigherDegNbrV[i].Reduce(k);
499 #pragma omp parallel for schedule(dynamic) reduction(+:cnt)
501 for (
int i = 0; i < HigherDegNbrV.
Len(); i++) {
502 for (
int j = 0; j < HigherDegNbrV[i].
Len(); j++) {
503 TInt NbrInd = IndV[HigherDegNbrV[i][j]];
513 template<
class PGraph>
518 int indeg = NI.GetInDeg();
519 int outdeg = NI.GetOutDeg();
520 if (indeg > 0 && outdeg > 0) {
521 int v1 = NI.GetInNId(j);
522 int v2 = NI.GetOutNId(k);
543 v2 = NI.GetOutNId(k);
548 int v = NI.GetInNId(j);
556 int v = NI.GetOutNId(k);
566 template <
class PGraph>
568 const bool IsDir = Graph->HasFlag(
gfDirected);
571 for(
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
573 for (
int e = 0; e < NI.GetOutDeg(); e++) {
574 if (NI.GetOutNId(e) != NI.GetId()) {
575 NbrH.
AddKey(NI.GetOutNId(e)); }
578 for (
int e = 0; e < NI.GetInDeg(); e++) {
579 if (NI.GetInNId(e) != NI.GetId()) {
580 NbrH.
AddKey(NI.GetInNId(e)); }
583 for (
int e = 0; e < NI.GetOutDeg(); e++) {
584 if (!IsDir && NI.GetId()<NI.GetOutNId(e)) {
continue; }
585 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NI.GetOutNId(e));
587 for (
int e1 = 0; e1 < SrcNode.GetOutDeg(); e1++) {
588 if (NbrH.
IsKey(SrcNode.GetOutNId(e1))) { Triad=
true;
break; }
590 if (IsDir && ! Triad) {
591 for (
int e1 = 0; e1 < SrcNode.GetInDeg(); e1++) {
592 if (NbrH.
IsKey(SrcNode.GetInNId(e1))) { Triad=
true;
break; }
595 if (Triad) { TriadEdges++; }
602 template <
class PGraph>
604 int ClosedTriads=0, OpenTriads=0;
609 template <
class PGraph>
610 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
int& ClosedTriads,
int& OpenTriads) {
611 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
612 ClosedTriads=0; OpenTriads=0;
613 if (NI.GetDeg() < 2) {
return 0; }
616 for (
int e = 0; e < NI.GetOutDeg(); e++) {
617 if (NI.GetOutNId(e) != NI.GetId()) {
618 NbrSet.
AddKey(NI.GetOutNId(e)); }
621 for (
int e = 0; e < NI.GetInDeg(); e++) {
622 if (NI.GetInNId(e) != NI.GetId()) {
623 NbrSet.AddKey(NI.GetInNId(e)); }
627 for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
628 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrSet.GetKey(srcNbr));
629 for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
630 const int dstNId = NbrSet.GetKey(dstNbr);
631 if (SrcNode.IsNbrNId(dstNId)) { ClosedTriads++; }
632 else { OpenTriads++; }
638 template <
class PGraph>
639 int GetNodeTriadsAll(
const PGraph& Graph,
const int& NId,
int& ClosedTriads,
int& OpenTriads) {
647 template <
class PGraph>
648 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
const TIntSet& GroupSet,
int& InGroupEdges,
int& InOutGroupEdges,
int& OutGroupEdges) {
649 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
650 const bool IsDir = Graph->HasFlag(
gfDirected);
651 InGroupEdges=0; InOutGroupEdges=0; OutGroupEdges=0;
652 if (NI.GetDeg() < 2) {
return 0; }
655 for (
int e = 0; e < NI.GetOutDeg(); e++) {
656 if (NI.GetOutNId(e) != NI.GetId()) {
657 NbrSet.
AddKey(NI.GetOutNId(e)); }
660 for (
int e = 0; e < NI.GetInDeg(); e++) {
661 if (NI.GetInNId(e) != NI.GetId()) {
662 NbrSet.AddKey(NI.GetInNId(e)); }
666 for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
667 const int NbrId = NbrSet.GetKey(srcNbr);
668 const bool NbrIn = GroupSet.
IsKey(NbrId);
669 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrId);
670 for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
671 const int DstNId = NbrSet.GetKey(dstNbr);
672 if (SrcNode.IsNbrNId(DstNId)) {
673 bool DstIn = GroupSet.
IsKey(DstNId);
674 if (NbrIn && DstIn) { InGroupEdges++; }
675 else if (NbrIn || DstIn) { InOutGroupEdges++; }
676 else { OutGroupEdges++; }
684 template <
class PGraph>
687 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
689 TriadCntH.
AddDat(Triads) += 1;
695 template<
class PGraph>
696 int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2) {
702 template<
class PGraph>
704 if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.
Clr(
false);
return 0; }
705 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
706 typename PGraph::TObj::TNodeI NI2 = Graph->GetNI(NId2);
709 TIntSet NSet1(NI1.GetDeg()), NSet2(NI2.GetDeg());
710 for (
int i = 0; i < NI1.GetDeg(); i++) {
711 const int nid = NI1.GetNbrNId(i);
712 if (nid!=NId1 && nid!=NId2) {
715 for (
int i = 0; i < NI2.GetDeg(); i++) {
716 const int nid = NI2.GetNbrNId(i);
717 if (NSet1.IsKey(nid)) {
727 if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.Clr(
false);
return 0; }
736 if (j < NI2.
GetDeg() && nid==NI2.
GetNbrNId(j) && nid!=NId1 && nid!=NId2) {
737 IAssert(NbrV.Empty() || NbrV.Last() < nid);
748 template<
class PGraph>
749 int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2) {
756 template<
class PGraph>
758 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId1);
761 for (
int e = 0; e < NI.GetOutDeg(); e++) {
762 const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(NI.GetOutNId(e));
763 if (MidNI.IsOutNId(NId2)) {
764 NbrV.
Add(MidNI.GetId());
770 template <
class PGraph>
772 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
779 int InDeg = NI.GetInDeg();
780 int OutDeg = NI.GetOutDeg();
781 if (InDeg > 0 && OutDeg > 0) {
782 int v1 = NI.GetInNId(j);
783 int v2 = NI.GetOutNId(k);
808 v2 = NI.GetOutNId(k);
813 int v = NI.GetInNId(j);
823 int v = NI.GetOutNId(k);
839 template <
class PGraph>
847 double GetC(
const int& ConstraintN)
const {
return NodePrCH[ConstraintN]; }
849 double GetEdgeC(
const int& NId1,
const int& NId2)
const;
850 double GetNodeC(
const int& NId)
const;
858 template <
class PGraph>
866 template <
class PGraph>
868 if (NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
869 return NodePrCH.GetDat(
TIntPr(NId1, NId2)); }
874 template <
class PGraph>
876 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
877 if (NI1.GetOutDeg() == 0) {
return 0.0; }
879 for (
int k = 0; k<NI1.GetOutDeg(); k++) {
880 KeyId = NodePrCH.GetKeyId(
TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
881 if (KeyId > -1) {
break; }
883 if (KeyId < 0) {
return 0.0; }
884 double Constraint = NodePrCH[KeyId];
885 for (
int i = KeyId-1; i >-1 && NodePrCH.GetKey(i).Val1()==NId; i--) {
886 Constraint += NodePrCH[i];
888 for (
int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
889 Constraint += NodePrCH[i];
894 template <
class PGraph>
896 if (NId1==NId2 || NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
899 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
900 double Constraint = 0.0;
901 if (NI1.IsOutNId(NId2)) {
902 Constraint += 1.0/(double) NI1.GetOutDeg();
904 const double SrcC = 1.0/(double) NI1.GetOutDeg();
905 for (
int e = 0; e < NI1.GetOutDeg(); e++) {
906 const int MidNId = NI1.GetOutNId(e);
907 if (MidNId == NId1 || MidNId == NId2) {
continue; }
908 const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(MidNId);
909 if (MidNI.IsOutNId(NId2)) {
910 Constraint += SrcC * (1.0/(double)MidNI.GetOutDeg());
913 if (Constraint==0) {
return; }
915 NodePrCH.AddDat(
TIntPr(NId1, NId2), Constraint);
918 template <
class PGraph>
921 for (
typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
922 AddConstraint(EI.GetSrcNId(), EI.GetDstNId());
923 AddConstraint(EI.GetDstNId(), EI.GetSrcNId());
926 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
927 for (
int i = 0; i < NI.GetDeg(); i++) {
928 const int NId1 = NI.GetNbrNId(i);
929 for (
int j = 0; j < NI.GetDeg(); j++) {
930 const int NId2 = NI.GetNbrNId(j);
931 AddConstraint(NId1, NId2);
935 NodePrCH.SortByKey();
939 template <
class PGraph>
941 typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
943 for (
int e = 0; e < StartNI.GetOutDeg(); e++) {
944 typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(StartNI.GetOutNId(e));
945 AddConstraint(NId, MidNI.GetId());
946 for (
int i = 0; i < MidNI.GetOutDeg(); i++) {
947 const int EndNId = MidNI.GetOutNId(i);
948 if (! SeenSet.
IsKey(EndNId)) {
949 AddConstraint(NId, EndNId);
956 template <
class PGraph>
958 printf(
"Edge network constraint: (%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
959 for (
int e = 0; e < NodePrCH.Len(); e++) {
960 printf(
" %4d %4d : %f\n", NodePrCH.GetKey(e).Val1(), NodePrCH.GetKey(e).Val2(), NodePrCH[e].Val);
967 template <
class PGraph>
977 NetConstraint.
Dump();
978 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
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.