0

I need to solve a mix of equations/inequalities:

a1 + a2 + a3 >= 50
b1 + b2 + b3 <= 40
c1 + c2 + c3 <= 10
a1 + b1 + c1  = 50
a2 + b2 + c2  = 35
a3 + b3 + c3  = 15

There are nine variables and six equations/inequalities, but I will be zeroing three of the variables at a time (I will have to check all combinations).

I tried a couple of packages in R (limSolve, matlib) with no success.

#The matrix representation:
X1 <- c(1,1,1,0,0,0,0,0,0)
X2 <- c(0,0,0,1,1,1,0,0,0)
X3 <- c(0,0,0,0,0,0,1,1,1)
Y1 <- c(1,0,0,1,0,0,1,0,0)
Y2 <- c(0,1,0,0,1,0,0,1,0)
Y3 <- c(0,0,1,0,0,1,0,0,1)
A1 <- matrix(c(X1,X2,X3,Y1,Y2,Y3),c(9,9))
A2 <- t(A1); colnames(A2) <- c("a1","a2","a3","b1","b2","b3","c1","c2","c3")
b <- c(50,40,10,50,35,15)

Any help will be appreciated.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Greg3er
  • 27
  • 6
  • What do you mean by "no success"? What was the failure? – user2974951 Jan 22 '21 at 08:47
  • I was not proficient enough to get any meaningful answer. – Greg3er Jan 22 '21 at 08:48
  • So, when I try solve():
    solve(A2[,-c(2,3,4)], b) I get an Error message:
    : "Error in solve.default(A2[, -c(2, 3, 4)], b) : Lapack routine dgesv: system is exactly singular: U[6,6] = 0". I tried also linp(G=A2[,-c(2,3,4)], H=b, int.vec=c(1,2,3,4,5,6)) but I was not sure how to apply "Cost".
    – Greg3er Jan 22 '21 at 09:30
  • That's because you have more variables than equations, hence solve and other similar procedures cannot be used, numerical (iterative) methods must be used. – user2974951 Jan 22 '21 at 09:32
  • @user2974951 There are nine variables and six equations/inequalities, but I will be zeroing three of the variables at a time (I will have to check all combinations). – Greg3er Jan 22 '21 at 09:33
  • You should explain what exactly you mean by "zeroing" three variables. Why are you doing this, for what purpose? Are you forcing them to be equal to 0? – user2974951 Jan 22 '21 at 09:35
  • @user2974951 Yes, exactly. I will be forcing three of them to be zoreos, so that the rest can be calculated – Greg3er Jan 22 '21 at 09:48
  • This won't save you. You will add three new equations to zero three variables, so you will end up with 9 equations, however three equations are still inequalities, which cannot be used in `solve`. You would have to introduce new variables to transform the inequalities into equalities, which would again result in more variables than equations. – user2974951 Jan 22 '21 at 09:56
  • @user2974951 but if, say, I remove all "a2", "a3" and "b1", then I have six equations/inequalities, and six variables. What I am going to do is then to iterate - turn inequalities into equations, i.e. for (a1 + a2 + a3 >= 50) the ">=50" will be changed to "=50", then "=60" etc.) and, hopefully, I find a function to describe the behaviour of the variables in between the iterated points. – Greg3er Jan 22 '21 at 10:06

1 Answers1

1

This can be solved using linear programming. There is nothing to optimize, you are just searching for a feasible solution.

library(lpSolve)

res=lp(
  "min",
  rep(0,ncol(A2)),
  A2,
  c(">=","<=","<=","==","==","=="),
  b
)

res$solution

[1] 50 35 15  0  0  0  0  0  0
user2974951
  • 9,535
  • 1
  • 17
  • 24