SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TNetConstraint< PGraph > Class Template Reference

#include <triad.h>

Collaboration diagram for TNetConstraint< PGraph >:

Public Member Functions

 TNetConstraint (const PGraph &GraphPt, const bool &CalcaAll=true)
 
int Len () const
 
double GetC (const int &ConstraintN) const
 
TIntPr GetNodePr (const int &ConstraintN) const
 
double GetEdgeC (const int &NId1, const int &NId2) const
 
double GetNodeC (const int &NId) const
 
void AddConstraint (const int &NId1, const int &NId2)
 
void CalcConstraints ()
 
void CalcConstraints (const int &NId)
 
void Dump () const
 

Static Public Member Functions

static void Test ()
 

Public Attributes

PGraph Graph
 
THash< TIntPr, TFltNodePrCH
 

Detailed Description

template<class PGraph>
class TNetConstraint< PGraph >

Definition at line 852 of file triad.h.

Constructor & Destructor Documentation

template<class PGraph >
TNetConstraint< PGraph >::TNetConstraint ( const PGraph &  GraphPt,
const bool &  CalcaAll = true 
)

Definition at line 871 of file triad.h.

References TNetConstraint< PGraph >::CalcConstraints(), CAssert, gfMultiGraph, and HasGraphFlag.

871  : Graph(GraphPt) {
872  CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // must not be multigraph
873  if (CalcaAll) {
874  CalcConstraints();
875  }
876 }
void CalcConstraints()
Definition: triad.h:931
PGraph Graph
Definition: triad.h:854
have explicit edges (multigraph): TNEGraph, TNodeEdgeNet
Definition: gbase.h:14
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
#define CAssert(Cond)
Definition: bd.h:302

Here is the call graph for this function:

Member Function Documentation

template<class PGraph >
void TNetConstraint< PGraph >::AddConstraint ( const int &  NId1,
const int &  NId2 
)

Definition at line 907 of file triad.h.

References TMath::Sqr().

907  {
908  if (NId1==NId2 || NodePrCH.IsKey(TIntPr(NId1, NId2))) {
909  return;
910  }
911  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
912  double Constraint = 0.0;
913  if (NI1.IsOutNId(NId2)) { // is direct edge
914  Constraint += 1.0/(double) NI1.GetOutDeg();
915  }
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());
923  }
924  }
925  if (Constraint==0) { return; }
926  Constraint = TMath::Sqr(Constraint);
927  NodePrCH.AddDat(TIntPr(NId1, NId2), Constraint);
928 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
PGraph Graph
Definition: triad.h:854
static double Sqr(const double &x)
Definition: xmath.h:12
Definition: ds.h:32
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TDat & AddDat(const TKey &Key)
Definition: hash.h:238

Here is the call graph for this function:

template<class PGraph >
void TNetConstraint< PGraph >::CalcConstraints ( )

Definition at line 931 of file triad.h.

Referenced by TNetConstraint< PGraph >::TNetConstraint().

931  {
932  // add edges
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());
936  }
937  // add open triads
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);
944  }
945  }
946  }
948 }
PGraph Graph
Definition: triad.h:854
void AddConstraint(const int &NId1, const int &NId2)
Definition: triad.h:907
void SortByKey(const bool &Asc=true)
Definition: hash.h:291
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855

Here is the caller graph for this function:

template<class PGraph >
void TNetConstraint< PGraph >::CalcConstraints ( const int &  NId)

Definition at line 952 of file triad.h.

References THashSet< TKey, THashFunc >::AddKey(), and THashSet< TKey, THashFunc >::IsKey().

952  {
953  typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
954  TIntSet SeenSet;
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);
962  SeenSet.AddKey(EndNId);
963  }
964  }
965  }
966 }
PGraph Graph
Definition: triad.h:854
bool IsKey(const TKey &Key) const
Definition: shash.h:1148
void AddConstraint(const int &NId1, const int &NId2)
Definition: triad.h:907
int AddKey(const TKey &Key)
Definition: shash.h:1254

Here is the call graph for this function:

template<class PGraph >
void TNetConstraint< PGraph >::Dump ( ) const

