I am struggling to use the lp() function, from lpSolve() with a series of constraints. In particular, I want to add a non-zero constraint to all elements of the solution.
The data:
q <- c(6,3,6,6,6,6,3,5)
Q <- 5
I want to find a set of 8 weights that make Q a weighted sum of q. The following works OK:
obj.fun <- rep(1,8)
constr <- rbind(q,rep(1,8))
constr.dir <- c("==","==")
rhs <- c(Q,1)
p.start <- lp("max",obj.fun,constr,constr.dir,rhs)$sol
But I want the solution to be all 8 weights (p.start) as non-zero. I have tried:
obj.fun <- rep(1,8)
constr <- rbind(q,rep(1,8),diag(nrow=8))
constr.dir <- c("==","==",">")
rhs <- c(Q,1,rep(0,8))
p.start <- lp("max",obj.fun,constr,constr.dir,rhs)$sol
But I get an error, and the solution still has 6 of the weights as zero. Can anyone help me get this constraint in correctly?