R/find_simplicial.R

Defines functions find_simplicial

Documented in find_simplicial

#' Find simplicial nodes
#'
#' This function finds all simplicial nodes in a graph. Notice that isolated nodes are treated as
#' simplicial nodes for programming convenience. The output is a vector of node names, ordered by
#' node degree ascending.
#' @param graph A graph that is stored in an adjacency matrix.
#' @keywords simplicial
#' @export

find_simplicial = function(graph) {

  nodes = colnames(graph)
  sim = c()
  degrees = c()
  for (x in nodes) {

    nbrs = names(which(graph[x, ] == 1))
    if (length(nbrs) < 1) {

      sim = c(sim, x)
      degrees = c(degrees, 0)

    } else {

      if (is_simplicial(graph, x)) {

        sim = c(sim, x)
        degrees = c(degrees, length(nbrs))

      }

    }

  }

  if (length(sim) > 1) sim = sim[order(degrees)]

  return(sim)

}
kelvinyangli/wrsgraph documentation built on Sept. 6, 2019, 10 a.m.