Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

Model Queries#

While most model related queries are handled through theattribute interface, a few fall outside of thatinterface. These are described here.

intGRBgetcoeff(GRBmodel*model,intconstrind,intvarind,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 theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 shouldbe placed.

Example:
doubleA12;error=GRBgetcoeff(model,1,2,&A12);
intGRBgetconstrbyname(GRBmodel*model,constchar*name,int*constrnumP)#

Retrieves a linear constraint from its name. If multiple linearconstraints 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 theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the linear constraint should beretrieved.

  • name – The name of the desired linear constraint.

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

Note

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

intGRBgetconstrs(GRBmodel*model,int*numnzP,int*cbeg,int*cind,double*cval,intstart,intlen)#

Retrieve the non-zeros for a set of linear constraints from theconstraint matrix. Typical usage is to call this routine twice. In thefirst call, you specify the requested set of constraints, withNULLvalues forcbeg,cind, andcval. The routine returns thenumber of non-zero values for the specified constraint range innumnzP. That allows you to make certain thatcind andcvalare of sufficient size to hold the result of the second call.

If your constraint matrix may contain more than 2 billion non-zerovalues, you should consider using theGRBXgetconstrs variantof this routine.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the constraintcoefficients. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the linear constraints should beretrieved.

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

  • cbeg – Constraint matrix non-zero values are returned in CompressedSparse Row (CSR) format. Each constraint in the constraint matrix isrepresented as a list of index-value pairs, where each index entryprovides the variable index for a non-zero coefficient, and each valueentry provides the corresponding non-zero value. Each constraint has anassociatedcbeg value, indicating the start position of thenon-zeros for that constraint in thecind andcval arrays. Thenon-zeros for constrainti immediately follow those for constrainti-1 incind andcval. Thus,cbeg[i] indicates both theindex of the first non-zero in constrainti and the end of thenon-zeros for constrainti-1. For example, consider the case wherecbeg[2]=10 andcbeg[3]=12. This would indicate thatconstraint 2 has two non-zero values associated with it. Their variableindices can be found incind[10] andcind[11], and the numericalvalues for those non-zeros can be found incval[10] andcval[11].

  • cind – Variable indices associated with non-zero values. See thedescription of thecbeg argument for more information.

  • cval – Numerical values associated with constraint matrix non-zeros.See the description of thecbeg 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 originalenvironment on which the model was created. SeeAlgorithmic parameters for moreinformation.

Return value:

The environment associated with the model. ANULLreturn value indicates that there was a problem retrieving theenvironment.

Arguments:
  • model – The model from which the environment should be retrieved.

Example:
GRBenv*env=GRBgetenv(model);
intGRBgetgenconstrMax(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thevars argument. The routine returns the total number of operandvariables in the specified general constraint innvarsP. That allowsyou to make certain that thevars array is of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrMax for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the resultant variableof the constraint.

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

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

  • constantP – The additional constant operand of the constraint.

Example:
inttype;intresvar;intnvars;int*vars;doubleconstant;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);}
intGRBgetgenconstrMin(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thevars argument. The routine returns the total number of operandvariables in the specified general constraint innvarsP. That allowsyou to make certain that thevars array is of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrMin for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the resultant variableof the constraint.

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

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

  • constantP – The additional constant operand of the constraint.

Example:
inttype;intresvar;intnvars;int*vars;doubleconstant;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);}
intGRBgetgenconstrAbs(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

See alsoGRBaddgenconstrAbs for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the resultant variableof the constraint.

  • argvarP – The variable index associated with the argument variable ofthe constraint.

Example:
inttype;intresvar;intargvar;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_ABS){error=GRBgetgenconstrAbs(model,3,&resvar,&argvar);}
intGRBgetgenconstrAnd(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thevars argument. The routine returns the total number of operandvariables in the specified general constraint innvarsP. That allowsyou to make certain that thevars array is of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrAnd for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the binary resultantvariable of the constraint.

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

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

Example:
inttype;intresvar;intnvars;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);}
intGRBgetgenconstrOr(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thevars argument. The routine returns the total number of operandvariables in the specified general constraint innvarsP. That allowsyou to make certain that thevars array is of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrOr for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the binary resultantvariable of the constraint.

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

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

Example:
inttype;intresvar;intnvars;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);}
intGRBgetgenconstrNorm(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thevars argument. The routine returns the total number of operandvariables in the specified general constraint innvarsP. That allowsyou to make certain that thevars array is of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrNorm for a description of thesemantics of this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the resultant variableof the constraint.

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

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

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

Example:
inttype;intresvar;intnvars;int*vars;doublewhich;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);}
intGRBgetgenconstrNL(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, you specifythe requested general constraint, with aNULL value for theopcode,data andparent arguments. The routine returns the total number ofnodes that form the expression tree for the specified general constraint innnodesP. That allows you to make certain that theopcode,data andparent arrays are of sufficient size to hold the result of the second call.

See alsoNonlinear Constraints andGRBaddgenconstrNL fora 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 constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • resvarP – The variable index associated with the resultant variableof 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:
inttype;intresvar;intnnodes;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);}
intGRBgetgenconstrIndicator(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, withNULL values for theind andval arguments. The routine returns the total number ofnon-zero coefficients in the linear constraint associated with thespecified indicator constraint innvarsP. That allows you to makecertain that theind andval arrays are of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrIndicator for a description of thesemantics of this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • binvarP – The variable index associated with the binary indicatorvariable.

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

  • nvarsP – The number of non-zero coefficients in the linear constrainttriggered by the indicator.

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

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

  • senseP – Sense for the linear constraint. Options areGRB_LESS_EQUAL,GRB_EQUAL, orGRB_GREATER_EQUAL.

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

Example:
inttype;intbinvar;intbinval:intnvars;int*ind;double*val;charsense;doublerhs;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);}
intGRBgetgenconstrPWL(GRBmodel*model,intid,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 leadsto an error return code. You can query theGenConstrType attribute to determine the typeof the general constraint.

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thexpts andypts arguments. The routine returns the length for thexpts andypts arrays innptsP. That allows you to makecertain that thexpts andypts arrays are of sufficient size tohold the result of the second call.

See alsoGRBaddgenconstrPWL for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

  • nptsP – The number of points that define the piecewise-linearfunction.

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

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

Example:
inttype;intxvar;intyvar;intnpts;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);}
intGRBgetgenconstrPoly(GRBmodel*model,intid,int*xvarP,int*yvarP,int*plenP,double*p)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

