R/chrom.R

Defines functions chrom

###########################################################
### returning the permutation matrix associated to a permutation ###############

##' @keywords internal
# @examples
#  ########################################################
#  # Loading toy data
#  ########################################################
#  c <- sample(10)
#
#  ########################################################
#  # Transforming in a matrix form
#  ########################################################
#  P <- chrom(c=c)
#
# @title Transform a permutation in a matrix form
# @description Internal function of the genetic algorithm to transform a permutation in a matrix form.
# @param c A permutation from [1,p].
# @return The pxp matrix of permutation associated to c.
# @author \packageAuthor{GADAG}
# @seealso \code{\link{GADAG}}, \code{\link{GADAG_Run}}.
#

chrom <- function(c){
  # INPUTS
  # c: permutation vector (size p)
  #
  # OUTPUTS
  # P: permutation matrix (p*p)

  p <- length(c)
  P <- matrix(0,p,p)
  I <- p*seq(from = 0, to = (p-1), by = 1)+c
  P[I] <- 1
  return(P)
}

Try the GADAG package in your browser

Any scripts or data that you put into this service are public.

GADAG documentation built on May 2, 2019, 3:25 p.m.