簡體   English   中英

如何在 R 的 Gurobi 中設置 NonConvex = 2?

[英]How to set NonConvex = 2 in Gurobi in R?

當我運行下面的 MWE 代碼時出現此錯誤。 有誰知道如何解決這個問題? 謝謝!

錯誤:錯誤 10020:Q 矩陣不是半正定 (PSD)。 將 NonConvex 參數設置為 2 以求解 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)

NM ...我看到我可以通過不將參數作為 model 列表的一部分來解決此問題,而是將其作為 gurobi(,) 調用的輸入運行,如下所示:

params <- list(NonConvex=2)
result <- gurobi(model, params)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM