Attributes

The primary mechanism for querying and modifying properties of a Gurobi model is through the attribute interface. A variety of different attributes are available. Some are only populated at certain times (e.g., those related to the solution of a model), while others are available at all times (e.g., the number of variables in the model). Attributes can be associated with variables (e.g., lower bounds), constraints (e.g., the right-hand side), SOSs (e.g., IIS membership), or with the model as a whole (e.g., the objective value for the current solution).

The same attributes exist in all of the Gurobi APIs, but the approaches used to query and modify them, and the means by which you refer to them vary. Consider the LB attribute, which captures the lower bound on a variable. You would refer to this attribute as follows in the different Gurobi APIs:
Language Attribute
C GRB_DBL_ATTR_LB
C++ GRB_DoubleAttr_LB
Java GRB.DoubleAttr.LB
.NET GRB.DoubleAttr.LB
Python GRB.attr.lb, or just var.lb

To query the value of this attribute in the different API's, you would do the following:
Language Attribute Query Example
C GRBgetdblattrelement(model, GRB_DBL_ATTR_LB, var_index);
C++ var.get(GRB_DoubleAttr_LB)
Java var.get(GRB.DoubleAttr.LB)
.NET var.Get(GRB.DoubleAttr.LB)
Python var.getAttr(GRB.attr.lb), or just var.lb

Attributes are referred to using a set of enum types in C++, Java, and .NET (one enum for double-valued attributes, one for int-valued attributes, etc.). In C and Python, the names listed above are simply constants that take string values. For example, GRB_DBL_ATTR_LB is defined in the C layer as:

#define GRB_DBL_ATTR_LB "LB"
In C and Python, you have the option of using the strings directly when calling attribute methods. If you wish to do so, note that character case and underscores are ignored. Thus, MIN_COEFF and MinCoeff are equivalent.

One important point to note about attributes modification is that it is done in a lazy fashion. Modifications don't actually affect the model until the next request to either update or optimize the model (GRBupdatemodel or GRBoptimize in C).

The following tables list the full set of Gurobi attributes. The attributes have been grouped by type: model attributes take scalar values, while variable, constraint, and SOS attributes contain one entry per variable, constraint, or SOS in the model. The APIs provide methods to query attribute values for individual constraints or variables, or to query their values for arrays of constraints or variables. Array queries are generally more efficient.

Note that the attributes that provide solution quality information have been split off into a separate table at the end of this section. These attributes are also associated with the model as a whole.

Some solution attributes require information that is only computed by certain Gurobi algorithms. The tables below note such cases. For example, the VBasis and CBasis attributes can only be queried when a simplex basis is available (a basis is available when a continuous model has been solved using primal simplex, dual simplex, or barrier with crossover). Sensitivity information (SAObjLow, SAObjUp, etc.) is also only available for basic solutions.

Model attributes:

Attribute name Attribute type Settable? Description
NumConstrs int No Number of constraints.
NumVars int No Number of variables.
NumSOS int No Number of SOS constraints.
NumQConstrs int No Number of quadratic constraints.
NumNZs int No Number of non-zero coefficients in the constraint matrix.
NumQNZs int No Number of non-zero quadratic objective terms.
NumQCNZs int No Number of non-zero terms in quadratic constraints (includes both the linear and the quadratic terms).
NumIntVars int No Number of integer variables (including binary variables).
NumBinVars int No Number of binary variables.
ModelName string Yes Model name.
ModelSense int Yes Model sense (+1 for minimize, -1 for maximize).
ObjCon double Yes Constant offset for objective function.
ObjVal double No Objective value for current solution.
ObjBound double No Best available bound on solution (lower bound for minimization, upper bound for maximization).
Runtime double No Runtime (in seconds) for most recent optimization. Note that all times in the Gurobi Optimizer are wall-clock times.
Status int No Current status of model (status values are described in the Status Code section).
SolCount int No Number of solutions found.
IterCount double No Number of simplex iterations performed in most recent optimization.
BarIterCount int No Number of barrier iterations performed in most recent optimization.
NodeCount double No Number of branch-and-cut nodes explored in most recent optimization.
IsMIP int No Indicates whether the model has any discrete elements. Discrete elements include binary, integer, semi-continuous, and semi-integer variables, and SOS constraints.
IsQP int No Indicates whether the model is a quadratic programming problem. Note that a model with both a quadratic objective and quadratic constraints is classified as a QCP, not a QP. Thus, IsQP is 0 for such a model.
IsQCP int No Indicates whether the model has quadratic constraints.
IISMinimal int No Indicates whether the current IIS is minimal (this will only be 0 if the IIS computation was stopped early).
MaxCoeff double No Maximum constraint matrix coefficient (in absolute value).
MinCoeff double No Minimum (non-zero) constraint matrix coefficient (in absolute value).
MaxBound double No Maximum finite variable bound.
MinBound double No Minimum (non-zero) variable bound.
MaxObjCoeff double No Maximum linear objective coefficient (in absolute value).
MinObjCoeff double No Minimum (non-zero) linear objective coefficient (in absolute value).
MaxRHS double No Maximum constraint right-hand side (in absolute value).
MinRHS double No Minimum (non-zero) constraint right-hand side (in absolute value).
Kappa double No Estimated condition number of current LP basis matrix. Only available for basic solutions.
KappaExact double No Exact condition number of current LP basis matrix. Only available for basic solutions.
FarkasProof double No Magnitude of infeasibility violation in Farkas infeasibility proof (for infeasible linear models only). A Farkas infeasibility proof identifies a new constraint, obtained by taking a linear combination of the constraints in the model, that can never be satisfied (The linear combination is available in the FarkasDual attribute). This attribute indicates the magnitude of the violation of this aggregated constraint. Only available when parameter InfUnbdInfo is set to 1.

