Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Model Queries

While most model related queries are handled through the attribute interface, a few fall outside of that interface. These are described here.

int GRBgetcoeff(GRBmodel *model, int constrind, int varind, double *valP)

  Retrieve a single constraint matrix coefficient.

  Return value:

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

  Arguments:

    - model – The model from which the coefficient should be retrieved.

    - constrind – The constraint index for the desired coefficient.

    - varind – The variable index for the desired coefficient.

    - valP – The location in which the requested matrix coefficient should be placed.

  Example:

        double A12;
        error = GRBgetcoeff(model, 1, 2, &A12);

int GRBgetconstrbyname(GRBmodel *model, const char *name, int *constrnumP)

  Retrieves a linear constraint from its name. If multiple linear constraints have the same name, this routine chooses one arbitrarily.

  Return value:

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

  Arguments:

    - model – The model from which the linear constraint should be retrieved.

    - name – The name of the desired linear constraint.

    - constrnumP – Constraint number for a linear constraint with the indicated name. Returns -1 if no matching name is found.

  Note

  Retrieving constraint objects by name is not recommended in general. When adding constraints to a model, you should keep track of the returned objects in your own data structures in order to retrieve them efficiently for model building and extracting attribute values.

int GRBgetconstrs(GRBmodel *model, int *numnzP, int *cbeg, int *cind, double *cval, int start, int len)

  Retrieve the non-zeros for a set of linear constraints from the constraint matrix. Typical usage is to call this routine twice. In the first call, you specify the requested set of constraints, with `NULL` values for `cbeg`, `cind`, and `cval`. The routine returns the number of non-zero values for the specified constraint range in `numnzP`. That allows you to make certain that `cind` and `cval` are of sufficient size to hold the result of the second call.

  If your constraint matrix may contain more than 2 billion non-zero values, you should consider using the `GRBXgetconstrs` variant of this routine.

  Return value:

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

  Arguments:

    - model – The model from which the linear constraints should be retrieved.

    - numnzP – The number of non-zero values retrieved.

    - cbeg – Constraint matrix non-zero values are returned in Compressed Sparse Row (CSR) format. Each constraint in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the variable index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each constraint has an associated `cbeg` value, indicating the start position of the non-zeros for that constraint in the `cind` and `cval` arrays. The non-zeros for constraint `i` immediately follow those for constraint `i-1` in `cind` and `cval`. Thus, `cbeg[i]` indicates both the index of the first non-zero in constraint `i` and the end of the non-zeros for constraint `i-1`. For example, consider the case where `cbeg[2] = 10` and `cbeg[3] = 12`. This would indicate that constraint 2 has two non-zero values associated with it. Their variable indices can be found in `cind[10]` and `cind[11]`, and the numerical values for those non-zeros can be found in `cval[10]` and `cval[11]`.

    - cind – Variable indices associated with non-zero values. See the description of the `cbeg` argument for more information.

    - cval – Numerical values associated with constraint matrix non-zeros. See the description of the `cbeg` argument for more information.

    - start – The index of the first linear constraint to retrieve.

    - len – The number of linear constraints to retrieve.

GRBenv *GRBgetenv(GRBmodel *model)

  Retrieve the environment associated with a model.

  Note that this environment is a model environment, not the original environment on which the model was created. See Algorithmic parameters for more information.

  Return value:

    The environment associated with the model. A `NULL` return value indicates that there was a problem retrieving the environment.

  Arguments:

    - model – The model from which the environment should be retrieved.

  Example:

        GRBenv *env = GRBgetenv(model);

