convertNodePair function

Convert node pair (i,j)(i,j)

Convert node pair (i,j)(i,j)

Convert node pair (i,j)(i,j) into an index

  • Directed case :: * The node pair (i,j)(i,j) with (ij)(i\neq j) is converted into the index (i1)(n1)+j(i\<j)(i-1)*(n-1)+j-(i\<j)
  • Undirected case :: * The node pair (i,j)(i,j) with (ij)(i\neq j) is converted into the index (2ni)(i1)/2+ji(2*n-i)*(i-1)/2 +j-i
convertNodePair(i, j, n, directed)

Arguments

  • i: Node ii : i1,,ni\in {1, \ldots, n}
  • j: Node jj : j1,,nj\in {1, \ldots, n}
  • n: Total number of nodes : i,j1,,ni,j\in {1, \ldots, n}
  • directed: Boolean for directed (TRUE) or undirected (FALSE) case

Returns

Index corresponding to the node pair

Details

The number of possible node pairs is

  • N=n(n1)N = n*(n-1) for the directed case
  • N=n(n1)/2N = n*(n-1)/2 for the undirected case

which corresponds to the cardinality of data$type.seq

Examples

# Convert the node pair (3,7) into an index, where the total number of nodes is 10, # for directed and undirected graph i <- 3 j <- 7 n <- 10 directedIndex <- convertNodePair(i,j,n,TRUE) undirectedIndex <- convertNodePair(i,j,n,FALSE)