Programming
AnsweredSo I have a minimization problem, my Zi are (-1,0,1), originally I'm trying to minimize ZTWZ, it works fine, and now I want to add an additional constraint, the sum of Zi^2 is less than a number m. m is predetermined. I tried this: I added a sparse matrix Q and calculate ZTQZ which is the sum of Zi^2, but it doesn't work for me, this is my code(R):
Qc <- sparseMatrix(i = 1:n, j = 1:n, x = 1)
model$quadcon <- list(Q = Qc, sense = "<", rhs = m)
but it doesn't work, it says
Error: is.list(model$quadcon[[i]]) == FALSE
I tried then model$quadcon <- list(list(Q = Qc, sense = "<", rhs = m))
then it says
Error: length(model$quadcon[[i]]$Qc) == 0
Could you please tell me how to fix it?
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
The \(\texttt{quadcon}\) named component should be a list of lists. For each element/list, the \(\texttt{Qc}\) named component defines the matrix for the corresponding quadratic constraint. The following should work:
model$quadcon <- list(list(Qc = Qc, sense = "<", rhs = m))
See the The model argument section of the R documentation for more details.
0
Post is closed for comments.
Comments
2 comments