2

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 in model$quadcon[[i]]$sense.

constraints state

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.

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)
Christoph
  • 6,841
  • 4
  • 37
  • 89

1 Answers1

1

Like mattmilten already said in the comments, it's necessary to upgrade to version 9.0. Then it should work with

params <- list(OutputFlag = 0, NonConvex = 2)
joni
  • 6,840
  • 2
  • 13
  • 20