SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
localmotifcluster.cpp File Reference
#include "localmotifcluster.h"
#include "stdafx.h"

Go to the source code of this file.

Functions

MotifType ParseMotifType (const TStr &motif, const bool &IsDirected)
 
void printMotifType (const MotifType &type)
 
int getCliqueSize (const MotifType &type)
 
bool higherDeg (PUNGraph &G, TUNGraph::TNodeI &NI1, int nodeID2)
 
bool higherDeg (PUNGraph &G, int nodeID1, int nodeID2)
 
int checkEdge (PNGraph &G, long nodeID, long nbrID)
 
int checkTriadMotif (PNGraph &G, long nodeID, long srcNId, long dstNId)
 
bool higherDeg (PNGraph &G, TNGraph::TNodeI &NI1, int nodeID2)
 
bool higherDeg (PNGraph &G, int nodeID1, int nodeID2)
 

Function Documentation

int checkEdge ( PNGraph G,
long  nodeID,
long  nbrID 
)

Definition at line 259 of file localmotifcluster.cpp.

259  {
260  if (G->IsEdge(nodeID, nbrID)) {
261  if (G->IsEdge(nbrID, nodeID)) {
262  return 0;
263  } else {
264  return 1;
265  }
266  } else {
267  return 2;
268  }
269 }
int checkTriadMotif ( PNGraph G,
long  nodeID,
long  srcNId,
long  dstNId 
)

Definition at line 273 of file localmotifcluster.cpp.

273  {
274  int motifType = 0;
275  if (G->IsEdge(dstNId, srcNId)) {
276  switch (checkEdge(G, nodeID, dstNId)) {
277  case 0: {
278  switch (checkEdge(G, nodeID, srcNId)) {
279  case 0: {
280  motifType = 4;
281  break;
282  }
283  case 1: {
284  motifType = 3;
285  break;
286  }
287  case 2: {
288  motifType = 3;
289  }
290  }
291  break;
292  }
293  case 1: {
294  switch (checkEdge(G, nodeID, srcNId)) {
295  case 0: {
296  motifType = 3;
297  break;
298  }
299  case 1: {
300  motifType = 6;
301  break;
302  }
303  case 2: {
304  motifType = 2;
305  }
306  }
307  break;
308  }
309  case 2: {
310  switch (checkEdge(G, nodeID, srcNId)) {
311  case 0: {
312  motifType = 3;
313  break;
314  }
315  case 1: {
316  motifType = 2;
317  break;
318  }
319  case 2: {
320  motifType = 7;
321  }
322  }
323  }
324  }
325  } else {
326  switch (checkEdge(G, nodeID, dstNId)) {
327  case 0: {
328  switch (checkEdge(G, nodeID, srcNId)) {
329  case 0: {
330  motifType = 3;
331  break;
332  }
333  case 1: {
334  motifType = 2;
335  break;
336  }
337  case 2: {
338  motifType = 6;
339  }
340  }
341  break;
342  }
343  case 1: {
344  switch (checkEdge(G, nodeID, srcNId)) {
345  case 0: {
346  motifType = 7;
347  break;
348  }
349  case 1: {
350  motifType = 5;
351  break;
352  }
353  case 2: {
354  motifType = 5;
355  }
356  }
357  break;
358  }
359  case 2: {
360  switch (checkEdge(G, nodeID, srcNId)) {
361  case 0: {
362  motifType = 2;
363  break;
364  }
365  case 1: {
366  motifType = 1;
367  break;
368  }
369  case 2: {
370  motifType = 5;
371  }
372  }
373  }
374  }
375  }
376  return motifType;
377 }
int checkEdge(PNGraph &G, long nodeID, long nbrID)
int getCliqueSize ( const MotifType type)

Definition at line 88 of file localmotifcluster.cpp.

88  {
89  switch (type) {
90  case UEdge: return 2;
91  case clique3: return 3;
92  case clique4: return 4;
93  case clique5: return 5;
94  case clique6: return 6;
95  case clique7: return 7;
96  case clique8: return 8;
97  case clique9: return 9;
98  default: {
99  TExcept::Throw("Unknown motif for undirected graph!");
100  return -1;
101  }
102  }
103 }
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
bool higherDeg ( PUNGraph G,
TUNGraph::TNodeI NI1,
int  nodeID2 
)

Definition at line 125 of file localmotifcluster.cpp.

125  {
126  TUNGraph::TNodeI NI2 = G->GetNI(nodeID2);
127  if (NI1.GetOutDeg() > NI2.GetOutDeg()) {
128  return true;
129  } else if (NI1.GetOutDeg() == NI2.GetOutDeg() && NI1.GetId() > nodeID2) {
130  return true;
131  } else {
132  return false;
133  }
134 }
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:68
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
Definition: graph.h:94
int GetId() const
Returns ID of the current node.
Definition: graph.h:88
bool higherDeg ( PUNGraph G,
int  nodeID1,
int  nodeID2 
)

