library(lpSolve) obj.fun <- c(rep(1,7)) constr <- matrix(c( 8,0,0,8,8,8,8, 8,8,0,0,8,8,8, 8,8,8,0,0,8,8, 8,8,8,8,0,0,8, 8,8,8,8,8,0,0, 0,8,8,8,8,8,0, 0,0,8,8,8,8,8 ), ncol=7, byrow=TRUE) constr.dir <- c(rep(">=",7)) rhs <- c(48,48,52,52,36,24,24) shifts <- lp('min', obj.fun, constr, constr.dir, rhs, all.int=TRUE) shifts shifts$solution shifts$objval