Definition at line 969 of file triad.h.

Referenced by TNetConstraint< PGraph >::Test().

969  {
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);
973  }
974  printf("\n");
975 }
PGraph Graph
Definition: triad.h:854
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
int Len() const
Definition: hash.h:228
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252

Here is the caller graph for this function:

template<class PGraph>
double TNetConstraint< PGraph >::GetC ( const int &  ConstraintN) const
inline

Definition at line 859 of file triad.h.

859 { return NodePrCH[ConstraintN]; }
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
template<class PGraph >
double TNetConstraint< PGraph >::GetEdgeC ( const int &  NId1,
const int &  NId2 
) const

Definition at line 879 of file triad.h.

879  {
880  if (NodePrCH.IsKey(TIntPr(NId1, NId2))) {
881  return NodePrCH.GetDat(TIntPr(NId1, NId2)); }
882  else {
883  return 0.0; }
884 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
Definition: ds.h:32
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
bool IsKey(const TKey &Key) const
Definition: hash.h:258
template<class PGraph >
double TNetConstraint< PGraph >::GetNodeC ( const int &  NId) const

Definition at line 887 of file triad.h.

Referenced by TNetConstraint< PGraph >::Test().

887  {
888  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
889  if (NI1.GetOutDeg() == 0) { return 0.0; }
890  int KeyId = -1;
891  for (int k = 0; k<NI1.GetOutDeg(); k++) {
892  KeyId = NodePrCH.GetKeyId(TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
893  if (KeyId > -1) { break; }
894  }
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];
899  }
900  for (int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
901  Constraint += NodePrCH[i];
902  }
903  return Constraint;
904 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
PGraph Graph
Definition: triad.h:854
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
TVal1 Val1
Definition: ds.h:34
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
int Len() const
Definition: hash.h:228
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252

Here is the caller graph for this function:

template<class PGraph>
TIntPr TNetConstraint< PGraph >::GetNodePr ( const int &  ConstraintN) const
inline

Definition at line 860 of file triad.h.

References THash< TKey, TDat, THashFunc >::GetKey().

860 { return NodePrCH.GetKey(ConstraintN); }
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252

Here is the call graph for this function:

template<class PGraph>
int TNetConstraint< PGraph >::Len ( ) const
inline

Definition at line 858 of file triad.h.

References THash< TKey, TDat, THashFunc >::Len().

858 { return NodePrCH.Len(); }
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:855
int Len() const
Definition: hash.h:228

Here is the call graph for this function:

template<class PGraph >
void TNetConstraint< PGraph >::Test ( )
static

Definition at line 980 of file triad.h.

References TUNGraph::AddEdge(), TUNGraph::AddNode(), TNetConstraint< PGraph >::Dump(), TNetConstraint< PGraph >::GetNodeC(), and TUNGraph::New().

980  {
981  PUNGraph G = TUNGraph::New();
982  G->AddNode(0); G->AddNode(1); G->AddNode(2); G->AddNode(3);
983  G->AddNode(4); G->AddNode(5); G->AddNode(6);
984  G->AddEdge(0,1); G->AddEdge(0,2); G->AddEdge(0,3); G->AddEdge(0,4); G->AddEdge(0,5); G->AddEdge(0,6);
985  G->AddEdge(1,2); G->AddEdge(1,5); G->AddEdge(1,6);
986  G->AddEdge(2,4);
987  TNetConstraint<PUNGraph> NetConstraint(G, true);
988  // NetConstraint.CalcConstraints(0);
989  NetConstraint.Dump();
990  printf("middle node network constraint: %f\n", NetConstraint.GetNodeC(0));
991 }
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New().
Definition: graph.h:172
Definition: bd.h:196

Here is the call graph for this function:

Member Data Documentation

template<class PGraph>
PGraph TNetConstraint< PGraph >::Graph

Definition at line 854 of file triad.h.

template<class PGraph>
THash<TIntPr, TFlt> TNetConstraint< PGraph >::NodePrCH

Definition at line 855 of file triad.h.


The documentation for this class was generated from the following file: