From the answer to this question here 3 years ago it seems, this is not possible. The Gurobi documentation is not clear ro me:
the model argument state
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 state
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.
But NonConvex
throws an Error 10007: Unknown parameter: 'NonConvex'
in R.
Any help is appreciated, a reproducible example can be found below:
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)