Definition at line 135 of file localmotifcluster.cpp.

135  {
136  TUNGraph::TNodeI NI1 = G->GetNI(nodeID1);
137  return higherDeg(G, NI1, nodeID2);
138 }
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:68
bool higherDeg(PUNGraph &G, TUNGraph::TNodeI &NI1, int nodeID2)
bool higherDeg ( PNGraph G,
TNGraph::TNodeI NI1,
int  nodeID2 
)

Definition at line 382 of file localmotifcluster.cpp.

382  {
383  TNGraph::TNodeI NI2 = G->GetNI(nodeID2);
384  if (NI1.GetOutDeg() > NI2.GetOutDeg()) {
385  return true;
386  } else if (NI1.GetOutDeg() == NI2.GetOutDeg() && NI1.GetId() > nodeID2) {
387  return true;
388  } else {
389  return false;
390  }
391 }
int GetId() const
Returns ID of the current node.
Definition: graph.h:400
int GetOutDeg() const
Returns out-degree of the current node.
Definition: graph.h:406
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:383
bool higherDeg ( PNGraph G,
int  nodeID1,
int  nodeID2 
)

Definition at line 392 of file localmotifcluster.cpp.

392  {
393  TNGraph::TNodeI NI1 = G->GetNI(nodeID1);
394  return higherDeg(G, NI1, nodeID2);
395 }
bool higherDeg(PUNGraph &G, TUNGraph::TNodeI &NI1, int nodeID2)
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:383
MotifType ParseMotifType ( const TStr motif,
const bool &  IsDirected 
)

Definition at line 20 of file localmotifcluster.cpp.

20  {
21  TStr motif_lc = motif.GetLc();
22  if (IsDirected) {
23  if (motif_lc == "m1") { return M1; }
24  else if (motif_lc == "m2") { return M2; }
25  else if (motif_lc == "m3") { return M3; }
26  else if (motif_lc == "m4") { return M4; }
27  else if (motif_lc == "m5") { return M5; }
28  else if (motif_lc == "m6") { return M6; }
29  else if (motif_lc == "m7") { return M7; }
30  else if (motif_lc == "triad") { return triad; }
31  else if (motif_lc == "cycle") { return cycle; }
32  else if (motif_lc == "ffloop") { return FFLoop; }
33  else if (motif_lc == "unide") { return UniDE; }
34  else if (motif_lc == "bide") { return BiDE; }
35  else if (motif_lc == "de") { return DE; }
36  else if (motif_lc == "edge") { return DE_any; }
37  else {
38  TExcept::Throw("Unknown motif for directed graph!");
39  }
40  } else {
41  if (motif_lc == "uedge") { return UEdge; }
42  else if (motif_lc == "clique3") { return clique3; }
43  else if (motif_lc == "clique4") { return clique4; }
44  else if (motif_lc == "clique5") { return clique5; }
45  else if (motif_lc == "clique6") { return clique6; }
46  else if (motif_lc == "clique7") { return clique7; }
47  else if (motif_lc == "clique8") { return clique8; }
48  else if (motif_lc == "clique9") { return clique9; }
49  else { TExcept::Throw("Unknown motif for undirected graph!"); }
50  }
51  TExcept::Throw("Inappropriate input!");
52  return UEdge;
53 }
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
TStr GetLc() const
Definition: dt.h:502
Definition: dt.h:412
void printMotifType ( const MotifType type)

Definition at line 56 of file localmotifcluster.cpp.

56  {
57  switch (type) {
58  case M1: printf("M1\n"); break;
59  case M2: printf("M2\n"); break;
60  case M3: printf("M3\n"); break;
61  case M4: printf("M4\n"); break;
62  case M5: printf("M5\n"); break;
63  case M6: printf("M6\n"); break;
64  case M7: printf("M7\n"); break;
65  case triad: printf("triad\n"); break;
66  case cycle: printf("cycle\n"); break;
67  case FFLoop: printf("FFLoop\n"); break;
68  case UniDE: printf("UniDE\n"); break;
69  case BiDE: printf("BiDE\n"); break;
70  case DE: printf("DE\n"); break;
71  case DE_any: printf("DE_any\n"); break;
72 
73  case UEdge: printf("UEdge\n"); break;
74  case clique3: printf("clique3\n"); break;
75  case clique4: printf("clique4\n"); break;
76  case clique5: printf("clique5\n"); break;
77  case clique6: printf("clique6\n"); break;
78  case clique7: printf("clique7\n"); break;
79  case clique8: printf("clique8\n"); break;
80  case clique9: printf("clique9\n"); break;
81 
82  default:
83  TExcept::Throw("Unknown motif type!");
84  }
85 }
static void Throw(const TStr &MsgStr)
Definition: ut.h:187