tfit.R 1.03 KB
Newer Older
Gosset Simon's avatar
Gosset Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#' tfit
#'
#' Description de tfit
#'
#' @param X Fichier network d'entrée
#' @return Partition du graphe + labels
#'
#' @export
tfit <- function(X)
{
  edges <- read.table(X, header=TRUE)
  nbEdges <- nrow(edges)
  labels <- unique(c(as.character(edges[,1]), as.character(edges[,2])))
  nbVertices <- length(labels)
  integerLabels <- 1:nbVertices
  # NOTE: following inspired by https://stackoverflow.com/a/46251794
  # There should be an easier solution (?!)
  names(integerLabels) <- labels
  integerLabelsList <- split(unname(integerLabels), names(integerLabels))
  adjacencyMatrix <- matrix(FALSE, nbVertices, nbVertices)
  for (i in 1:nbEdges)
  {
    integerEdge1 <- integerLabelsList[[ edges[i,1] ]]
    integerEdge2 <- integerLabelsList[[ edges[i,2] ]]
    adjacencyMatrix[integerEdge1,integerEdge2] <- TRUE
    adjacencyMatrix[integerEdge2,integerEdge1] <- TRUE #symmetric graph
  }
  partition <- .Call("tfit", adjacencyMatrix, PACKAGE = "appinetwork")
29
  result_tfit = list("partition"=partition, "labels"=labels)
Gosset Simon's avatar
Gosset Simon committed
30
  return(result_tfit)
Gosset Simon's avatar
Gosset Simon committed
31
}