I am not sure whether this is the right place to ask, but I need to efficiently implement a very large linear programming problem in R
(and there is no way around R
here). I have tried out some packages like lpSolve
but the results seem unsatisfactory. I would be glad for any advice on packages, or alternatively a better place to ask this question.
Here is the problem:
N <- 10^4 # number of products
K <- 10^4 # number of scenarios
### Get expectation and covariance matrix
mu <- rep(100,N)
A <- matrix(rnorm(N^2,0,1), nrow=N, ncol=N)
Sigma <- t(A) %*% A
R <- mvrnorm(K, mu, Sigma) # create scenarios
means <- apply(R, 2, mean) # computes mean for each product
### The LP
# There are some additional constraints to pure expectation maximization
# This leads to additional variables
c <- c(-means,0,rep(0,K))
A1 <- c(rep(1,N),0,rep(0,K))
A2 <- c(rep(0,N),1,-rep((0.05*K)^(-1),K))
A3 <- cbind(R,rep(-1,K),diag(1,K))
A <- rbind(A1,A2,A3)
b <- c(1,98,rep(0,K))
system.time(lp <- lp(direction = "min", objective.in = c, const.mat = A,
const.dir = c("=", ">=", rep(">=",K)), const.rhs = b))