Typical usage is to call this routine twice. In the first call, youspecify the requested general constraint, with aNULL value for thep argument. The routine returns the length of thep array inplenP. That allows you to make certain that thep array is ofsufficient size to hold the result of the second call.

See alsoGRBaddgenconstrPoly for a description of thesemantics of this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

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\) isthe highest power term, then\(d+1\) will be returned.

  • p – The coefficients for polynomial function.

Example:
inttype;intxvar;intyvar;intplen;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);}
intGRBgetgenconstrExp(GRBmodel*model,intid,int*xvarP,int*yvarP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrExp for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

Example:
inttype;intxvar;intyvar;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_EXP){error=GRBgetgenconstrExp(model,3,&xvar,&yvar);}
intGRBgetgenconstrExpA(GRBmodel*model,intid,int*xvarP,int*yvarP,double*aP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrExpA for a description of thesemantics of this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

  • aP – The base of the function.

Example:
inttype;intxvar;intyvar;doublea;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_EXPA){error=GRBgetgenconstrExpA(model,3,&xvar,&yvar,&a);}
intGRBgetgenconstrLog(GRBmodel*model,intid,int*xvarP,int*yvarP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrLog for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

Example:
inttype;intxvar;intyvar;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_LOG){error=GRBgetgenconstrLog(model,3,&xvar,&yvar);}
intGRBgetgenconstrLogA(GRBmodel*model,intid,int*xvarP,int*yvarP,double*aP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrLogA for a description of thesemantics of this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

  • aP – The base of the function.

Example:
inttype;intxvar;intyvar;doublea;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_LOGA){error=GRBgetgenconstrLogA(model,3,&xvar,&yvar,&a);}
intGRBgetgenconstrLogistic(GRBmodel*model,intid,int*xvarP,int*yvarP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrLogistic for a description of thesemantics of this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

Example:
inttype;intxvar;intyvar;doublea;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_LOGISTIC){error=GRBgetgenconstrLogistic(model,3,&xvar,&yvar);}
intGRBgetgenconstrPow(GRBmodel*model,intid,int*xvarP,int*yvarP,double*aP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrPow for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

  • aP – The exponent of the function.

Example:
inttype;intxvar;intyvar;doublea;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_POW){error=GRBgetgenconstrPow(model,3,&xvar,&yvar,&a);}
intGRBgetgenconstrSin(GRBmodel*model,intid,int*xvarP,int*yvarP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrSin for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

Example:
inttype;intxvar;intyvar;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_SIN){error=GRBgetgenconstrSin(model,3,&xvar,&yvar);}
intGRBgetgenconstrCos(GRBmodel*model,intid,int*xvarP,int*yvarP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrCos for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

Example:
inttype;intxvar;intyvar;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_COS){error=GRBgetgenconstrCos(model,3,&xvar,&yvar);}
intGRBgetgenconstrTan(GRBmodel*model,intid,int*xvarP,int*yvarP)#

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

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

