ROI lpsolve插件使用二进制约束得到错误结果

ROI lpsolve插件使用二进制约束得到错误结果,r,knapsack-problem,lpsolve,r-optimization,R,Knapsack Problem,Lpsolve,R Optimization,我正试图通过ROI接口(ROI.plugin.lpsolve)使用lp_solve solver,并获得MIP问题的随机结果 下面是我的示例,我期望0/1二进制解决方案: library(slam) library(ROI) library(ROI.plugin.lpsolve) library(lpSolve) solver = "lpsolve" volume <- c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L

我正试图通过
ROI
接口(
ROI.plugin.lpsolve
)使用lp_solve solver,并获得MIP问题的随机结果

下面是我的示例,我期望0/1二进制解决方案:

library(slam)
library(ROI)
library(ROI.plugin.lpsolve)
library(lpSolve)
solver = "lpsolve"
volume <- c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 
            3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 10L, 10L, 10L, 
            10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L)
profit <- c(20L, 15L, 12L, 10L, 7L, 5L, 5L, 5L, 4L, 3L, 2L, 1L, 0L, 40L, 
            38L, 36L, 35L, 30L, 26L, 25L, 22L, 20L, 17L, 15L, 10L, 5L, 0L, 
            100L, 60L, 40L, 20L, 10L, 5L, 5L, 5L, 5L, 5L, 0L)
cap <- 65

lp <- OP(objective = profit,
         constraints = L_constraint(L = rbind(volume),
                                    dir = c("<="),
                                    rhs = cap),
         maximum = TRUE)
types(lp) <- rep("B", length(volume))

mod <- ROI_solve(lp, solver)
res <- mod$solution
print(res)
# 65  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  
#  0  0  0  0  0  0  0  0
#  0  0  0  0  0  0  0

插件似乎没有正确设置类型向量。

谢谢您指出这一点! 这在新版的
ROI.plugin.lpsolve
,版本0.3-2中得到了修复 自2018年12月20日起在CRAN上运行

问题在于,在
lpSolveAPI
包中,如果首先设置边界或类型,则会产生不同。在
lpSolveAPI
中,应首先设置边界,然后设置类型

# 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0