Skip to content

Instantly share code, notes, and snippets.

@dirkschumacher
Created May 9, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkschumacher/4c0d8f1681579e828a6fc170759781e8 to your computer and use it in GitHub Desktop.
Save dirkschumacher/4c0d8f1681579e828a6fc170759781e8 to your computer and use it in GitHub Desktop.
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