int GRBgetgenconstrMax(GRBmodel *model, int id, int *resvarP, int *nvarsP, int *vars, double *constantP)

  Retrieve the data associated with a general constraint of type MAX. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `vars` argument. The routine returns the total number of operand variables in the specified general constraint in `nvarsP`. That allows you to make certain that the `vars` array is of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrMax` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the resultant variable of the constraint.

    - nvarsP – The number of operand variables of the constraint.

    - vars – An array to store the variable indices associated with the variable operands of the constraint.

    - constantP – The additional constant operand of the constraint.

  Example:

        int type;
        int resvar;
        int nvars;
        int *vars;
        double constant;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_MAX) {
          error = GRBgetgenconstrMax(model, 3, &resvar, &nvars, NULL, &constant);
          /* ...allocate vars to hold 'nvars' values... */
          error = GRBgetgenconstrMax(model, 3, NULL, NULL, vars, NULL);
        }

int GRBgetgenconstrMin(GRBmodel *model, int id, int *resvarP, int *nvarsP, int *vars, double *constantP)

  Retrieve the data associated with a general constraint of type MIN. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `vars` argument. The routine returns the total number of operand variables in the specified general constraint in `nvarsP`. That allows you to make certain that the `vars` array is of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrMin` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the resultant variable of the constraint.

    - nvarsP – The number of operand variables of the constraint.

    - vars – An array to store the variable indices associated with the variable operands of the constraint.

    - constantP – The additional constant operand of the constraint.

  Example:

        int type;
        int resvar;
        int nvars;
        int *vars;
        double constant;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_MIN) {
          error = GRBgetgenconstrMin(model, 3, &resvar, &nvars, NULL, &constant);
          /* ...allocate vars to hold 'nvars' values... */
          error = GRBgetgenconstrMin(model, 3, NULL, NULL, vars, NULL);
        }

int GRBgetgenconstrAbs(GRBmodel *model, int id, int *resvarP, int *argvarP)

  Retrieve the data associated with a general constraint of type ABS. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrAbs` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the resultant variable of the constraint.

    - argvarP – The variable index associated with the argument variable of the constraint.

  Example:

        int type;
        int resvar;
        int argvar;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_ABS) {
          error = GRBgetgenconstrAbs(model, 3, &resvar, &argvar);
        }

int GRBgetgenconstrAnd(GRBmodel *model, int id, int *resvarP, int *nvarsP, int *vars)

  Retrieve the data associated with a general constraint of type AND. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `vars` argument. The routine returns the total number of operand variables in the specified general constraint in `nvarsP`. That allows you to make certain that the `vars` array is of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrAnd` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the binary resultant variable of the constraint.

    - nvarsP – The number of binary operand variables of the constraint.

    - vars – An array to store the variable indices associated with the binary variable operands of the constraint.

  Example:

        int type;
        int resvar;
        int nvars;
        int *vars;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_AND) {
          error = GRBgetgenconstrAnd(model, 3, &resvar, &nvars, NULL);
          /* ...allocate vars to hold 'nvars' values... */
          error = GRBgetgenconstrAnd(model, 3, NULL, NULL, vars);
        }

int GRBgetgenconstrOr(GRBmodel *model, int id, int *resvarP, int *nvarsP, int *vars)

  Retrieve the data associated with a general constraint of type OR. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `vars` argument. The routine returns the total number of operand variables in the specified general constraint in `nvarsP`. That allows you to make certain that the `vars` array is of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrOr` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the binary resultant variable of the constraint.

    - nvarsP – The number of binary operand variables of the constraint.

    - vars – An array to store the variable indices associated with the binary variable operands of the constraint.

  Example:

        int type;
        int resvar;
        int nvars;
        int *vars;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_OR) {
          error = GRBgetgenconstrOr(model, 3, &resvar, &nvars, NULL);
          /* ...allocate vars to hold 'nvars' values... */
          error = GRBgetgenconstrOr(model, 3, NULL, NULL, vars);
        }

int GRBgetgenconstrNorm(GRBmodel *model, int id, int *resvarP, int *nvarsP, int *vars, double *whichP)

  Retrieve the data associated with a general constraint of type NORM. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `vars` argument. The routine returns the total number of operand variables in the specified general constraint in `nvarsP`. That allows you to make certain that the `vars` array is of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrNorm` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the resultant variable of the constraint.

    - nvarsP – The number of operand variables of the constraint.

    - vars – An array to store the variable indices associated with the variable operands of the constraint.

    - whichP – Which norm is used. Options are 0, 1, 2, and GRB_INFINITY.

  Example:

        int type;
        int resvar;
        int nvars;
        int *vars;
        double which;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_NORM) {
          error = GRBgetgenconstrNorm(model, 3, &resvar, &nvars, NULL, &which);
          /* ...allocate vars to hold 'nvars' values... */
          error = GRBgetgenconstrNorm(model, 3, NULL, NULL, vars);
        }

