Gurobi(> = 8.1)可以在R接口内求解具有二次等式约束的ILP吗?

Can Gurobi (>= 8.1) solve ILP with quadratic equality constraint within R-interface?

从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.

约束状态

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'
感谢您的帮助,以下是可复制的示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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版。然后它应该与

1
params <- list(OutputFlag = 0, NonConvex = 2)