gurobipy.GenConstr#
- class GenConstr#
Gurobi general constraint object. General constraints are always associated with a particular model. You add a general constraint to a model either by using one of the
Model.addGenConstr*
methods, or by usingModel.addConstr
orModel.addConstrs
plus a general constraint helper function).General constraint objects have a number of attributes, which can be queried with the
GenConstr.getAttr
method. The full list can be found in the Attributes section of this document.- getAttr(attrname)#
Query the value of a general constraint attribute. The full list of available attributes can be found in the Attributes section.
Raises an
AttributeError
if the requested attribute doesn’t exist or can’t be queried. Raises aGurobiError
if there is a problem with theGenConstr
object (e.g., it was removed from the model).- Parameters:
attrname – The attribute being queried.
- Returns:
The current value of the requested attribute.
- Example:
print(genconstr.getAttr(GRB.Attr.GenConstrType)) print(genconstr.getAttr("GenConstrType"))
- setAttr(attrname, newvalue)#
Set the value of a general constraint attribute. Note that, due to our lazy update approach, the change won’t actually take effect until you update the model (using
Model.update
), optimize the model (usingModel.optimize
), or write the model to disk (usingModel.write
).The full list of available attributes can be found in the Attributes section.
Raises an
AttributeError
if the specified attribute doesn’t exist or can’t be set. Raises aGurobiError
if there is a problem with theGenConstr
object (e.g., it was removed from the model).- Parameters:
attrname – The attribute being modified.
newvalue – The desired new value of the attribute.