int GRBgetgenconstrNL(GRBmodel *model, int id, int *resvarP, int *nnodesP, int *opcode, double *data, int *parent)

  Retrieve the data associated with a general constraint of type NL. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `opcode`, `data` and `parent` arguments. The routine returns the total number of nodes that form the expression tree for the specified general constraint in `nnodesP`. That allows you to make certain that the `opcode`, `data` and `parent` arrays are of sufficient size to hold the result of the second call.

  See also Nonlinear Constraints and `GRBaddgenconstrNL` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - resvarP – The variable index associated with the resultant variable of the constraint.

    - nnodesP – The number of nodes in the expression tree for this constraint.

    - opcode – An array to store the nodes’ operation codes.

    - data – An array to store the nodes’ auxiliary data items.

    - parent – An array to store the nodes’ parent indices.

  Example:

        int type;
        int resvar;
        int nnodes;
        int *opcode, *parent;
        double *data;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_NL) {
          error = GRBgetgenconstrNL(model, 3, &resvar, &nnodes, NULL, NULL, NULL);
          /* ...allocate opcode, data, parent to hold 'nnodes' values... */
          error = GRBgetgenconstrNL(model, 3, NULL, NULL, opcode, data, parent);
        }

int GRBgetgenconstrIndicator(GRBmodel *model, int id, int *binvarP, int *binvalP, int *nvarsP, int *ind, double *val, char *senseP, double *rhsP)

  Retrieve the data associated with a general constraint of type INDICATOR. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with `NULL` values for the `ind` and `val` arguments. The routine returns the total number of non-zero coefficients in the linear constraint associated with the specified indicator constraint in `nvarsP`. That allows you to make certain that the `ind` and `val` arrays are of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrIndicator` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - binvarP – The variable index associated with the binary indicator variable.

    - binvalP – The value that the indicator variable has to take in order to trigger the linear constraint.

    - nvarsP – The number of non-zero coefficients in the linear constraint triggered by the indicator.

    - ind – An array to store the variable indices for non-zero values in the linear constraint.

    - val – An array to store the numerical values for non-zero values in the linear constraint.

    - senseP – Sense for the linear constraint. Options are `GRB_LESS_EQUAL`, `GRB_EQUAL`, or `GRB_GREATER_EQUAL`.

    - rhsP – Right-hand side value for the linear constraint.

  Example:

        int type;
        int binvar;
        int binval:
        int nvars;
        int *ind;
        double *val;
        char sense;
        double rhs;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_INDICATOR) {
          error = GRBgetgenconstrIndicator(model, 3, &binvar, &binval, &nvars,
                                           NULL, NULL, &sense, &rhs);
          /* ...allocate ind and val to hold 'nvars' values... */
          error = GRBgetgenconstrIndicator(model, 3, NULL, NULL, NULL,
                                           ind, val, NULL, NULL);
        }

int GRBgetgenconstrPWL(GRBmodel *model, int id, int *xvarP, int *yvarP, int *nptsP, double *xpts, double *ypts)

  Retrieve the data associated with a general constraint of type PWL. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `xpts` and `ypts` arguments. The routine returns the length for the `xpts` and `ypts` arrays in `nptsP`. That allows you to make certain that the `xpts` and `ypts` arrays are of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrPWL` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

    - nptsP – The number of points that define the piecewise-linear function.

    - xpts – The \(x\) values for the points that define the piecewise-linear function.

    - ypts – The \(y\) values for the points that define the piecewise-linear function.

  Example:

        int type;
        int xvar;
        int yvar;
        int npts;
        double *xpts;
        double *ypts;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_PWL) {
          error = GRBgetgenconstrPWL(model, 3, &xvar, &yvar, &npts, NULL, NULL);
          /* ...allocate xpts and ypts arrays with length npts */
          error = GRBgetgenconstrPWL(model, 3, NULL, NULL, NULL, xpts, ypts);
        }

