SNAP Library 4.1, Developer Reference  2018-07-26 16:30:42
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 840 of file triad.h.

Constructor & Destructor Documentation

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

Definition at line 859 of file triad.h.

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

859  : Graph(GraphPt) {
860  CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // must not be multigraph
861  if (CalcaAll) {
862  CalcConstraints();
863  }
864 }
void CalcConstraints()
Definition: triad.h:919
PGraph Graph
Definition: triad.h:842
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 895 of file triad.h.

References TMath::Sqr().

895  {
896  if (NId1==NId2 || NodePrCH.IsKey(TIntPr(NId1, NId2))) {
897  return;
898  }
899  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
900  double Constraint = 0.0;
901  if (NI1.IsOutNId(NId2)) { // is direct edge
902  Constraint += 1.0/(double) NI1.GetOutDeg();
903  }
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());
911  }
912  }
913  if (Constraint==0) { return; }
914  Constraint = TMath::Sqr(Constraint);
915  NodePrCH.AddDat(TIntPr(NId1, NId2), Constraint);
916 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
PGraph Graph
Definition: triad.h:842
static double Sqr(const double &x)
Definition: xmath.h:12
Definition: ds.h:32
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:843
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 919 of file triad.h.

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

919  {
920  // add edges
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());
924  }
925  // add open triads
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);
932  }
933  }
934  }
936 }
PGraph Graph
Definition: triad.h:842
void AddConstraint(const int &NId1, const int &NId2)
Definition: triad.h:895
void SortByKey(const bool &Asc=true)
Definition: hash.h:291
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:843

Here is the caller graph for this function:

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

Definition at line 940 of file triad.h.

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

940  {
941  typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
942  TIntSet SeenSet;
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);
950  SeenSet.AddKey(EndNId);
951  }
952  }
953  }
954 }
PGraph Graph
Definition: triad.h:842
bool IsKey(const TKey &Key) const
Definition: shash.h:1148
void AddConstraint(const int &NId1, const int &NId2)
Definition: triad.h:895
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 957 of file triad.h.

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

957  {
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);
961  }
962  printf("\n");
963 }
PGraph Graph
Definition: triad.h:842
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:843
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 847 of file triad.h.

References TNetConstraint< PGraph >::NodePrCH.

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

Definition at line 867 of file triad.h.

867  {
868  if (NodePrCH.IsKey(TIntPr(NId1, NId2))) {
869  return NodePrCH.GetDat(TIntPr(NId1, NId2)); }
870  else {
871  return 0.0; }
872 }
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:843
bool IsKey(const TKey &Key) const
Definition: hash.h:258
template<class PGraph >
double TNetConstraint< PGraph >::GetNodeC ( const int &  NId) const

Definition at line 875 of file triad.h.

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

875  {
876  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
877  if (NI1.GetOutDeg() == 0) { return 0.0; }
878  int KeyId = -1;
879  for (int k = 0; k<NI1.GetOutDeg(); k++) {
880  KeyId = NodePrCH.GetKeyId(TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
881  if (KeyId > -1) { break; }
882  }
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];
887  }
888  for (int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
889  Constraint += NodePrCH[i];
890  }
891  return Constraint;
892 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
PGraph Graph
Definition: triad.h:842
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
TVal1 Val1
Definition: ds.h:34
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:843
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 848 of file triad.h.

References THash< TKey, TDat, THashFunc >::GetKey(), and TNetConstraint< PGraph >::NodePrCH.

848 { return NodePrCH.GetKey(ConstraintN); }
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:843
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 846 of file triad.h.

References THash< TKey, TDat, THashFunc >::Len(), and TNetConstraint< PGraph >::NodePrCH.

846 { return NodePrCH.Len(); }
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:843
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 968 of file triad.h.

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

968  {
969  PUNGraph G = TUNGraph::New();
970  G->AddNode(0); G->AddNode(1); G->AddNode(2); G->AddNode(3);
971  G->AddNode(4); G->AddNode(5); G->AddNode(6);
972  G->AddEdge(0,1); G->AddEdge(0,2); G->AddEdge(0,3); G->AddEdge(0,4); G->AddEdge(0,5); G->AddEdge(0,6);
973  G->AddEdge(1,2); G->AddEdge(1,5); G->AddEdge(1,6);
974  G->AddEdge(2,4);
975  TNetConstraint<PUNGraph> NetConstraint(G, true);
976  // NetConstraint.CalcConstraints(0);
977  NetConstraint.Dump();
978  printf("middle node network constraint: %f\n", NetConstraint.GetNodeC(0));
979 }
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 842 of file triad.h.

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

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