SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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 803 of file triad.h.

Constructor & Destructor Documentation

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

Definition at line 822 of file triad.h.

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

822  : Graph(GraphPt) {
823  CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // must not be multigraph
824  if (CalcaAll) {
825  CalcConstraints();
826  }
827 }
void CalcConstraints()
Definition: triad.h:882
PGraph Graph
Definition: triad.h:805
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 858 of file triad.h.

References TMath::Sqr().

858  {
859  if (NId1==NId2 || NodePrCH.IsKey(TIntPr(NId1, NId2))) {
860  return;
861  }
862  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
863  double Constraint = 0.0;
864  if (NI1.IsOutNId(NId2)) { // is direct edge
865  Constraint += 1.0/(double) NI1.GetOutDeg();
866  }
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());
874  }
875  }
876  if (Constraint==0) { return; }
877  Constraint = TMath::Sqr(Constraint);
878  NodePrCH.AddDat(TIntPr(NId1, NId2), Constraint);
879 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
PGraph Graph
Definition: triad.h:805
static double Sqr(const double &x)
Definition: xmath.h:12
Definition: ds.h:32
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:806
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 882 of file triad.h.

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

882  {
883  // add edges
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());
887  }
888  // add open triads
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);
895  }
896  }
897  }
899 }
PGraph Graph
Definition: triad.h:805
void AddConstraint(const int &NId1, const int &NId2)
Definition: triad.h:858
void SortByKey(const bool &Asc=true)
Definition: hash.h:291
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:806

Here is the caller graph for this function:

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

Definition at line 903 of file triad.h.

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

903  {
904  typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
905  TIntSet SeenSet;
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);
913  SeenSet.AddKey(EndNId);
914  }
915  }
916  }
917 }
PGraph Graph
Definition: triad.h:805
bool IsKey(const TKey &Key) const
Definition: shash.h:1148
void AddConstraint(const int &NId1, const int &NId2)
Definition: triad.h:858
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 920 of file triad.h.

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

920  {
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);
924  }
925  printf("\n");
926 }
PGraph Graph
Definition: triad.h:805
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:806
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 810 of file triad.h.

References TNetConstraint< PGraph >::NodePrCH.

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

Definition at line 830 of file triad.h.

830  {
831  if (NodePrCH.IsKey(TIntPr(NId1, NId2))) {
832  return NodePrCH.GetDat(TIntPr(NId1, NId2)); }
833  else {
834  return 0.0; }
835 }
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:806
bool IsKey(const TKey &Key) const
Definition: hash.h:258
template<class PGraph >
double TNetConstraint< PGraph >::GetNodeC ( const int &  NId) const

Definition at line 838 of file triad.h.

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

838  {
839  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
840  if (NI1.GetOutDeg() == 0) { return 0.0; }
841  int KeyId = -1;
842  for (int k = 0; k<NI1.GetOutDeg(); k++) {
843  KeyId = NodePrCH.GetKeyId(TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
844  if (KeyId > -1) { break; }
845  }
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];
850  }
851  for (int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
852  Constraint += NodePrCH[i];
853  }
854  return Constraint;
855 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
PGraph Graph
Definition: triad.h:805
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
TVal1 Val1
Definition: ds.h:34
THash< TIntPr, TFlt > NodePrCH
Definition: triad.h:806
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 811 of file triad.h.

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

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

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

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

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

931  {
932  PUNGraph G = TUNGraph::New();
933  G->AddNode(0); G->AddNode(1); G->AddNode(2); G->AddNode(3);
934  G->AddNode(4); G->AddNode(5); G->AddNode(6);
935  G->AddEdge(0,1); G->AddEdge(0,2); G->AddEdge(0,3); G->AddEdge(0,4); G->AddEdge(0,5); G->AddEdge(0,6);
936  G->AddEdge(1,2); G->AddEdge(1,5); G->AddEdge(1,6);
937  G->AddEdge(2,4);
938  TNetConstraint<PUNGraph> NetConstraint(G, true);
939  // NetConstraint.CalcConstraints(0);
940  NetConstraint.Dump();
941  printf("middle node network constraint: %f\n", NetConstraint.GetNodeC(0));
942 }
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 805 of file triad.h.

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

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