Variable attributes:

Attribute name Attribute type Settable? Description
LB double Yes Variable lower bound. Note that any value less than -1e20 is treated as infinite.
UB double Yes Variable upper bound. Note that any value greater than 1e20 is treated as infinite.
Obj double Yes Variable linear objective coefficient.
VType char Yes Variable type ('C' for continuous, 'B' for binary, 'I' for integer, 'S' for semi-continuous, or 'N' for semi-integer). Binary variables must be either 0 or 1. Integer variables can take any integer value between the specified lower and upper bounds. Semi-continuous variables can take any value between the specified lower and upper bounds, or a value of zero. Semi-integer variables can take any integer value between the specified lower and upper bounds, or a value of zero.
VarName string Yes Variable name.
X double No The variable value in the current solution.
Xn double No The variable value in a sub-optimal MIP solution. Use parameter SolutionNumber to indicate which alternate solution to retrieve. Solutions are sorted in order of worsening objective value. Thus, when SolutionNumber is 1, Xn returns the second-best solution found. When SolutionNumber is equal to its default value of 0, querying attribute Xn is equivalent to querying attribute X.
RC double No The reduced cost in the current solution. Only available for continuous models.
Start double Yes The current MIP start vector. The MIP solver will attempt to build an initial solution from this vector when it is available. Note that the start can be partially populated -- the MIP solver will attempt to fill in values for missing start values. If you wish to leave the start value for a variable undefined, you can either avoid setting the Start attribute for that variable, or you can set it to a special undefined value (GRB_UNDEFINED in C and C++, or GRB.UNDEFINED in Java, .NET, and Python).
BranchPriority int Yes Variable branching priority. The value of this attribute is used as the primary criteria for selecting a fractional variable for branching during the MIP search. Variables with larger values always take priority over those with smaller values. Ties are broken using the standard branch variable selection criteria. The default variable branch priority value is zero.
VBasis int Yes The status of a given variable in the current basis. Possible values are 0 (basic), -1 (non-basic at lower bound), -2 (non-basic at upper bound), and -3 (super-basic). Note that, if you wish to specify an advanced starting basis, you must set basis status information for all constraints and variables in the model. Only available for basic solutions.
PStart double Yes The current simplex start vector. If you set PStart values for every variable in the model and DStart values for every constraint, then simplex will use those values to compute a warm start basis. If you'd like to retract a previously specified start, set any PStart value to GRB_UNDEFINED.
IISLB int No For an infeasible model, indicates whether the lower bound participates in the computed Irreducible Inconsistent Subsystem (IIS).
IISUB int No For an infeasible model, indicates whether the upper bound participates in the computed Irreducible Inconsistent Subsystem (IIS).
SAObjLow double No Objective coefficient sensitivity information: smallest objective value at which the current optimal basis would remain optimal. Only available for basic solutions.
SAObjUp double No Objective coefficient sensitivity information: largest objective value at which the current optimal basis would remain optimal. Only available for basic solutions.
SALBLow double No Lower bound sensitivity information: smallest lower bound value at which the current optimal basis would remain optimal. Only available for basic solutions.
SALBUp double No Lower bound sensitivity information: largest lower bound value at which the current optimal basis would remain optimal. Only available for basic solutions.
SAUBLow double No Upper bound sensitivity information: smallest upper bound value at which the current optimal basis would remain optimal. Only available for basic solutions.
SAUBUp double No Upper bound sensitivity information: largest upper bound value at which the current optimal basis would remain optimal. Only available for basic solutions.
UnbdRay double No Unbounded ray (for unbounded linear models only). Provides a vector that, when added to any feasible solution, yields a new solution that is also feasible but improves the objective. Only available when parameter InfUnbdInfo is set to 1.

Constraint attributes:

Attribute name Attribute type Settable? Description
Sense char Yes Constraint sense ('<', '>', or '=').
RHS double Yes Constraint right-hand side.
ConstrName string Yes Constraint name.
Pi double No The constraint dual value in the current solution (also known as the shadow price). Only available for continuous models.
Slack double No The constraint slack in the current solution.
CBasis int Yes The status of a given constraint in the current basis. Possible values are 0 (basic) or -1 (non-basic). Note that, if you wish to specify an advanced starting basis, you must set basis status information for all constraints and variables in the model. Only available for basic solutions.
DStart double Yes The current simplex start vector. If you set PStart values for every variable in the model and DStart values for every constraint, then simplex will use those values to compute a warm-start basis. If you'd like to retract a previously specified start, set any DStart value to GRB_UNDEFINED.
IISConstr int No For an infeasible model, indicates whether the constraint participates in the computed Irreducible Inconsistent Subsystem (IIS).
SARHSLow double No Right-hand-side sensitivity information: smallest right-hand-side value at which the current optimal basis would remain optimal. Only available for basic solutions.
SARHSUp double No Right-hand-side sensitivity information: largest right-hand-side value at which the current optimal basis would remain optimal. Only available for basic solutions.
FarkasDual double No Farkas infeasibility proof (for infeasible linear models only). Provides a dual unbounded vector. Adding this vector into any feasible solution to the dual model yields a new solution that is also feasible but improves the dual objective. Only available when parameter InfUnbdInfo is set to 1.

SOS attributes:

Attribute name Attribute type Settable? Description
IISSOS int No For an infeasible model, indicates whether the SOS constraint participates in the computed Irreducible Inconsistent Subsystem (IIS).

Quadratic constraint attributes:

Attribute name Attribute type Settable? Description
QCSense char Yes Quadratic constraint sense ('<', '>', or '=').
QCRHS double Yes Quadratic constraint right-hand side.
QCName string Yes Quadratic constraint name.
QCPi double No The constraint dual value in the current solution.
QCSlack double No The constraint slack in the current solution.
IISQConstr int No For an infeasible model, indicates whether the quadratic constraint participates in the computed Irreducible Inconsistent Subsystem (IIS).

Solution quality attributes:

Attribute name Attribute type Settable? Model type Description
BoundVio double No All Maximum (unscaled) bound violation.
BoundSVio double No Continuous Maximum (scaled) bound violation.
BoundVioIndex int No All Index of variable with the largest (unscaled) bound violation.
BoundSVioIndex int No Continuous Index of variable with the largest (scaled) bound violation.
BoundVioSum double No All Sum of (unscaled) bound violations.
BoundSVioSum double No Continuous Sum of (scaled) bound violations.
ConstrVio double No All Maximum (unscaled) constraint violation.
ConstrSVio double No Continuous Maximum (scaled) constraint violation.
ConstrVioIndex int No All Index of constraint with the largest (unscaled) violation.
ConstrSVioIndex int No Continuous Index of constraint with the largest (scaled) violation.
ConstrVioSum double No All Sum of (unscaled) constraint violations.
ConstrSVioSum double No Continuous Sum of (scaled) constraint violations.
ConstrResidual double No Continuous Maximum (unscaled) primal constraint error.
ConstrSResidual double No Continuous Maximum (scaled) primal constraint error.
ConstrResidualIndex int No Continuous Index of variable with the largest (unscaled) primal constraint error.
ConstrSResidualIndex int No Continuous Index of variable with the largest (scaled) primal constraint error.
ConstrResidualSum double No Continuous Sum of (unscaled) primal constraint errors.
ConstrSResidualSum double No Continuous Sum of (scaled) primal constraint errors.
DualVio double No Continuous Maximum (unscaled) reduced cost violation.
DualSVio double No Continuous Maximum (scaled) reduced cost violation.
DualVioIndex int No Continuous Index of variable with the largest (unscaled) reduced cost violation.
DualSVioIndex int No Continuous Index of variable with the largest (scaled) reduced cost violation.
DualVioSum double No Continuous Sum of (unscaled) reduced cost violations.
DualSVioSum double No Continuous Sum of (scaled) reduced cost violations.
DualResidual double No Continuous Maximum (unscaled) dual constraint error.
DualSResidual double No Continuous Maximum (scaled) dual constraint error.
DualResidualIndex int No Continuous Index of variable with the largest (unscaled) dual constraint error.
DualSResidualIndex int No Continuous Index of variable with the largest (scaled) dual constraint error.
DualResidualSum double No Continuous Sum of (unscaled) dual constraint errors.
DualSResidualSum double No Continuous Sum of (scaled) dual constraint errors.
ComplVio double No Continuous In an optimal solution, the product of the value of a variable and its reduced cost must be zero. This isn't always strictly true for interior point solutions. This attribute returns the maximum complementarity violation for any variable.
ComplVioIndex int No Continuous Index of variable with the largest complementarity violation.
ComplVioSum double No Continuous Sum of complementarity violations.
IntVio double No MIP A MIP solver won't always assign strictly integral values to integer variables. This attribute returns the largest distance between the computed value of any integer variable and the nearest integer.
IntVioIndex int No MIP Index of variable with the largest integrality violation.
IntVioSum double No MIP Sum of integrality violations.