int GRBgetgenconstrPoly(GRBmodel *model, int id, int *xvarP, int *yvarP, int *plenP, double *p)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type POLY. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  Typical usage is to call this routine twice. In the first call, you specify the requested general constraint, with a `NULL` value for the `p` argument. The routine returns the length of the `p` array in `plenP`. That allows you to make certain that the `p` array is of sufficient size to hold the result of the second call.

  See also `GRBaddgenconstrPoly` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

    - plenP – Pointer to store the array length for p. If \(x^d\) is the highest power term, then \(d+1\) will be returned.

    - p – The coefficients for polynomial function.

  Example:

        int type;
        int xvar;
        int yvar;
        int plen;
        double *p;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_POLY) {
          error = GRBgetgenconstrPoly(model, 3, &xvar, &yvar, &plen, NULL);
          /* ...allocate p array with length plen */
          error = GRBgetgenconstrPoly(model, 3, NULL, NULL, NULL, p);
        }

int GRBgetgenconstrExp(GRBmodel *model, int id, int *xvarP, int *yvarP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type EXP. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrExp` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

  Example:

        int type;
        int xvar;
        int yvar;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_EXP) {
          error = GRBgetgenconstrExp(model, 3, &xvar, &yvar);
        }

int GRBgetgenconstrExpA(GRBmodel *model, int id, int *xvarP, int *yvarP, double *aP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type EXPA. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrExpA` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

    - aP – The base of the function.

  Example:

        int type;
        int xvar;
        int yvar;
        double a;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_EXPA) {
          error = GRBgetgenconstrExpA(model, 3, &xvar, &yvar, &a);
        }

int GRBgetgenconstrLog(GRBmodel *model, int id, int *xvarP, int *yvarP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type LOG. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrLog` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

  Example:

        int type;
        int xvar;
        int yvar;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_LOG) {
          error = GRBgetgenconstrLog(model, 3, &xvar, &yvar);
        }

int GRBgetgenconstrLogA(GRBmodel *model, int id, int *xvarP, int *yvarP, double *aP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type LOGA. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrLogA` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

    - aP – The base of the function.

  Example:

        int type;
        int xvar;
        int yvar;
        double a;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_LOGA) {
          error = GRBgetgenconstrLogA(model, 3, &xvar, &yvar, &a);
        }

int GRBgetgenconstrLogistic(GRBmodel *model, int id, int *xvarP, int *yvarP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type LOGISTIC. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrLogistic` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

  Example:

        int type;
        int xvar;
        int yvar;
        double a;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_LOGISTIC) {
          error = GRBgetgenconstrLogistic(model, 3, &xvar, &yvar);
        }

int GRBgetgenconstrPow(GRBmodel *model, int id, int *xvarP, int *yvarP, double *aP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type POW. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrPow` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

    - aP – The exponent of the function.

  Example:

        int type;
        int xvar;
        int yvar;
        double a;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_POW) {
          error = GRBgetgenconstrPow(model, 3, &xvar, &yvar, &a);
        }

int GRBgetgenconstrSin(GRBmodel *model, int id, int *xvarP, int *yvarP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type SIN. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrSin` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

  Example:

        int type;
        int xvar;
        int yvar;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_SIN) {
          error = GRBgetgenconstrSin(model, 3, &xvar, &yvar);
        }

int GRBgetgenconstrCos(GRBmodel *model, int id, int *xvarP, int *yvarP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type COS. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrCos` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

  Example:

        int type;
        int xvar;
        int yvar;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_COS) {
          error = GRBgetgenconstrCos(model, 3, &xvar, &yvar);
        }

int GRBgetgenconstrTan(GRBmodel *model, int id, int *xvarP, int *yvarP)

  Deprecated since version 13.0: Using function constraints is deprecated since version 13.0. Please use nonlinear constraints instead.

  Retrieve the data associated with a general constraint of type TAN. Calling this method for a general constraint of a different type leads to an error return code. You can query the GenConstrType attribute to determine the type of the general constraint.

  See also `GRBaddgenconstrTan` for a description of the semantics of this general constraint type.

  Return value:

    A non-zero return value indicates that a problem occurred while retrieving the general constraint data. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model that contains the desired general constraint.

    - id – The index of the general constraint to retrieve.

  Note that any of the following arguments can be `NULL`.

  Arguments:

    - xvarP – The index of variable \(x\).

    - yvarP – The index of variable \(y\).

  Example:

        int type;
        int xvar;
        int yvar;

        error = GRBgetintattrelement(model, GRB_INT_ATTR_GENCONSTRTYPE, 3, &type);
        if (type == GRB_GENCONSTR_TAN) {
          error = GRBgetgenconstrTan(model, 3, &xvar, &yvar);
        }