See alsoGRBaddgenconstrTan for a description of the semanticsof this general constraint type.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the general constraintdata. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 beNULL.

Arguments:
  • xvarP – The index of variable\(x\).

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

Example:
inttype;intxvar;intyvar;error=GRBgetintattrelement(model,GRB_INT_ATTR_GENCONSTRTYPE,3,&type);if(type==GRB_GENCONSTR_TAN){error=GRBgetgenconstrTan(model,3,&xvar,&yvar);}
intGRBgetjsonsolution(GRBmodelmodel,char**buffP)#

After a call tooptimize, this method returns the resulting solution andrelated model attributes as a JSON string. Please refer to theJSON solution format section for details.

Return value:

A non-zero return value indicates that there was a problemgenerating the JSON solution string. Refer to theError Codes tablefor 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 JSONstring should be placed.

Important

On Windows, the string returned inbuffP is allocated in a differentheap from the calling program. You must callGRBfree to free it.

intGRBgetpwlobj(GRBmodel*model,intvar,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 theresult. If either are NULL, thennpointsP will contain the number ofpoints in the function on return.

Refer tothis discussion foradditional 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-linearobjective function. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the piecewise-linear objective functionis being retrieved.

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

  • npointsP – The number of points that define the piecewise-linearfunction.

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

  • y – The\(y\) values for the points that define thepiecewise-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);
intGRBgetq(GRBmodel*model,int*numqnzP,int*qrow,int*qcol,double*qval)#

Retrieve all quadratic objective terms. Theqrow,qcol, andqval arguments must be large enough to hold the result. You canquery theNumQNZs attribute to determine how many terms willbe returned.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the quadratic objectiveterms. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the quadratic objective terms should beretrieved.

  • numqnzP – The number of quadratic objective terms retrieved.

  • qrow – Row indices associated with quadratic terms. A quadratic termis represented using three values: a pair of indices (stored inqrowandqcol), and a coefficient (stored inqval). The threeargument arrays provide the corresponding values for each quadraticterm. 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}, andqval[]={2.0,1.0,1.0}.

  • qcol – Column indices associated with quadratic terms. See thedescription of theqrow argument for more information.

  • qval – Numerical values associated with quadratic terms. See thedescription of theqrow argument for more information.

Example:
intqnz;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);
intGRBgetqconstr(GRBmodel*model,intqconstr,int*numlnzP,int*lind,double*lval,int*numqnzP,int*qrow,int*qcol,double*qval)#

