int GRBgetq ( GRBmodel *model,
    int *numqnzP,
    int *qrow,
    int *qcol,
    double *qval )

Retrieve all quadratic objective terms. The qrow, qcol, and qval arguments must be large enough to hold the result. You can query the NumQNZs attribute to determine how many terms will be returned.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the quadratic objective terms. Refer to the Error Code table for a list of possible return values. Details on the error can be obtained by calling GRBgeterrormsg.


model: The model from which the quadratic objective terms should be retrieved.

numqnzP: The number of quadratic objective terms retrieved.

qrow: Row indices associated with quadratic terms. A quadratic term is represented using three values: a pair of indices (stored in qrow and qcol), and a coefficient (stored in qval). The three argument arrays provide the corresponding values for each quadratic term. To give an example, to represent <span>$</span>2 x_0^2 + x_0 x_1 +
x_1^2<span>$</span>, you would have *numqnzP=3, qrow[] = {0, 0, 1}, qcol[] = {0, 1, 1}, and qval[] = {2.0, 1.0, 1.0}.

qcol: Column indices associated with quadratic terms. See the description of the qrow argument for more information.

qval: Numerical values associated with quadratic terms. See the description of the qrow argument for more information.

Example usage:

  int     qnz;
  int    *qrow, *qcol;
  double *qval;

  error = GRBgetdblattr(model, GRB_DBL_ATTR_NUMQNZS, &qnz);
  /* ...allocate qrow, qcol, qval to hold 'qnz' values... */
  error = GRBgetq(model, &qnz, qrow, qcol, qval);

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.