R/transformObjectiveFunction.R

Defines functions transformObjectiveFunction

## Vectorizing the objective function
##
## Enio Gjerga, 2020

transformObjectiveFunction <- function(mt = mt, lpFile = lpFile){
  
  matrixProblem <- matrix(data = , nrow = 1, ncol = nrow(mt))
  idx <- which(grepl(pattern = "Obj:", x = lpFile$`enter Problem`))
  
  problem <- as.character(lpFile[idx, ])
  problem <- gsub(pattern = "Obj:\t ", replacement = "", x = problem, 
                  fixed = TRUE)
  
  coefficients <- as.numeric(
    unlist(
      lapply(
        strsplit(
          x = strsplit(
            x = problem, split = "+ ", fixed = TRUE)[[1]], 
          split = " ", fixed = TRUE), "[[", 1)))
  
  varID <- as.character(
    unlist(
      lapply(
        strsplit(
          x = strsplit(
            x = problem, split = "+ ", fixed = TRUE)[[1]], 
          split = " ", fixed = TRUE), "[[", 2)))
  
  idx <- rep(NA, length(varID))
  for(ii in seq_len(length(varID))){
    idx[ii] = which(mt[, 1]==varID[ii])
  }
  
  f.obj = rep(0, nrow(mt))
  f.obj[idx] = coefficients
  
  return(f.obj)
}

Try the CARNIVAL package in your browser

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

CARNIVAL documentation built on Nov. 8, 2020, 5:24 p.m.