Most of the information associated with a Gurobi model object is stored in a set of attributes. Attributes can be associated to: the model, the variables, the constraints (linear, quadratic, general, SOS). There are also solution quality attributes, multi-objective attributes, multi-scenario attributes and batch attributes. See Attribute Types for a list of attributes grouped by the modeling object to which they are associated to.
Examples:
- After optimizing a model, the model attribute Runtime stores the amount of time (in seconds) Gurobi spent solving the model.
- After optimizing a model, the variable attribute X stores the solution value of a variable.
- The variable attributes LB and UB store the lower and upper bounds of a variable, respectively.
- The linear constraint attribute ConstrName stores the name of a linear constraint.
Querying and modifying attributes
Not all attributes are modifiable: attributes computed by the Gurobi optimizer (such as X and Runtime) cannot be modified directly by the user, they can only be queried. Attributes representing input data (such as LB, UB, and ConstrName), can be modified directly by the user.
Every Gurobi API contains routines for querying or modifying attribute values. To retrieve or modify the value of a particular attribute, simply pass the name of the attribute to the appropriate query or modification routine.
Examples on how to access attributes:
- The Attribute Examples section of the documentation, which includes examples for Python, C, C++, C#, Java, and Visual Basic.
- How do I retrieve variable values after optimizing?
- Gurobi's Example Tour.
The full list of Gurobi attributes can be found in the Attribute Reference section of the documentation.