Bounds on binary variables seem to be ignored in ROI (ROI_0.2-1)
# Bug report | |
# It seems variable bounds are ignored when using binary variables "B". | |
# It works as expected if variables of type "I" are used | |
library(ROI) | |
library(ROI.plugin.glpk) | |
# max: x1 + x2 + x3 + x4 | |
# s.t. x1 + x2 + x3 + x4 <= 4 | |
# 0 <= x1 <= 0 | |
# 0 <= x2 <= 1 | |
# 0 <= x3 <= 1 | |
# 0 <= x4 <= 0 | |
bounds <- ROI::V_bound( | |
ui = c(1, 2, 3, 4), | |
ub = c(0, 1, 1, 0) | |
) | |
constraints <- ROI::L_constraint(L = matrix(c(1, 1, 1, 1), ncol = 4), | |
dir = "<=", | |
rhs = 4) | |
op <- ROI::OP(c(1, 1, 1, 1), | |
constraints, | |
bounds = bounds, | |
types = c("B", "B", "B", "B"), | |
max = TRUE) | |
resultB <- ROI::ROI_solve(op, "glpk") | |
# expected c(0, 1, 1, 0) | |
resultB$solution | |
op <- ROI::OP(c(1, 1, 1, 1), | |
constraints, | |
bounds = bounds, | |
types = c("I", "I", "I", "I"), | |
max = TRUE) | |
resultI <- ROI::ROI_solve(op, "glpk") | |
# expected c(0, 1, 1, 0) | |
resultI$solution | |
stopifnot(resultB$solution != resultI$solution) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment