Documentation

Attributes


Attributes

As mentioned in the previous section, most of the information associated with a Gurobi model is stored in a set of attributes. Some attributes are associated with the variables of the model, some with the constraints of the model, and some with the model itself. After you optimize a model, for example, the solution is stored in the X variable attribute. Attributes that are computed by the Gurobi optimizer (such as the solution attribute) cannot be modified directly by the user, while those that represent input data (such as the LB attribute which stores variable lower bounds) can.

Each of the Gurobi language interfaces contains routines for querying or modifying attribute values. To retrieve or modify the value of a particular attribute, you simply pass the name of the attribute to the appropriate query or modification routine. In the C interface, for example, you'd make the following call to query the current solution value on variable 1:

  double x1;
  error = GRBgetdblattrelement(model, GRB_DBL_ATTR_X, 1, &x1);
This routine returns a single element from an array-valued attribute containing double-precision data. Routines are provided to query and modify scalar-valued and array-valued attributes of type int, double, char, or char *.

In the object oriented interfaces, you query or modify attribute values through the appropriate objects. For example, if variable v is a Gurobi variable object (a GRBVar), then the following calls would be used to modify the lower bound on v:

  C++:    v.set(GRB_DoubleAttr_LB, 0.0)
  Java:   v.set(GRB.DoubleAttr.LB, 0.0)
  C#:     v.Set(GRB.DoubleAttr.LB, 0.0) or v.LB = 0.0
  Python: v.lb = 0.0
The exact syntax for querying or modifying an attribute varies slightly from one language to another, but the basic approach remains consistent: you call the appropriate query or modification method using the name of the desired attribute as an argument.

The full list of Gurobi attributes can be found in the Attributes section of the Gurobi Reference Manual.