Bulat
Bulat

Reputation: 6969

ROI lpsolve plugin gets wrong result with binary constraint

I am trying to use lp_solve solver through ROI interface (ROI.plugin.lpsolve) and get random result on MIP problem.

Here is my example where I was expecting 0/1 binary solution:

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

Correct solution is:

# 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

It seems that plugin does not set type vector correctly.

Upvotes: 0

Views: 143

Answers (1)

Florian
Florian

Reputation: 663

Thank you for pointing this out! This is fixed in the new version of ROI.plugin.lpsolve, version 0.3-2 on CRAN since 2018-12-20.

The issue was that in the lpSolveAPI package it makes a difference if you set first the bounds or the types. In lpSolveAPI one should first set the bounds and afterwards the types.

Upvotes: 1

Related Questions