Movatterモバイル変換


[0]ホーム

URL:


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

Concepts

Features

Reference

Gurobi
Back to top

GRBVar#

GRBVar#

Gurobi variable object. Variables are always associated with aparticular model. You create a variable object by adding a variable to amodel (usingGRBModel.addVar), rather than by using aGRBVar constructor.

The methods on variable objects are used to get and set variableattributes. For example, solution information can be queried by callingget (GRB.DoubleAttr.X). Note, however,that it is generally more efficient to query attributes for a set ofvariables at once. This is done using the attribute query method on theGRBModel object (GRBModel.get).

The full list of attributescan be found in theAttributes section of thisdocument. Examples of how to query and set attributes can also be foundinthis section.

charget(GRB.CharAttrattr)#
doubleget(GRB.DoubleAttrattr)#
intget(GRB.IntAttrattr)#
Stringget(GRB.StringAttrattr)#

Query the value of an attribute.

Arguments:

attr – The attribute being queried.

Return value:

The current value of the requested attribute.

Example:
// Get VType valuecharvtype=var.get(GRB.CharAttr.VType);// Get lower bound valuedoublelb=var.get(GRB.DoubleAttr.LB);// Get VBasis valueintvbasis=var.get(GRB.IntAttr.VBasis);// Get variable nameStringname=var.get(GRB.StringAttr.VarName);
intindex()#

This method returns the current index, or order, of the variable in theunderlying constraint matrix.

Note that the index of a variable may change after subsequent modelmodifications.

Return value:

-2: removed, -1: not in model, otherwise: index of the variablein the model

Example:
// Get variable indexintindex=var.index();
booleansameAs(GRBVarotherVar)#

Check whether two variable objects refer to the same variable.

Arguments:

otherVar – The other variable.

Return value:

Boolean result indicates whether the two variable objects referto the same model variable.

Example:
// Compare to a second variablebooleanisSame=var.sameAs(var2);
voidset(GRB.CharAttrattr,charnewval)#
voidset(GRB.DoubleAttrattr,doublenewval)#
voidset(GRB.IntAttrattr,intnewval)#
voidset(GRB.StringAttrattr,Stringnewval)#

Set the value of an attribute.

Arguments:
  • attr – The attribute being modified.

  • newval – The desired new value of the attribute.

Example:
// Set VType valuevar.set(GRB.CharAttr.VType,'B');// Set lower bound valuevar.set(GRB.DoubleAttr.LB,0.1);// Set VBasis valuevar.set(GRB.IntAttr.VBasis,-1);// Set variable namevar.set(GRB.StringAttr.VarName,"newName");

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp