Gurobi (>= 8.1) 能否在 R 接口内解决具有二次等式约束的 ILP?
Can Gurobi (>= 8.1) solve ILP with quadratic equality constraint within R-interface?
来自这个问题的回答 here 3 年前
看来,这是不可能的。 Gurobi 文档对我来说不是很清楚:
quadcon (optional)
...
The optional sense string defines the sense of
the quadratic constrint. Allowed values are <
, =
or >
. If not
present, the default sense is <
. It is stored in
model$quadcon[[i]]$sense
.
constraints 状态
Quadratic Constraints
...
Quadratic equality constraints are always
non-convex; they will give a GRB_ERROR_QCP_EQUALITY_CONSTRAINT
error with default settings.
[...] If you set the NonConvex
parameter to 2, however, then Gurobi will accept arbitrary quadratic
constraints and attempt to solve the resulting model.
但是 NonConvex
在 R 中抛出一个 Error 10007: Unknown parameter: 'NonConvex'
。
感谢任何帮助,可以在下面找到可重现的示例:
library(Matrix)
model <- list(
modelsense = "min",
Q = structure(c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)),
A = structure(c(36, 0, 24, 0, -23, 0, -49, 1), .Dim = c(2L, 4L)),
rhs = c(0, 1),
sense = c("=", ">="),
vtype = "I",
quadcon = list(list(Qc = new("dgTMatrix", i = 0:3, j = 0:3,
Dim = c(4L, 4L),
Dimnames = list(NULL, NULL),
x = c(1, 1, 1, -2),
factors = list()),
# sense = "<=", # works fine
sense = ">=", # Error 10020: Q matrix is not positive semi-definite (PSD)
sense = "=", # Error 10021: Quadratic equality constraints
rhs = 0)))
params <- list(OutputFlag = 0)
result <- gurobi::gurobi(model, params)
print(result$x)
就像mattmilten在评论中已经说过的,有必要升级到9.0版本。然后它应该与
一起工作
params <- list(OutputFlag = 0, NonConvex = 2)
来自这个问题的回答 here 3 年前 看来,这是不可能的。 Gurobi 文档对我来说不是很清楚:
quadcon (optional)
...
The optional sense string defines the sense of the quadratic constrint. Allowed values are<
,=
or>
. If not present, the default sense is<
. It is stored inmodel$quadcon[[i]]$sense
.
constraints 状态
Quadratic Constraints
...
Quadratic equality constraints are always non-convex; they will give aGRB_ERROR_QCP_EQUALITY_CONSTRAINT
error with default settings.
[...] If you set theNonConvex
parameter to 2, however, then Gurobi will accept arbitrary quadratic constraints and attempt to solve the resulting model.
但是 NonConvex
在 R 中抛出一个 Error 10007: Unknown parameter: 'NonConvex'
。
感谢任何帮助,可以在下面找到可重现的示例:
library(Matrix)
model <- list(
modelsense = "min",
Q = structure(c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)),
A = structure(c(36, 0, 24, 0, -23, 0, -49, 1), .Dim = c(2L, 4L)),
rhs = c(0, 1),
sense = c("=", ">="),
vtype = "I",
quadcon = list(list(Qc = new("dgTMatrix", i = 0:3, j = 0:3,
Dim = c(4L, 4L),
Dimnames = list(NULL, NULL),
x = c(1, 1, 1, -2),
factors = list()),
# sense = "<=", # works fine
sense = ">=", # Error 10020: Q matrix is not positive semi-definite (PSD)
sense = "=", # Error 10021: Quadratic equality constraints
rhs = 0)))
params <- list(OutputFlag = 0)
result <- gurobi::gurobi(model, params)
print(result$x)
就像mattmilten在评论中已经说过的,有必要升级到9.0版本。然后它应该与
一起工作params <- list(OutputFlag = 0, NonConvex = 2)