Try our new documentation site (beta).
Filter Content By
Version
Text Search
Table of contents
Filter by Language
Python Attribute Examples
Consider the case where you have a Gurobi model . You can
retrieve the number of variables in the model by querying the
NumVars model attribute:
print(m.numVars)(Note that attribute capitalization doesn't matter in the Python interface, so you could also query
If you've performed optimization on the model, the optimal objective value can be obtained by querying the ObjVal model attribute:
print(m.objVal)
If you'd like to query the value that a variable takes in the computed solution, you can query the X attribute for the corresponding variable object:
for v in m.getVars(): print(v.x)You can also query the value of
print(m.getAttr(GRB.Attr.X, m.getVars()))
For each attribute query method, there's an analogous routine.
To set the upper bound of a variable, for example:
v = m.getVars()[0] v.ub = 0(In this example, we've set the upper bound for the first variable in the model to 0).








