lpSolve 解决整数规划问题

lpSolve to solving an Integer programming problem

用 R 求解整数规划问题,模型为:

# variables: x1, x2, x3
max z = 25000x1 + 18000x2 + 31000x3

s.t.:
x1 + x2 + x3 = 100
5000x1 + 11000x2 + 7000x3  <= 700000
x1 >= 10
x2 >= 10
x3 >= 10

x1, x2, x3  є {0,1}

在 R 中,我有如下几行:

library(lpSolve)

f.obj <- c(25000, 18000, 31000)

f.con <- matrix(c(1,1,1,
              5000,11000,7000,
              1,0,0,
              0,1,0,
              0,0,1), nrow = 5, byrow = TRUE)

f.dir <- c("=", "<=", ">=", ">=", ">=")

f.rhs <- c(100, 700000, 10, 10, 10)

# Final value (z)
lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:5, all.bin = TRUE)

# Variables final values
lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:5, all.bin = TRUE)$solution

我希望(给出的)正确答案是:

Z = 2850000 when x1 = 20, x2 = 10, x3 = 70. 

但以上代码returns:

Error: no feasible solution found

哪里出了问题,我该如何纠正?谢谢!

根据 lpSolve 的文档,参数 all.bin 指定是否所有变量都是二进制的。正确的叫法应该是

lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:5, all.int = TRUE)