int GRBgetjsonsolution(GRBmodel model, char **buffP)

  After a call to `optimize`, this method returns the resulting solution and related model attributes as a JSON string. Please refer to the JSON solution format section for details.

  Return value:

    A non-zero return value indicates that there was a problem generating the JSON solution string. Refer to the Error Codes table for a list of possible return values.

  Arguments:

    - model – Model from which to query its current JSON solution string.

    - buffP – The location in which the pointer to the newly created JSON string should be placed.

  Important

  On Windows, the string returned in `buffP` is allocated in a different heap from the calling program. You must call `GRBfree` to free it.

int GRBgetpwlobj(GRBmodel *model, int var, int *npointsP, double *x, double *y)

  Retrieve the piecewise-linear objective function for a variable. The \(x\) and \(y\) arguments must be large enough to hold the result. If either are NULL, then `npointsP` will contain the number of points in the function on return.

  Refer to this discussion for additional information on what the values in \(x\) and \(y\) mean.

  Return value:

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

  Arguments:

    - model – The model from which the piecewise-linear objective function is being retrieved.

    - var – The variable whose objective function is being retrieved.

    - npointsP – The number of points that define the piecewise-linear function.

    - x – The \(x\) values for the points that define the piecewise-linear function. These will always be in non-decreasing order.

    - y – The \(y\) values for the points that define the piecewise-linear function.

  Example:

        double *x;
        double *y;

        error = GRBgetpwlobj(model, var, &npoints, NULL, NULL);
        /* ...allocate x and y to hold 'npoints' values... */
        error = GRBgetpwlobj(model, var, &npoints, x, y);

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 Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - 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 \(2 x_0^2 + x_0 x_1 + x_1^2\), 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:

        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);

