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);
28 template <
class PGraph>
double GetNodeClustCf(
const PGraph& Graph,
const int& NId);
41 template <
class PGraph>
int64 GetTriads(
const PGraph& Graph,
int SampleNodes=-1);
46 template <
class PGraph>
int64 GetTriads(
const PGraph& Graph,
int64& ClosedTriadsX,
int64& OpenTriadsX,
int SampleNodes);
52 template <
class PGraph>
void GetTriads(
const PGraph& Graph,
TIntTrV& NIdCOTriadV,
int SampleNodes=-1);
57 template <
class PGraph>
int GetTriadEdges(
const PGraph& Graph,
int SampleEdges=-1);
64 template <
class PGraph>
int GetNodeTriads(
const PGraph& Graph,
const int& NId);
72 template <
class PGraph>
int GetNodeTriads(
const PGraph& Graph,
const int& NId,
int& ClosedNTriadsX,
int& OpenNTriadsX);
82 template <
class PGraph>
83 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
const TIntSet& GroupSet,
int& InGroupEdgesX,
int& InOutGroupEdgesX,
int& OutGroupEdgesX);
90 template<
class PGraph>
int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2);
92 template<
class PGraph>
int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2,
TIntV& NbrV);
94 template<
class PGraph>
int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2);
98 template<
class PGraph>
int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2,
TIntV& NbrV);
104 template<
class PGraph>
void MergeNbrs(
TIntV& NeighbourV,
const typename PGraph::TObj::TNodeI& NI);
109 template <
class PGraph>
void GetUniqueNbrV(
const PGraph& Graph,
const int& NId,
TIntV& NbrV);
117 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
int SampleNodes) {
119 GetTriads(Graph, NIdCOTriadV, SampleNodes);
120 if (NIdCOTriadV.
Empty()) {
return 0.0; }
122 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
123 const double OpenCnt = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
125 SumCcf += NIdCOTriadV[i].Val2() / OpenCnt; }
128 return SumCcf / double(NIdCOTriadV.
Len());
131 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
TFltPrV& DegToCCfV,
int SampleNodes) {
133 GetTriads(Graph, NIdCOTriadV, SampleNodes);
136 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
137 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
138 const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
139 TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
145 DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
146 for (
int d = 0; d < DegSumCnt.
Len(); d++) {
147 DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, double(DegSumCnt[d].Val1()/DegSumCnt[d].Val2())));
150 return SumCcf / double(NIdCOTriadV.
Len());
153 template <
class PGraph>
156 GetTriads(Graph, NIdCOTriadV, SampleNodes);
159 int64 closedTriads = 0;
160 int64 openTriads = 0;
161 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
162 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
163 const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
164 closedTriads += NIdCOTriadV[i].Val2;
165 openTriads += NIdCOTriadV[i].Val3;
166 TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
172 DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
173 for (
int d = 0; d < DegSumCnt.
Len(); d++) {
174 DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, DegSumCnt[d].Val1()/DegSumCnt[d].Val2()));
178 ClosedTriads = closedTriads/
int64(3);
179 OpenTriads = openTriads;
181 return SumCcf / double(NIdCOTriadV.
Len());
184 template <
class PGraph>
189 return (Open+Closed)==0 ? 0 : double(Open)/double(Open+Closed);
192 template <
class PGraph>
197 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
198 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
199 const double CCf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
200 NIdCCfH.
AddDat(NIdCOTriadV[i].Val1, CCf);
204 template <
class PGraph>
206 int64 OpenTriads, ClosedTriads;
207 return GetTriads(Graph, ClosedTriads, OpenTriads, SampleNodes);
210 template <
class PGraph>
213 GetTriads(Graph, NIdCOTriadV, SampleNodes);
216 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
217 closedTriads += NIdCOTriadV[i].Val2;
218 openTriads += NIdCOTriadV[i].Val3;
222 ClosedTriads =
int64(closedTriads/3);
223 OpenTriads =
int64(openTriads);
229 template <
class PGraph>
231 const bool IsDir = Graph->HasFlag(
gfDirected);
236 Graph->GetNIdV(NIdV);
238 if (SampleNodes == -1) {
239 SampleNodes = Graph->GetNodes(); }
240 NIdCOTriadV.
Clr(
false);
241 NIdCOTriadV.
Reserve(SampleNodes);
242 for (
int node = 0; node < SampleNodes; node++) {
243 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
244 if (NI.GetDeg() < 2) {
245 NIdCOTriadV.
Add(
TIntTr(NI.GetId(), 0, 0));
250 for (
int e = 0; e < NI.GetOutDeg(); e++) {
251 if (NI.GetOutNId(e) != NI.GetId()) {
252 NbrH.
AddKey(NI.GetOutNId(e)); }
255 for (
int e = 0; e < NI.GetInDeg(); e++) {
256 if (NI.GetInNId(e) != NI.GetId()) {
257 NbrH.
AddKey(NI.GetInNId(e)); }
261 int OpenCnt=0, CloseCnt=0;
262 for (
int srcNbr = 0; srcNbr < NbrH.
Len(); srcNbr++) {
263 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrH.
GetKey(srcNbr));
264 for (
int dstNbr = srcNbr+1; dstNbr < NbrH.
Len(); dstNbr++) {
265 const int dstNId = NbrH.
GetKey(dstNbr);
266 if (SrcNode.IsNbrNId(dstNId)) { CloseCnt++; }
271 NIdCOTriadV.
Add(
TIntTr(NI.GetId(), CloseCnt, OpenCnt));
277 template <
class PGraph>
279 const bool IsDir = Graph->HasFlag(
gfDirected);
292 NNodes = Graph->GetNodes();
293 Graph->GetNIdV(NIdV);
295 if (SampleNodes == -1) {
296 SampleNodes = NNodes;
300 for (
int i = 0; i < NNodes; i++) {
301 if (NIdV[i] > MxId) {
310 for (
int node = 0; node < NNodes; node++) {
311 int NId = NIdV[node];
317 for (
int node = 0; node < NNodes; node++) {
318 int NId = NIdV[node];
319 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
321 NbrV[NId].
Reserve(NI.GetOutDeg());
323 for (
int i = 0; i < NI.GetOutDeg(); i++) {
324 NbrV[NId].
Add(NI.GetOutNId(i));
329 NIdCOTriadV.
Clr(
false);
330 NIdCOTriadV.
Reserve(SampleNodes);
331 for (
int node = 0; node < SampleNodes; node++) {
332 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
337 if (NI.GetDeg() < 2) {
346 int OpenCnt1 = 0, CloseCnt1 = 0;
347 for (
int srcNbr = 0; srcNbr < NLen; srcNbr++) {
348 int Count =
GetCommon(NbrV[NbrV[NId][srcNbr]],Nbrs);
352 OpenCnt1 = (NLen*(NLen-1))/2 - CloseCnt1;
353 NIdCOTriadV.
Add(
TIntTr(NId, CloseCnt1, OpenCnt1));
357 template<
class PGraph>
364 H.
AddDat(NI.GetId(), ind);
365 MapV.
Add(NI.GetId());
372 #pragma omp parallel for schedule(dynamic)
374 for (
int i = 0; i < ind; i++) {
381 for (
int j = 0; j < NbrV.
Len(); j++) {
383 TInt Deg = Graph->GetNI(Vert).GetDeg();
390 HigherDegNbrV[i] = V;
396 #pragma omp parallel for schedule(dynamic) reduction(+:cnt)
398 for (
int i = 0; i < HigherDegNbrV.
Len(); i++) {
399 for (
int j = 0; j < HigherDegNbrV[i].
Len(); j++) {
410 template<
class PGraph>
412 struct timeval start, end;
413 struct timeval startall, endall;
416 int TimerId = Profiler.
AddTimer(
"Profiler");
417 int TimerAll = Profiler.
AddTimer(
"ProfilerAll");
418 const int NNodes = Graph->GetNodes();
426 gettimeofday(&startall, NULL);
430 gettimeofday(&start, NULL);
434 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
446 for (
int j = 0; j < NNodes; j++) {
450 gettimeofday(&end, NULL);
452 delta = ((end.tv_sec - start.tv_sec) * 1000000u +
453 end.tv_usec - start.tv_usec) / 1.e6;
454 printf(
"__nodemap__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.
GetTimerSec(TimerId));
458 gettimeofday(&start, NULL);
464 gettimeofday(&start, NULL);
468 for (
int i = 0; i < ind; i++) {
470 HigherDegNbrV[i].
Reserve(NV[i].GetDeg());
471 HigherDegNbrV[i].
Reduce(0);
474 gettimeofday(&end, NULL);
476 delta = ((end.tv_sec - start.tv_sec) * 1000000u +
477 end.tv_usec - start.tv_usec) / 1.e6;
478 printf(
"__valloc__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.
GetTimerSec(TimerId));
482 gettimeofday(&start, NULL);
485 #pragma omp parallel for schedule(dynamic)
487 for (
int i = 0; i < ind; i++) {
488 typename PGraph::TObj::TNodeI NI = NV[i];
493 MergeNbrs<PGraph>(HigherDegNbrV[i], NI);
496 for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
497 TInt Vert = HigherDegNbrV[i][j];
498 TInt Deg = NV[IndV[Vert]].GetDeg();
499 if (Deg > NI.GetDeg() ||
500 (Deg == NI.GetDeg() && Vert > NI.GetId())) {
501 HigherDegNbrV[i][k] = Vert;
505 HigherDegNbrV[i].Reduce(k);
508 gettimeofday(&end, NULL);
510 delta = ((end.tv_sec - start.tv_sec) * 1000000u +
511 end.tv_usec - start.tv_usec) / 1.e6;
512 printf(
"__sort__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.
GetTimerSec(TimerId));
516 gettimeofday(&start, NULL);
520 #pragma omp parallel for schedule(dynamic) reduction(+:cnt)
522 for (
int i = 0; i < HigherDegNbrV.
Len(); i++) {
523 for (
int j = 0; j < HigherDegNbrV[i].
Len(); j++) {
525 TInt NbrInd = IndV[HigherDegNbrV[i][j]];
532 gettimeofday(&end, NULL);
534 delta = ((end.tv_sec - start.tv_sec) * 1000000u +
535 end.tv_usec - start.tv_usec) / 1.e6;
536 printf(
"__count__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.
GetTimerSec(TimerId));
538 gettimeofday(&endall, NULL);
540 delta = ((endall.tv_sec - startall.tv_sec) * 1000000u +
541 endall.tv_usec - startall.tv_usec) / 1.e6;
542 printf(
"__all__ \ttime %7.3f\tcpu %8.3f\n", delta, Profiler.
GetTimerSec(TimerAll));
546 template<
class PGraph>
551 int indeg = NI.GetInDeg();
552 int outdeg = NI.GetOutDeg();
554 if (indeg > 0 && outdeg > 0) {
555 int v1 = NI.GetInNId(j);
556 int v2 = NI.GetOutNId(k);
577 v2 = NI.GetOutNId(k);
582 int v = NI.GetInNId(j);
590 int v = NI.GetOutNId(k);
600 template <
class PGraph>
602 const bool IsDir = Graph->HasFlag(
gfDirected);
605 for(
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
607 for (
int e = 0; e < NI.GetOutDeg(); e++) {
608 if (NI.GetOutNId(e) != NI.GetId()) {
609 NbrH.
AddKey(NI.GetOutNId(e)); }
612 for (
int e = 0; e < NI.GetInDeg(); e++) {
613 if (NI.GetInNId(e) != NI.GetId()) {
614 NbrH.
AddKey(NI.GetInNId(e)); }
617 for (
int e = 0; e < NI.GetOutDeg(); e++) {
618 if (!IsDir && NI.GetId()<NI.GetOutNId(e)) {
continue; }
619 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NI.GetOutNId(e));
621 for (
int e1 = 0; e1 < SrcNode.GetOutDeg(); e1++) {
622 if (NbrH.
IsKey(SrcNode.GetOutNId(e1))) { Triad=
true;
break; }
624 if (IsDir && ! Triad) {
625 for (
int e1 = 0; e1 < SrcNode.GetInDeg(); e1++) {
626 if (NbrH.
IsKey(SrcNode.GetInNId(e1))) { Triad=
true;
break; }
629 if (Triad) { TriadEdges++; }
636 template <
class PGraph>
638 int ClosedTriads=0, OpenTriads=0;
643 template <
class PGraph>
644 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
int& ClosedTriads,
int& OpenTriads) {
645 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
646 ClosedTriads=0; OpenTriads=0;
647 if (NI.GetDeg() < 2) {
return 0; }
650 for (
int e = 0; e < NI.GetOutDeg(); e++) {
651 if (NI.GetOutNId(e) != NI.GetId()) {
652 NbrSet.
AddKey(NI.GetOutNId(e)); }
655 for (
int e = 0; e < NI.GetInDeg(); e++) {
656 if (NI.GetInNId(e) != NI.GetId()) {
657 NbrSet.AddKey(NI.GetInNId(e)); }
661 for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
662 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrSet.GetKey(srcNbr));
663 for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
664 const int dstNId = NbrSet.GetKey(dstNbr);
665 if (SrcNode.IsNbrNId(dstNId)) { ClosedTriads++; }
666 else { OpenTriads++; }
676 template <
class PGraph>
677 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
const TIntSet& GroupSet,
int& InGroupEdges,
int& InOutGroupEdges,
int& OutGroupEdges) {
678 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
679 const bool IsDir = Graph->HasFlag(
gfDirected);
680 InGroupEdges=0; InOutGroupEdges=0; OutGroupEdges=0;
681 if (NI.GetDeg() < 2) {
return 0; }
684 for (
int e = 0; e < NI.GetOutDeg(); e++) {
685 if (NI.GetOutNId(e) != NI.GetId()) {
686 NbrSet.
AddKey(NI.GetOutNId(e)); }
689 for (
int e = 0; e < NI.GetInDeg(); e++) {
690 if (NI.GetInNId(e) != NI.GetId()) {
691 NbrSet.AddKey(NI.GetInNId(e)); }
695 for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
696 const int NbrId = NbrSet.GetKey(srcNbr);
697 const bool NbrIn = GroupSet.
IsKey(NbrId);
698 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrId);
699 for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
700 const int DstNId = NbrSet.GetKey(dstNbr);
701 if (SrcNode.IsNbrNId(DstNId)) {
702 bool DstIn = GroupSet.
IsKey(DstNId);
703 if (NbrIn && DstIn) { InGroupEdges++; }
704 else if (NbrIn || DstIn) { InOutGroupEdges++; }
705 else { OutGroupEdges++; }
713 template <
class PGraph>
716 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
718 TriadCntH.
AddDat(Triads) += 1;
724 template<
class PGraph>
725 int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2) {
731 template<
class PGraph>
733 if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.
Clr(
false);
return 0; }
734 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
735 typename PGraph::TObj::TNodeI NI2 = Graph->GetNI(NId2);
738 TIntSet NSet1(NI1.GetDeg()), NSet2(NI2.GetDeg());
739 for (
int i = 0; i < NI1.GetDeg(); i++) {
740 const int nid = NI1.GetNbrNId(i);
741 if (nid!=NId1 && nid!=NId2) {
744 for (
int i = 0; i < NI2.GetDeg(); i++) {
745 const int nid = NI2.GetNbrNId(i);
746 if (NSet1.IsKey(nid)) {
756 if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.Clr(
false);
return 0; }
765 if (j < NI2.
GetDeg() && nid==NI2.
GetNbrNId(j) && nid!=NId1 && nid!=NId2) {
766 IAssert(NbrV.Empty() || NbrV.Last() < nid);
777 template<
class PGraph>
778 int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2) {
785 template<
class PGraph>
787 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId1);
790 for (
int e = 0; e < NI.GetOutDeg(); e++) {
791 const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(NI.GetOutNId(e));
792 if (MidNI.IsOutNId(NId2)) {
793 NbrV.
Add(MidNI.GetId());
799 template <
class PGraph>
801 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
808 int InDeg = NI.GetInDeg();
809 int OutDeg = NI.GetOutDeg();
810 if (InDeg > 0 && OutDeg > 0) {
811 int v1 = NI.GetInNId(j);
812 int v2 = NI.GetOutNId(k);
837 v2 = NI.GetOutNId(k);
842 int v = NI.GetInNId(j);
852 int v = NI.GetOutNId(k);
868 template <
class PGraph>
876 double GetC(
const int& ConstraintN)
const {
return NodePrCH[ConstraintN]; }
878 double GetEdgeC(
const int& NId1,
const int& NId2)
const;
879 double GetNodeC(
const int& NId)
const;
887 template <
class PGraph>
895 template <
class PGraph>
897 if (NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
898 return NodePrCH.GetDat(
TIntPr(NId1, NId2)); }
903 template <
class PGraph>
905 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
906 if (NI1.GetOutDeg() == 0) {
return 0.0; }
908 for (
int k = 0; k<NI1.GetOutDeg(); k++) {
909 KeyId = NodePrCH.GetKeyId(
TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
910 if (KeyId > -1) {
break; }
912 if (KeyId < 0) {
return 0.0; }
913 double Constraint = NodePrCH[KeyId];
914 for (
int i = KeyId-1; i >-1 && NodePrCH.GetKey(i).Val1()==NId; i--) {
915 Constraint += NodePrCH[i];
917 for (
int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
918 Constraint += NodePrCH[i];
923 template <
class PGraph>
925 if (NId1==NId2 || NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
928 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
929 double Constraint = 0.0;
930 if (NI1.IsOutNId(NId2)) {
931 Constraint += 1.0/(double) NI1.GetOutDeg();
933 const double SrcC = 1.0/(double) NI1.GetOutDeg();
934 for (
int e = 0; e < NI1.GetOutDeg(); e++) {
935 const int MidNId = NI1.GetOutNId(e);
936 if (MidNId == NId1 || MidNId == NId2) {
continue; }
937 const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(MidNId);
938 if (MidNI.IsOutNId(NId2)) {
939 Constraint += SrcC * (1.0/(double)MidNI.GetOutDeg());
942 if (Constraint==0) {
return; }
944 NodePrCH.AddDat(
TIntPr(NId1, NId2), Constraint);
947 template <
class PGraph>
950 for (
typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
951 AddConstraint(EI.GetSrcNId(), EI.GetDstNId());
952 AddConstraint(EI.GetDstNId(), EI.GetSrcNId());
955 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
956 for (
int i = 0; i < NI.GetDeg(); i++) {
957 const int NId1 = NI.GetNbrNId(i);
958 for (
int j = 0; j < NI.GetDeg(); j++) {
959 const int NId2 = NI.GetNbrNId(j);
960 AddConstraint(NId1, NId2);
964 NodePrCH.SortByKey();
968 template <
class PGraph>
970 typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
972 for (
int e = 0; e < StartNI.GetOutDeg(); e++) {
973 typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(StartNI.GetOutNId(e));
974 AddConstraint(NId, MidNI.GetId());
975 for (
int i = 0; i < MidNI.GetOutDeg(); i++) {
976 const int EndNId = MidNI.GetOutNId(i);
977 if (! SeenSet.
IsKey(EndNId)) {
978 AddConstraint(NId, EndNId);
985 template <
class PGraph>
987 printf(
"Edge network constraint: (%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
988 for (
int e = 0; e < NodePrCH.Len(); e++) {
989 printf(
" %4d %4d : %f\n", NodePrCH.GetKey(e).Val1(), NodePrCH.GetKey(e).Val2(), NodePrCH[e].Val);
996 template <
class PGraph>
1006 NetConstraint.
Dump();
1007 printf(
"middle node network constraint: %f\n", NetConstraint.
GetNodeC(0));
void Clr(const bool &DoDel=true, const int &NoDelLim=-1)
double GetTimerSec(const int &TimerId) const
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, newer version.
int64 CountTriangles(const PGraph &Graph)
Returns the number of triangles in graph Graph, original version.
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.
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.
int AddTimer(const TStr &TimerNm)
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)
void GetMergeSortedV(TIntV &NeighbourV, TNGraph::TNodeI NI)
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 GetC(const int &ConstraintN) const
TPair< TFlt, TFlt > TFltPr
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
void StopTimer(const TStr &TimerNm)
void StartTimer(const TStr &TimerNm)
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph
double GetEdgeC(const int &NId1, const int &NId2) const
int GetId() const
Returns ID of the current node.
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.
Node iterator. Only forward iteration (operator++) is supported.
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
void ResetTimer(const TStr &TimerNm)
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.