Retrieve the linear and quadratic terms associated with a singlequadratic constraint. Typical usage is to call this routine twice. Inthe first call, you specify the requested quadratic constraint, withNULL values for the array arguments. The routine returns the totalnumber of linear and quadratic terms in the specified quadraticconstraint innumlnzP andnumqnzP, respectively. That allows youto make certain thatlind,lval,qrow,qcol, andqval 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 theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the quadratic constraint should beretrieved.

  • qconstr – The index of the requested quadratic constraint.

  • numlnzP – The number of linear terms retrieved for the requestedquadratic constraint.

  • lind – Variable indices associated with linear terms.

  • lval – Numerical coefficients associated with linear terms.

  • numqnzP – The number of quadratic terms retrieved for the requestedquadratic constraint.

  • qrow – Row indices associated with quadratic terms. A quadratic termis represented using three values: a pair of indices (stored inqrowandqcol), and a coefficient (stored inqval). The associatedarguments arrays provide the corresponding values for each quadraticterm. To give an example, if the requested quadratic constraint hasquadratic terms\(2 x_0^2 + x_0 x_1 + x_1^2\), this routine wouldreturn*numqnzP=3,qrow[]={0,0,1},qcol[]={0,1,1},andqval[]={2.0,1.0,1.0}.

  • qcol – Column indices associated with quadratic terms. See thedescription of theqrow argument for more information.

  • qval – Numerical values associated with quadratic terms. See thedescription of theqrow argument for more information.

intGRBgetqconstrbyname(GRBmodel*model,constchar*name,int*constrnumP)#

Retrieves a quadratic constraint from its name. If multiple quadraticconstraints 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 theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the quadratic constraint should beretrieved.

  • name – The name of the desired quadratic constraint.

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

Note

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

intGRBgetsos(GRBmodel*model,int*nummembersP,int*sostype,int*beg,int*ind,double*weight,intstart,intlen)#

Retrieve the members and weights of a set of SOS constraints. Typicalusage is to call this routine twice. In the first call, you specify therequested SOS constraints, withNULL values forind andweight. The routine returns the total number of members for thespecified SOS constraints innummembersP. That allows you to makecertain thatind andweight are of sufficient size to hold theresult of the second call.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the SOS members.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 areGRB_SOS_TYPE1 orGRB_SOS_TYPE2.

  • beg – SOS constraints are returned in Compressed Sparse Row (CSR)format. Each SOS constraint in the model is represented as a list ofindex-value pairs, where each index entry provides the variable indexfor an SOS member, and each value entry provides the corresponding SOSconstraint weight. Each SOS constraint has an associatedbeg value,indicating the start position of the members of that constraint in theind andweight arrays. The members for SOS constraintiimmediately follow those for constrainti-1 inind andweight. Thus,beg[i] indicates both the index of the firstmember of SOS constrainti and the end of the member list for SOSconstrainti-1. For example, consider the case wherebeg[2]=10andbeg[3]=12. This would indicate that SOS constraint 2 has twomembers. Their variable indices can be found inind[10] andind[11], and their SOS weights can be found inweight[10] andweight[11].

  • ind – Variable indices associated with SOS members. See thedescription of thebeg argument for more information.

  • weight – Weights associated with SOS members. See the description ofthebeg argument for more information.

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

  • len – The number of SOS constraints to retrieve.

intGRBgetvarbyname(GRBmodel*model,constchar*name,int*varnumP)#

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

Return value:

A non-zero return value indicates that a problem occurred while retrieving the variable. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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. Whenadding variables to a model, you should keep track of the returned objectsin your own data structures in order to retrieve them efficiently formodel building and extracting attribute values.

intGRBgetvars(GRBmodel*model,int*numnzP,int*vbeg,int*vind,double*vval,intstart,intlen)#

Retrieve the non-zeros for a set of variables from the constraintmatrix. Typical usage is to call this routine twice. In the first call,you specify the requested set of variables, withNULL values forvbeg,vind, andvval. The routine returns the number ofnon-zero values for the specified variables innumnzP. That allowsyou to make certain thatvind andvval are of sufficient size tohold the result of the second call.

If your constraint matrix may contain more than 2 billion non-zerovalues, you should consider using theGRBXgetvars variant ofthis routine.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the variablecoefficients. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 CompressedSparse Column (CSC) format by this routine. Each column in theconstraint matrix is represented as a list of index-value pairs, whereeach index entry provides the constraint index for a non-zerocoefficient, and each value entry provides the corresponding non-zerovalue. Each variable has an associatedvbeg value, indicating thestart position of the non-zeros for that constraint in thevind andvval arrays. The non-zeros for variablei immediately followthose for variablei-1 invind andvval. Thus,vbeg[i]indicates both the index of the first non-zero in variablei and theend of the non-zeros for variablei-1. For example, consider thecase wherevbeg[2]=10 andvbeg[3]=12. This would indicatethat variable 2 has two non-zero values associated with it. Theirconstraint indices can be found invind[10] andvind[11], andthe numerical values for those non-zeros can be found invval[10]andvval[11].

  • vind – Constraint indices associated with non-zero values. See thedescription of thevbeg argument for more information.

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

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

  • len – The number of variables to retrieve.

