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);
102 template<
class PGraph>
void MergeNbrs(
TIntV& NeighbourV,
const typename PGraph::TObj::TNodeI& NI);
105 template <
class PGraph>
void GetUniqueNbrV(
const PGraph& Graph,
const int& NId,
TIntV& NbrV);
113 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
int SampleNodes) {
115 GetTriads(Graph, NIdCOTriadV, SampleNodes);
116 if (NIdCOTriadV.
Empty()) {
return 0.0; }
118 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
119 const double OpenCnt = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
121 SumCcf += NIdCOTriadV[i].Val2() / OpenCnt; }
124 return SumCcf / double(NIdCOTriadV.
Len());
127 template <
class PGraph>
double GetClustCf(
const PGraph& Graph,
TFltPrV& DegToCCfV,
int SampleNodes) {
129 GetTriads(Graph, NIdCOTriadV, SampleNodes);
132 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
133 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
134 const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
135 TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
141 DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
142 for (
int d = 0; d < DegSumCnt.
Len(); d++) {
143 DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, double(DegSumCnt[d].Val1()/DegSumCnt[d].Val2())));
146 return SumCcf / double(NIdCOTriadV.
Len());
149 template <
class PGraph>
152 GetTriads(Graph, NIdCOTriadV, SampleNodes);
155 int64 closedTriads = 0;
156 int64 openTriads = 0;
157 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
158 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
159 const double Ccf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
160 closedTriads += NIdCOTriadV[i].Val2;
161 openTriads += NIdCOTriadV[i].Val3;
162 TFltPr& SumCnt = DegSumCnt.
AddDat(Graph->GetNI(NIdCOTriadV[i].Val1).GetDeg());
168 DegToCCfV.
Gen(DegSumCnt.
Len(), 0);
169 for (
int d = 0; d < DegSumCnt.
Len(); d++) {
170 DegToCCfV.
Add(
TFltPr(DegSumCnt.
GetKey(d).
Val, DegSumCnt[d].Val1()/DegSumCnt[d].Val2()));
174 ClosedTriads = closedTriads/
int64(3);
175 OpenTriads = openTriads;
177 return SumCcf / double(NIdCOTriadV.
Len());
180 template <
class PGraph>
185 return (Open+Closed)==0 ? 0 : double(Open)/double(Open+Closed);
188 template <
class PGraph>
193 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
194 const int D = NIdCOTriadV[i].Val2()+NIdCOTriadV[i].Val3();
195 const double CCf = D!=0 ? NIdCOTriadV[i].Val2() / double(D) : 0.0;
196 NIdCCfH.
AddDat(NIdCOTriadV[i].Val1, CCf);
200 template <
class PGraph>
202 int64 OpenTriads, ClosedTriads;
203 return GetTriads(Graph, ClosedTriads, OpenTriads, SampleNodes);
206 template <
class PGraph>
209 GetTriads(Graph, NIdCOTriadV, SampleNodes);
212 for (
int i = 0; i < NIdCOTriadV.
Len(); i++) {
213 closedTriads += NIdCOTriadV[i].Val2;
214 openTriads += NIdCOTriadV[i].Val3;
218 ClosedTriads =
int64(closedTriads/3);
219 OpenTriads =
int64(openTriads);
225 template <
class PGraph>
227 const bool IsDir = Graph->HasFlag(
gfDirected);
232 Graph->GetNIdV(NIdV);
234 if (SampleNodes == -1) {
235 SampleNodes = Graph->GetNodes(); }
236 NIdCOTriadV.
Clr(
false);
237 NIdCOTriadV.
Reserve(SampleNodes);
238 for (
int node = 0; node < SampleNodes; node++) {
239 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
240 if (NI.GetDeg() < 2) {
241 NIdCOTriadV.
Add(
TIntTr(NI.GetId(), 0, 0));
246 for (
int e = 0; e < NI.GetOutDeg(); e++) {
247 if (NI.GetOutNId(e) != NI.GetId()) {
248 NbrH.
AddKey(NI.GetOutNId(e)); }
251 for (
int e = 0; e < NI.GetInDeg(); e++) {
252 if (NI.GetInNId(e) != NI.GetId()) {
253 NbrH.
AddKey(NI.GetInNId(e)); }
257 int OpenCnt=0, CloseCnt=0;
258 for (
int srcNbr = 0; srcNbr < NbrH.
Len(); srcNbr++) {
259 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrH.
GetKey(srcNbr));
260 for (
int dstNbr = srcNbr+1; dstNbr < NbrH.
Len(); dstNbr++) {
261 const int dstNId = NbrH.
GetKey(dstNbr);
262 if (SrcNode.IsNbrNId(dstNId)) { CloseCnt++; }
267 NIdCOTriadV.
Add(
TIntTr(NI.GetId(), CloseCnt, OpenCnt));
273 template <
class PGraph>
275 const bool IsDir = Graph->HasFlag(
gfDirected);
288 NNodes = Graph->GetNodes();
289 Graph->GetNIdV(NIdV);
291 if (SampleNodes == -1) {
292 SampleNodes = NNodes;
296 for (
int i = 0; i < NNodes; i++) {
297 if (NIdV[i] > MxId) {
306 for (
int node = 0; node < NNodes; node++) {
307 int NId = NIdV[node];
313 for (
int node = 0; node < NNodes; node++) {
314 int NId = NIdV[node];
315 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
317 NbrV[NId].
Reserve(NI.GetOutDeg());
319 for (
int i = 0; i < NI.GetOutDeg(); i++) {
320 NbrV[NId].
Add(NI.GetOutNId(i));
325 NIdCOTriadV.
Clr(
false);
326 NIdCOTriadV.
Reserve(SampleNodes);
327 for (
int node = 0; node < SampleNodes; node++) {
328 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NIdV[node]);
333 if (NI.GetDeg() < 2) {
342 int OpenCnt1 = 0, CloseCnt1 = 0;
343 for (
int srcNbr = 0; srcNbr < NLen; srcNbr++) {
344 int Count =
GetCommon(NbrV[NbrV[NId][srcNbr]],Nbrs);
348 OpenCnt1 = (NLen*(NLen-1))/2 - CloseCnt1;
349 NIdCOTriadV.
Add(
TIntTr(NId, CloseCnt1, OpenCnt1));
355 template<
class PGraph>
356 int64 CountTriangles(
const PGraph& Graph) {
361 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
362 H.
AddDat(NI.GetId(), ind);
363 MapV.
Add(NI.GetId());
370 #pragma omp parallel for schedule(dynamic)
372 for (
int i = 0; i < ind; i++) {
373 typename PGraph::TObj::TNodeI NI = Graph->GetNI(MapV[i]);
376 MergeNbrs<PGraph>(NbrV, NI);
379 for (
int j = 0; j < NbrV.Len(); j++) {
381 TInt Deg = Graph->GetNI(Vert).GetDeg();
382 if (Deg > NI.GetDeg() ||
383 (Deg == NI.GetDeg() && Vert > NI.GetId())) {
388 HigherDegNbrV[i] = V;
394 #pragma omp parallel for schedule(dynamic) reduction(+:cnt)
396 for (
int i = 0; i < HigherDegNbrV.Len(); i++) {
397 for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
409 template<
class PGraph>
411 const int NNodes = Graph->GetNodes();
419 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
431 for (
int j = 0; j < NNodes; j++) {
439 for (
int i = 0; i < ind; i++) {
441 HigherDegNbrV[i].
Reserve(NV[i].GetDeg());
442 HigherDegNbrV[i].
Reduce(0);
446 #pragma omp parallel for schedule(dynamic)
448 for (
int i = 0; i < ind; i++) {
449 typename PGraph::TObj::TNodeI NI = NV[i];
450 MergeNbrs<PGraph>(HigherDegNbrV[i], NI);
453 for (
int j = 0; j < HigherDegNbrV[i].Len(); j++) {
454 TInt Vert = HigherDegNbrV[i][j];
455 TInt Deg = NV[IndV[Vert]].GetDeg();
456 if (Deg > NI.GetDeg() ||
457 (Deg == NI.GetDeg() && Vert > NI.GetId())) {
458 HigherDegNbrV[i][k] = Vert;
462 HigherDegNbrV[i].Reduce(k);
467 #pragma omp parallel for schedule(dynamic) reduction(+:cnt)
469 for (
int i = 0; i < HigherDegNbrV.
Len(); i++) {
470 for (
int j = 0; j < HigherDegNbrV[i].
Len(); j++) {
471 TInt NbrInd = IndV[HigherDegNbrV[i][j]];
481 template<
class PGraph>
486 int indeg = NI.GetInDeg();
487 int outdeg = NI.GetOutDeg();
488 if (indeg > 0 && outdeg > 0) {
489 int v1 = NI.GetInNId(j);
490 int v2 = NI.GetOutNId(k);
511 v2 = NI.GetOutNId(k);
516 int v = NI.GetInNId(j);
524 int v = NI.GetOutNId(k);
534 template <
class PGraph>
536 const bool IsDir = Graph->HasFlag(
gfDirected);
539 for(
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
541 for (
int e = 0; e < NI.GetOutDeg(); e++) {
542 if (NI.GetOutNId(e) != NI.GetId()) {
543 NbrH.
AddKey(NI.GetOutNId(e)); }
546 for (
int e = 0; e < NI.GetInDeg(); e++) {
547 if (NI.GetInNId(e) != NI.GetId()) {
548 NbrH.
AddKey(NI.GetInNId(e)); }
551 for (
int e = 0; e < NI.GetOutDeg(); e++) {
552 if (!IsDir && NI.GetId()<NI.GetOutNId(e)) {
continue; }
553 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NI.GetOutNId(e));
555 for (
int e1 = 0; e1 < SrcNode.GetOutDeg(); e1++) {
556 if (NbrH.
IsKey(SrcNode.GetOutNId(e1))) { Triad=
true;
break; }
558 if (IsDir && ! Triad) {
559 for (
int e1 = 0; e1 < SrcNode.GetInDeg(); e1++) {
560 if (NbrH.
IsKey(SrcNode.GetInNId(e1))) { Triad=
true;
break; }
563 if (Triad) { TriadEdges++; }
570 template <
class PGraph>
572 int ClosedTriads=0, OpenTriads=0;
577 template <
class PGraph>
578 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
int& ClosedTriads,
int& OpenTriads) {
579 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
580 ClosedTriads=0; OpenTriads=0;
581 if (NI.GetDeg() < 2) {
return 0; }
584 for (
int e = 0; e < NI.GetOutDeg(); e++) {
585 if (NI.GetOutNId(e) != NI.GetId()) {
586 NbrSet.
AddKey(NI.GetOutNId(e)); }
589 for (
int e = 0; e < NI.GetInDeg(); e++) {
590 if (NI.GetInNId(e) != NI.GetId()) {
591 NbrSet.AddKey(NI.GetInNId(e)); }
595 for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
596 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrSet.GetKey(srcNbr));
597 for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
598 const int dstNId = NbrSet.GetKey(dstNbr);
599 if (SrcNode.IsNbrNId(dstNId)) { ClosedTriads++; }
600 else { OpenTriads++; }
610 template <
class PGraph>
611 int GetNodeTriads(
const PGraph& Graph,
const int& NId,
const TIntSet& GroupSet,
int& InGroupEdges,
int& InOutGroupEdges,
int& OutGroupEdges) {
612 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
613 const bool IsDir = Graph->HasFlag(
gfDirected);
614 InGroupEdges=0; InOutGroupEdges=0; OutGroupEdges=0;
615 if (NI.GetDeg() < 2) {
return 0; }
618 for (
int e = 0; e < NI.GetOutDeg(); e++) {
619 if (NI.GetOutNId(e) != NI.GetId()) {
620 NbrSet.
AddKey(NI.GetOutNId(e)); }
623 for (
int e = 0; e < NI.GetInDeg(); e++) {
624 if (NI.GetInNId(e) != NI.GetId()) {
625 NbrSet.AddKey(NI.GetInNId(e)); }
629 for (
int srcNbr = 0; srcNbr < NbrSet.Len(); srcNbr++) {
630 const int NbrId = NbrSet.GetKey(srcNbr);
631 const bool NbrIn = GroupSet.
IsKey(NbrId);
632 const typename PGraph::TObj::TNodeI SrcNode = Graph->GetNI(NbrId);
633 for (
int dstNbr = srcNbr+1; dstNbr < NbrSet.Len(); dstNbr++) {
634 const int DstNId = NbrSet.GetKey(dstNbr);
635 if (SrcNode.IsNbrNId(DstNId)) {
636 bool DstIn = GroupSet.
IsKey(DstNId);
637 if (NbrIn && DstIn) { InGroupEdges++; }
638 else if (NbrIn || DstIn) { InOutGroupEdges++; }
639 else { OutGroupEdges++; }
647 template <
class PGraph>
650 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
652 TriadCntH.
AddDat(Triads) += 1;
658 template<
class PGraph>
659 int GetCmnNbrs(
const PGraph& Graph,
const int& NId1,
const int& NId2) {
665 template<
class PGraph>
667 if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.
Clr(
false);
return 0; }
668 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
669 typename PGraph::TObj::TNodeI NI2 = Graph->GetNI(NId2);
672 TIntSet NSet1(NI1.GetDeg()), NSet2(NI2.GetDeg());
673 for (
int i = 0; i < NI1.GetDeg(); i++) {
674 const int nid = NI1.GetNbrNId(i);
675 if (nid!=NId1 && nid!=NId2) {
678 for (
int i = 0; i < NI2.GetDeg(); i++) {
679 const int nid = NI2.GetNbrNId(i);
680 if (NSet1.IsKey(nid)) {
690 if (! Graph->IsNode(NId1) || ! Graph->IsNode(NId2)) { NbrV.Clr(
false);
return 0; }
699 if (j < NI2.
GetDeg() && nid==NI2.
GetNbrNId(j) && nid!=NId1 && nid!=NId2) {
700 IAssert(NbrV.Empty() || NbrV.Last() < nid);
711 template<
class PGraph>
712 int GetLen2Paths(
const PGraph& Graph,
const int& NId1,
const int& NId2) {
719 template<
class PGraph>
721 const typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId1);
724 for (
int e = 0; e < NI.GetOutDeg(); e++) {
725 const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(NI.GetOutNId(e));
726 if (MidNI.IsOutNId(NId2)) {
727 NbrV.
Add(MidNI.GetId());
733 template <
class PGraph>
735 typename PGraph::TObj::TNodeI NI = Graph->GetNI(NId);
742 int InDeg = NI.GetInDeg();
743 int OutDeg = NI.GetOutDeg();
744 if (InDeg > 0 && OutDeg > 0) {
745 int v1 = NI.GetInNId(j);
746 int v2 = NI.GetOutNId(k);
771 v2 = NI.GetOutNId(k);
776 int v = NI.GetInNId(j);
786 int v = NI.GetOutNId(k);
802 template <
class PGraph>
810 double GetC(
const int& ConstraintN)
const {
return NodePrCH[ConstraintN]; }
812 double GetEdgeC(
const int& NId1,
const int& NId2)
const;
813 double GetNodeC(
const int& NId)
const;
821 template <
class PGraph>
829 template <
class PGraph>
831 if (NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
832 return NodePrCH.GetDat(
TIntPr(NId1, NId2)); }
837 template <
class PGraph>
839 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
840 if (NI1.GetOutDeg() == 0) {
return 0.0; }
842 for (
int k = 0; k<NI1.GetOutDeg(); k++) {
843 KeyId = NodePrCH.GetKeyId(
TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
844 if (KeyId > -1) {
break; }
846 if (KeyId < 0) {
return 0.0; }
847 double Constraint = NodePrCH[KeyId];
848 for (
int i = KeyId-1; i >-1 && NodePrCH.GetKey(i).Val1()==NId; i--) {
849 Constraint += NodePrCH[i];
851 for (
int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
852 Constraint += NodePrCH[i];
857 template <
class PGraph>
859 if (NId1==NId2 || NodePrCH.IsKey(
TIntPr(NId1, NId2))) {
862 typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
863 double Constraint = 0.0;
864 if (NI1.IsOutNId(NId2)) {
865 Constraint += 1.0/(double) NI1.GetOutDeg();
867 const double SrcC = 1.0/(double) NI1.GetOutDeg();
868 for (
int e = 0; e < NI1.GetOutDeg(); e++) {
869 const int MidNId = NI1.GetOutNId(e);
870 if (MidNId == NId1 || MidNId == NId2) {
continue; }
871 const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(MidNId);
872 if (MidNI.IsOutNId(NId2)) {
873 Constraint += SrcC * (1.0/(double)MidNI.GetOutDeg());
876 if (Constraint==0) {
return; }
878 NodePrCH.AddDat(
TIntPr(NId1, NId2), Constraint);
881 template <
class PGraph>
884 for (
typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
885 AddConstraint(EI.GetSrcNId(), EI.GetDstNId());
886 AddConstraint(EI.GetDstNId(), EI.GetSrcNId());
889 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
890 for (
int i = 0; i < NI.GetDeg(); i++) {
891 const int NId1 = NI.GetNbrNId(i);
892 for (
int j = 0; j < NI.GetDeg(); j++) {
893 const int NId2 = NI.GetNbrNId(j);
894 AddConstraint(NId1, NId2);
898 NodePrCH.SortByKey();
902 template <
class PGraph>
904 typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
906 for (
int e = 0; e < StartNI.GetOutDeg(); e++) {
907 typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(StartNI.GetOutNId(e));
908 AddConstraint(NId, MidNI.GetId());
909 for (
int i = 0; i < MidNI.GetOutDeg(); i++) {
910 const int EndNId = MidNI.GetOutNId(i);
911 if (! SeenSet.
IsKey(EndNId)) {
912 AddConstraint(NId, EndNId);
919 template <
class PGraph>
921 printf(
"Edge network constraint: (%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
922 for (
int e = 0; e < NodePrCH.Len(); e++) {
923 printf(
" %4d %4d : %f\n", NodePrCH.GetKey(e).Val1(), NodePrCH.GetKey(e).Val2(), NodePrCH[e].Val);
930 template <
class PGraph>
940 NetConstraint.
Dump();
941 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)
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 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.