int GRBgetqconstr(GRBmodel *model, int qconstr, int *numlnzP, int *lind, double *lval, int *numqnzP, int *qrow, int *qcol, double *qval)

  Retrieve the linear and quadratic terms associated with a single quadratic constraint. Typical usage is to call this routine twice. In the first call, you specify the requested quadratic constraint, with `NULL` values for the array arguments. The routine returns the total number of linear and quadratic terms in the specified quadratic constraint in `numlnzP` and `numqnzP`, respectively. That allows you to make certain that `lind`, `lval`, `qrow`, `qcol`, and `qval` are of sufficient size to hold the result of the second call.

  Return value:

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

  Arguments:

    - model – The model from which the quadratic constraint should be retrieved.

    - qconstr – The index of the requested quadratic constraint.

    - numlnzP – The number of linear terms retrieved for the requested quadratic constraint.

    - lind – Variable indices associated with linear terms.

    - lval – Numerical coefficients associated with linear terms.

    - numqnzP – The number of quadratic terms retrieved for the requested quadratic constraint.

    - 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 associated arguments arrays provide the corresponding values for each quadratic term. To give an example, if the requested quadratic constraint has quadratic terms \(2 x_0^2 + x_0 x_1 + x_1^2\), this routine would return `*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.

int GRBgetqconstrbyname(GRBmodel *model, const char *name, int *constrnumP)

  Retrieves a quadratic constraint from its name. If multiple quadratic constraints have the same name, this routine chooses one arbitrarily.

  Return value:

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

  Arguments:

    - model – The model from which the quadratic constraint should be retrieved.

    - name – The name of the desired quadratic constraint.

    - constrnumP – Constraint number for a quadratic constraint with the indicated name. Returns -1 if no matching name is found.

  Note

  Retrieving qconstraint objects by name is not recommended in general. When adding qconstraints to a model, you should keep track of the returned objects in your own data structures in order to retrieve them efficiently for model building and extracting attribute values.

int GRBgetsos(GRBmodel *model, int *nummembersP, int *sostype, int *beg, int *ind, double *weight, int start, int len)

  Retrieve the members and weights of a set of SOS constraints. Typical usage is to call this routine twice. In the first call, you specify the requested SOS constraints, with `NULL` values for `ind` and `weight`. The routine returns the total number of members for the specified SOS constraints in `nummembersP`. That allows you to make certain that `ind` and `weight` are of sufficient size to hold the result of the second call.

  Return value:

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

  Arguments:

    - model – The model from which the SOS constraints should be retrieved.

    - nummembersP – The total number of SOS members retrieved.

    - sostype – The types of the SOS constraints. Possible values are `GRB_SOS_TYPE1` or `GRB_SOS_TYPE2`.

    - beg – SOS constraints are returned in Compressed Sparse Row (CSR) format. Each SOS constraint in the model is represented as a list of index-value pairs, where each index entry provides the variable index for an SOS member, and each value entry provides the corresponding SOS constraint weight. Each SOS constraint has an associated `beg` value, indicating the start position of the members of that constraint in the `ind` and `weight` arrays. The members for SOS constraint `i` immediately follow those for constraint `i-1` in `ind` and `weight`. Thus, `beg[i]` indicates both the index of the first member of SOS constraint `i` and the end of the member list for SOS constraint `i-1`. For example, consider the case where `beg[2] = 10` and `beg[3] = 12`. This would indicate that SOS constraint 2 has two members. Their variable indices can be found in `ind[10]` and `ind[11]`, and their SOS weights can be found in `weight[10]` and `weight[11]`.

    - ind – Variable indices associated with SOS members. See the description of the `beg` argument for more information.

    - weight – Weights associated with SOS members. See the description of the `beg` argument for more information.

    - start – The index of the first SOS constraint to retrieve.

    - len – The number of SOS constraints to retrieve.

int GRBgetvarbyname(GRBmodel *model, const char *name, int *varnumP)

  Retrieves a variable from its name. If multiple variables have the same name, this routine chooses one arbitrarily.

  Return value:

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

  Arguments:

    - model – The model from which the variable should be retrieved.

    - name – The name of the desired variable.

    - varnumP – Variable number for a variable with the indicated name. Returns -1 if no matching name is found.

  Note

  Retrieving variable objects by name is not recommended in general. When adding variables to a model, you should keep track of the returned objects in your own data structures in order to retrieve them efficiently for model building and extracting attribute values.

int GRBgetvars(GRBmodel *model, int *numnzP, int *vbeg, int *vind, double *vval, int start, int len)

  Retrieve the non-zeros for a set of variables from the constraint matrix. Typical usage is to call this routine twice. In the first call, you specify the requested set of variables, with `NULL` values for `vbeg`, `vind`, and `vval`. The routine returns the number of non-zero values for the specified variables in `numnzP`. That allows you to make certain that `vind` and `vval` are of sufficient size to hold the result of the second call.

  If your constraint matrix may contain more than 2 billion non-zero values, you should consider using the `GRBXgetvars` variant of this routine.

  Return value:

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

  Arguments:

    - model – The model from which the variables should be retrieved.

    - numnzP – The number of non-zero values retrieved.

    - vbeg – Constraint matrix non-zero values are returned in Compressed Sparse Column (CSC) format by this routine. Each column in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the constraint index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each variable has an associated `vbeg` value, indicating the start position of the non-zeros for that constraint in the `vind` and `vval` arrays. The non-zeros for variable `i` immediately follow those for variable `i-1` in `vind` and `vval`. Thus, `vbeg[i]` indicates both the index of the first non-zero in variable `i` and the end of the non-zeros for variable `i-1`. For example, consider the case where `vbeg[2] = 10` and `vbeg[3] = 12`. This would indicate that variable 2 has two non-zero values associated with it. Their constraint indices can be found in `vind[10]` and `vind[11]`, and the numerical values for those non-zeros can be found in `vval[10]` and `vval[11]`.

    - vind – Constraint indices associated with non-zero values. See the description of the `vbeg` argument for more information.

    - vval – Numerical values associated with constraint matrix non-zeros. See the description of the `vbeg` argument for more information.

    - start – The index of the first variable to retrieve.

    - len – The number of variables to retrieve.

int GRBsinglescenariomodel(GRBmodel *model, GRBmodel **singlescenarioP)

  Capture a single scenario from a multi-scenario model. Use the ScenarioNumber parameter to indicate which scenario to capture.

  Return value:

    A non-zero return value indicates that a problem occurred while extracting the single-scenario model. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling `GRBgeterrormsg`.

  Arguments:

    - model – The model from which the scenario should be extracted.

    - singlescenarioP – The location in which the pointer to the requested single-scenario model should be placed.

int GRBXgetconstrs(GRBmodel *model, size_t *numnzP, size_t *cbeg, int *cind, double *cval, int start, int len)

  The `size_t` version of `GRBgetconstrs`. The two arguments that count non-zero values are of type `size_t` in this version to support models with more than 2 billion non-zero values.

  Retrieve the non-zeros for a set of linear constraints from the constraint matrix. Typical usage is to call this routine twice. In the first call, you specify the requested set of constraints, with `NULL` values for `cbeg`, `cind`, and `cval`. The routine returns the number of non-zero values for the specified constraint range in `numnzP`. That allows you to make certain that `cind` and `cval` are of sufficient size to hold the result of the second call.

  Return value:

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

  Arguments:

    - model – The model from which the constraints should be retrieved.

    - numnzP – The number of non-zero values retrieved.

    - cbeg – Constraint matrix non-zero values are returned in Compressed Sparse Row (CSR) format. Each constraint in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the variable index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each constraint has an associated `cbeg` value, indicating the start position of the non-zeros for that constraint in the `cind` and `cval` arrays. The non-zeros for constraint `i` immediately follow those for constraint `i-1` in `cind` and `cval`. Thus, `cbeg[i]` indicates both the index of the first non-zero in constraint `i` and the end of the non-zeros for constraint `i-1`. For example, consider the case where `cbeg[2] = 10` and `cbeg[3] = 12`. This would indicate that constraint 2 has two non-zero values associated with it. Their variable indices can be found in `cind[10]` and `cind[11]`, and the numerical values for those non-zeros can be found in `cval[10]` and `cval[11]`.

    - cind – Variable indices associated with non-zero values. See the description of the `cbeg` argument for more information.

    - cval – Numerical values associated with constraint matrix non-zeros. See the description of the `cbeg` argument for more information.

    - start – The index of the first constraint to retrieve.

    - len – The number of constraints to retrieve.

int GRBXgetvars(GRBmodel *model, size_t *numnzP, size_t *vbeg, int *vind, double *vval, int start, int len)

  The `size_t` version of `GRBgetvars`. The two arguments that count non-zero values are of type `size_t` in this version to support models with more than 2 billion non-zero values.

  Retrieve the non-zeros for a set of variables from the constraint matrix. Typical usage is to call this routine twice. In the first call, you specify the requested set of variables, with `NULL` values for `vbeg`, `vind`, and `vval`. The routine returns the number of non-zero values for the specified variables in `numnzP`. That allows you to make certain that `vind` and `vval` are of sufficient size to hold the result of the second call.

  Return value:

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

  Arguments:

    - model – The model from which the variables should be retrieved.

    - numnzP – The number of non-zero values retrieved.

    - vbeg – Constraint matrix non-zero values are returned in Compressed Sparse Column (CSC) format by this routine. Each column in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the constraint index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each variable has an associated `vbeg` value, indicating the start position of the non-zeros for that constraint in the `vind` and `vval` arrays. The non-zeros for variable `i` immediately follow those for variable `i-1` in `vind` and `vval`. Thus, `vbeg[i]` indicates both the index of the first non-zero in variable `i` and the end of the non-zeros for variable `i-1`. For example, consider the case where `vbeg[2] = 10` and `vbeg[3] = 12`. This would indicate that variable 2 has two non-zero values associated with it. Their constraint indices can be found in `vind[10]` and `vind[11]`, and the numerical values for those non-zeros can be found in `vval[10]` and `vval[11]`.

    - vind – Constraint indices associated with non-zero values. See the description of the `vbeg` argument for more information.

    - vval – Numerical values associated with constraint matrix non-zeros. See the description of the `vbeg` argument for more information.

    - start – The index of the first variable to retrieve.

    - len – The number of variables to retrieve.

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support