| 
    SNAP Library 2.0, Developer Reference
    2013-05-13 16:33:57
    
   SNAP, a general purpose, high performance system for analysis and manipulation of large networks 
   | 
  
  
  
 
#include <triad.h>

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, TFlt > | NodePrCH | 
| TNetConstraint< PGraph >::TNetConstraint | ( | const PGraph & | GraphPt, | 
| const bool & | CalcaAll = true  | 
        ||
| ) | 
Definition at line 471 of file triad.h.
References TNetConstraint< PGraph >::CalcConstraints(), CAssert, gfMultiGraph, and HasGraphFlag.
: Graph(GraphPt) { CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); // must not be multigraph if (CalcaAll) { CalcConstraints(); } }

| void TNetConstraint< PGraph >::AddConstraint | ( | const int & | NId1, | 
| const int & | NId2 | ||
| ) | 
Definition at line 507 of file triad.h.
References TMath::Sqr().
                                                                           {
  if (NId1==NId2 || NodePrCH.IsKey(TIntPr(NId1, NId2))) {
    return;
  }
  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId1);
  double Constraint = 0.0;
  if (NI1.IsOutNId(NId2)) { // is direct edge
    Constraint += 1.0/(double) NI1.GetOutDeg();
  }
  const double SrcC = 1.0/(double) NI1.GetOutDeg();
  for (int e = 0; e < NI1.GetOutDeg(); e++) {
    const int MidNId = NI1.GetOutNId(e);
    if (MidNId == NId1 || MidNId == NId2) { continue; }
    const typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(MidNId);
    if (MidNI.IsOutNId(NId2)) {
      Constraint += SrcC * (1.0/(double)MidNI.GetOutDeg());
    }
  }
  if (Constraint==0) { return; }
  Constraint = TMath::Sqr(Constraint);
  NodePrCH.AddDat(TIntPr(NId1, NId2), Constraint);
}

| void TNetConstraint< PGraph >::CalcConstraints | ( | ) | 
Definition at line 531 of file triad.h.
Referenced by TNetConstraint< PGraph >::TNetConstraint().
                                             {
  // add edges
  for (typename PGraph::TObj::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    AddConstraint(EI.GetSrcNId(), EI.GetDstNId());
    AddConstraint(EI.GetDstNId(), EI.GetSrcNId());
  }
  // add open triads
  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    for (int i = 0; i < NI.GetDeg();  i++) {
      const int NId1 = NI.GetNbrNId(i);
      for (int j = 0; j < NI.GetDeg();  j++) {
        const int NId2 = NI.GetNbrNId(j);
        AddConstraint(NId1, NId2);
      }
    }
  }
  NodePrCH.SortByKey();
}

| void TNetConstraint< PGraph >::CalcConstraints | ( | const int & | NId | ) | 
Definition at line 552 of file triad.h.
References THashSet< TKey, THashFunc >::AddKey(), and THashSet< TKey, THashFunc >::IsKey().
                                                           {
  typename PGraph::TObj::TNodeI StartNI = Graph->GetNI(NId);
  TIntSet SeenSet;
  for (int e = 0; e < StartNI.GetOutDeg(); e++) {
    typename PGraph::TObj::TNodeI MidNI = Graph->GetNI(StartNI.GetOutNId(e));
    AddConstraint(NId, MidNI.GetId());
    for (int i = 0; i < MidNI.GetOutDeg();  i++) {
      const int EndNId = MidNI.GetOutNId(i);
      if (! SeenSet.IsKey(EndNId)) {
        AddConstraint(NId, EndNId);
        SeenSet.AddKey(EndNId);
      }
    }
  }
}

| void TNetConstraint< PGraph >::Dump | ( | ) | const | 
Definition at line 569 of file triad.h.
Referenced by TNetConstraint< PGraph >::Test().
                                        {
  printf("Edge network constraint: (%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
  for (int e = 0; e < NodePrCH.Len(); e++) {
    printf("  %4d %4d  :  %f\n", NodePrCH.GetKey(e).Val1(), NodePrCH.GetKey(e).Val2(), NodePrCH[e].Val);
  }
  printf("\n");
}

| double TNetConstraint< PGraph >::GetC | ( | const int & | ConstraintN | ) |  const [inline] | 
        
Definition at line 459 of file triad.h.
References TNetConstraint< PGraph >::NodePrCH.
{ return NodePrCH[ConstraintN]; }
| double TNetConstraint< PGraph >::GetEdgeC | ( | const int & | NId1, | 
| const int & | NId2 | ||
| ) | const | 
| double TNetConstraint< PGraph >::GetNodeC | ( | const int & | NId | ) | const | 
Definition at line 487 of file triad.h.
Referenced by TNetConstraint< PGraph >::Test().
                                                            {
  typename PGraph::TObj::TNodeI NI1 = Graph->GetNI(NId);
  if (NI1.GetOutDeg() == 0) { return 0.0; }
  int KeyId = -1;
  for (int k = 0; k<NI1.GetOutDeg(); k++) {
    KeyId = NodePrCH.GetKeyId(TIntPr(NI1.GetId(), NI1.GetOutNId(k)));
    if (KeyId > -1) { break; }
  }
  if (KeyId < 0) { return 0.0; }
  double Constraint = NodePrCH[KeyId];
  for (int i = KeyId-1; i >-1 && NodePrCH.GetKey(i).Val1()==NId; i--) {
    Constraint += NodePrCH[i];
  }
  for (int i = KeyId+1; i < NodePrCH.Len() && NodePrCH.GetKey(i).Val1()==NId; i++) {
    Constraint += NodePrCH[i];
  }
  return Constraint;
}

| TIntPr TNetConstraint< PGraph >::GetNodePr | ( | const int & | ConstraintN | ) |  const [inline] | 
        
Definition at line 460 of file triad.h.
References THash< TKey, TDat, THashFunc >::GetKey(), and TNetConstraint< PGraph >::NodePrCH.

| int TNetConstraint< PGraph >::Len | ( | ) |  const [inline] | 
        
Definition at line 458 of file triad.h.
References THash< TKey, TDat, THashFunc >::Len(), and TNetConstraint< PGraph >::NodePrCH.

| void TNetConstraint< PGraph >::Test | ( | ) |  [static] | 
        
Definition at line 580 of file triad.h.
References TUNGraph::AddEdge(), TUNGraph::AddNode(), TNetConstraint< PGraph >::Dump(), TNetConstraint< PGraph >::GetNodeC(), and TUNGraph::New().
                                  {
  PUNGraph G = TUNGraph::New();
  G->AddNode(0); G->AddNode(1); G->AddNode(2); G->AddNode(3);
  G->AddNode(4); G->AddNode(5); G->AddNode(6);
  G->AddEdge(0,1); G->AddEdge(0,2); G->AddEdge(0,3); G->AddEdge(0,4); G->AddEdge(0,5); G->AddEdge(0,6);
  G->AddEdge(1,2); G->AddEdge(1,5);  G->AddEdge(1,6);
  G->AddEdge(2,4);
  TNetConstraint<PUNGraph> NetConstraint(G, true);
  // NetConstraint.CalcConstraints(0);
  NetConstraint.Dump();
  printf("middle node network constraint: %f\n", NetConstraint.GetNodeC(0));
}

| PGraph TNetConstraint< PGraph >::Graph | 
| THash<TIntPr, TFlt> TNetConstraint< PGraph >::NodePrCH | 
Definition at line 455 of file triad.h.
Referenced by TNetConstraint< PGraph >::GetC(), TNetConstraint< PGraph >::GetNodePr(), and TNetConstraint< PGraph >::Len().