我有以下不等式系统:Ay> = 0,其中A是9x3矩阵,y = (y1, y2, y3)
是3个元素的向量。不平等的解决方案是一个区域,但我想返回一个可能解决这个不等式的元组(y1,y2,y3)。注意,y的所有元素都必须是> 0
有没有办法在R?中做到这一点?
由于
A = matrix(runif(27, -0.5, 0.5), nc = 3)
### The system to solve is: A %*% y >= as.matrix(rep(0,9)) Solve for y. Do not return region, but rather any possible tuple that solves the inequalities
答案 0 :(得分:3)
尝试线性编程:
library(Rglpk)
rhs <- rep(c(0, 1e-3), c(9, 3))
ge <- rep(">=", 12)
# an example with no feasible solution (status = 1)
set.seed(123)
A <- rbind(matrix(runif(27, -0.5, 0.5), nc = 3), diag(3))
Rglpk_solve_LP(obj = numeric(3), mat = A, dir = ge, rhs = rhs)
# an example with a feasible solution (status = 0)
A2 <- rbind(cbind(numeric(9), 1, -1), diag(3))
Rglpk_solve_LP(obj = numeric(3), mat = A2, dir = ge, rhs = rhs)