I am making an lp solution but am stuck at defining constraints.
Suppose I have 9 decision variables, {x1,x2...n}
Suppose also I have a constraint that involves a subset of all decision variables:
x1 / (x1+x2+x3) = 40/100
Then how can I write this for lpsolve to use this?
I have tried:
add.constraint(model, c(1,0,0,0,0,0,0,0,0), "=", c(.4,.4,.4,0,0,0,0,0,0))
and
add.constraint(model, c(0.4,0,0,0,0,0,0,0,0), "=", c(1,1,1,0,0,0,0,0,0))
Thanks in advance.
Assuming that you meant (x1+x2+x3) we have
x1 / (x1+x2+x3) = 40/100
is equivalent to
x1 = (40/100) (x1+x2+x3)
which is equivalent to
(1-40/100)x1 - (40/100)x2 - (40/100)x3 = 0
In order to get a complete problem assume that the objective is ones
below and also add 9 constraints x[i] <= 1, i = 1, ..., 9 in which case we have the following for a maximization problem:
library(lpSolve)
ones <- rep(1, 9)
a <- c(1-40/100, -40/100, -40/100, 0, 0, 0, 0, 0, 0)
A <- rbind(a, diag(9))
lp("max", ones, A, c("=", rep("<=", 9)), c(0, ones))