How to obtain the coefficient matrices for a QCQP problem?
回答済みHi,
I wanna obtain the specific coefficient matrices/vectors for a QCQP problem, e.g., QMatrix, QLMatrix, QObjective and QRHS in the attached pic. Is there any API for me to leverage for the coefficient matrices/vectors mentioned?
Thanks

-
Hi Canqi,
Edit: In gurobipy v13 the following functions are introduced: Model.getQ and Model.getQCMatrices. For earlier versions, see the original response below.
There isn't anything in our API to retrieve this data in matrix form, you would have to retrieve it in our “term based” API and construct the matrix, e.g. for your model m:
import scipy.sparse as ss def get_q_matrix(model, qlinexpr): coeffs = [qlinexpr.getCoeff(i) for i in range(qlinexpr.size())] row = [qlinexpr.getVar1(i).index for i in range(qlinexpr.size())] col = [qlinexpr.getVar2(i).index for i in range(qlinexpr.size())] arr = ss.coo_array((coeffs, (row, col)), shape=(model.NumVars, model.NumVars)) return (arr + arr.transpose())/2 get_q_matrix(m, m.getObjective()) # QObjective get_q_matrix(m, m.getQCRow(m.getQConstrs()[0])) # QMatrix for the first quadratic constraintHowever perhaps you don't really need this data in matrix form, e.g. if your looking to find variables or constraints which lead to the extremities of the reported ranges then you can just work with the term-based API without needing to construct matrices.
- Riley
0
サインインしてコメントを残してください。
コメント
1件のコメント