intGRBsinglescenariomodel(GRBmodel*model,GRBmodel**singlescenarioP)#

Capture a single scenario from a multi-scenario model. Use theScenarioNumber parameter to indicate which scenario tocapture.

Return value:

A non-zero return value indicates that a problem occurred while extracting the single-scenariomodel. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model from which the scenario should be extracted.

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

intGRBXgetconstrs(GRBmodel*model,size_t*numnzP,size_t*cbeg,int*cind,double*cval,intstart,intlen)#

Thesize_t version ofGRBgetconstrs. The two argumentsthat count non-zero values are of typesize_t in this version tosupport models with more than 2 billion non-zero values.

Retrieve the non-zeros for a set of linear constraints from theconstraint matrix. Typical usage is to call this routine twice. In thefirst call, you specify the requested set of constraints, withNULLvalues forcbeg,cind, andcval. The routine returns thenumber of non-zero values for the specified constraint range innumnzP. That allows you to make certain thatcind andcvalare 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 constraintcoefficients. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 CompressedSparse Row (CSR) format. Each constraint in the constraint matrix isrepresented as a list of index-value pairs, where each index entryprovides the variable index for a non-zero coefficient, and each valueentry provides the corresponding non-zero value. Each constraint has anassociatedcbeg value, indicating the start position of thenon-zeros for that constraint in thecind andcval arrays. Thenon-zeros for constrainti immediately follow those for constrainti-1 incind andcval. Thus,cbeg[i] indicates both theindex of the first non-zero in constrainti and the end of thenon-zeros for constrainti-1. For example, consider the case wherecbeg[2]=10 andcbeg[3]=12. This would indicate thatconstraint 2 has two non-zero values associated with it. Their variableindices can be found incind[10] andcind[11], and the numericalvalues for those non-zeros can be found incval[10] andcval[11].

  • cind – Variable indices associated with non-zero values. See thedescription of thecbeg argument for more information.

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

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

  • len – The number of constraints to retrieve.

intGRBXgetvars(GRBmodel*model,size_t*numnzP,size_t*vbeg,int*vind,double*vval,intstart,intlen)#

Thesize_t version ofGRBgetvars. The two arguments thatcount non-zero values are of typesize_t in this version to supportmodels with more than 2 billion non-zero values.

Retrieve the non-zeros for a set of variables from the constraintmatrix. Typical usage is to call this routine twice. In the first call,you specify the requested set of variables, withNULL values forvbeg,vind, andvval. The routine returns the number ofnon-zero values for the specified variables innumnzP. That allowsyou to make certain thatvind andvval are of sufficient size tohold the result of the second call.

Return value:

A non-zero return value indicates that a problem occurred while retrieving the variablecoefficients. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

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 CompressedSparse Column (CSC) format by this routine. Each column in theconstraint matrix is represented as a list of index-value pairs, whereeach index entry provides the constraint index for a non-zerocoefficient, and each value entry provides the corresponding non-zerovalue. Each variable has an associatedvbeg value, indicating thestart position of the non-zeros for that constraint in thevind andvval arrays. The non-zeros for variablei immediately followthose for variablei-1 invind andvval. Thus,vbeg[i]indicates both the index of the first non-zero in variablei and theend of the non-zeros for variablei-1. For example, consider thecase wherevbeg[2]=10 andvbeg[3]=12. This would indicatethat variable 2 has two non-zero values associated with it. Theirconstraint indices can be found invind[10] andvind[11], andthe numerical values for those non-zeros can be found invval[10]andvval[11].

  • vind – Constraint indices associated with non-zero values. See thedescription of thevbeg argument for more information.

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

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

  • len – The number of variables to retrieve.

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp