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:
|.NET||GRB.DoubleAttr.LB, or just var.LB|
|Python||GRB.Attr.lb, or just var.lb|
To query the value of this attribute for an individual variable in
the different API's, you would do the following:
|Language||Attribute Query Example|
|C||GRBgetdblattrelement(model, GRB_DBL_ATTR_LB, var_index, &value);|
|.NET||var.Get(GRB.DoubleAttr.LB), or just var.LB|
|Python||var.getAttr(GRB.Attr.lb), or just var.lb|
Our APIs also include routines for querying attribute values for multiple variables or constraints at once, which is more efficient.
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,
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).
Refer to the following sections for more detailed examples of how to query or modify attributes from our various API's:Examples to get a better sense of how to use our attribute interface.