当我运行下面的MWE代码时,会得到这个错误。有人知道怎么解决这个问题吗?谢谢!
误差:误差10020: Q矩阵不是半正定的.将NonConvex参数设置为2以求解模型。
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)发布于 2021-12-19 01:29:28
NM.我看到可以通过不将params作为模型列表的一部分来解决这个问题,而是将其作为gurobi(,)调用的输入运行,如下所示:
params <- list(NonConvex=2)
result <- gurobi(model, params)https://stackoverflow.com/questions/70407274
复制相似问题