0

I get this error when I run the MWE code below. Does anyone know how to resolve this? thanks!

Error: Error 10020: Q matrix is not positive semi-definite (PSD). Set NonConvex parameter to 2 to solve model.

MWE:

library(gurobi)
library(Matrix)

model <- list()

#optimization problem:
# max x + y
# s.t.
# -x + y <= 0
# x^2 - y^2 <= 10
# 0 <= x < = 20
# 0 <= y <= 20

model$obj <- c(1,1)
model$A <- matrix(c(-1,1), nrow=1, byrow=T) # for LHS of linear constraint: -x + y <= 0
model$rhs <- c(0) # for RHS of linear constraint: -x + y <= 0
model$ub[1] = 20 # x < = 20
model$ub[2] = 20 # y < = 20
model$sense <- c('<')

# non-convex quadratic constraint: x^2 - y^2 <= 10
qc1 <- list()
qc1$Qc <- spMatrix(2, 2, c(1, 2), c(1, 2), c(1.0, -1.0))
qc1$rhs <- 10

model$quadcon <- list(qc1)

#the QC constraint is a non-convex quadratic constraint, so set NonConvex = 2
model$params <- list(NonConvex=2)

gurobi_write(model,'quadtest.lp', env)

result <- gurobi(model)   # THIS IS WHERE I GET THE ERROR ABOVE

print(result$objval)
print(result$x)
sms13
  • 13
  • 3

1 Answers1

0

NM...i see that I can fix this by not putting the params as part of the model list, and instead running it as an input to the gurobi(,) call as follows:

params <- list(NonConvex=2)
result <- gurobi(model, params)
sms13
  • 13
  • 3