Concepts
Features
Reference
Gurobi quadratic constraint object. Quadratic constraints are alwaysassociated with a particular model. You create a quadratic constraintobject by adding a quadratic constraint to a model (usingModel.addQConstr), rather than by using aQConstrconstructor.
Quadratic constraint objects have a number of attributes.Some constraint attributes can only be queried, while otherscan also be set. Recall that the Gurobi optimizer employs a lazy updateapproach, so changes to attributes don’t take effect until the next calltoModel.update,Model.optimize,Model.write on the associated model.
We should point out a few things about quadratic constraint attributes.Consider theqcrhs attribute. Its value can be queried usingqconstr.qcrhs. The Gurobi library ignores letter case in attributenames, so it can also be queried asqconstr.QCRHS. It can be setusing a standard assignment statement (e.g.,qconstr.qcrhs=0).However, as mentioned earlier, attribute modification is done in a lazyfashion, so you won’t see the effect of the change immediately. And someattributes can not be set (e.g., theqcpi attribute), so attempts toassign new values to them will raise an exception.
You can also useQConstr.getAttr/QConstr.setAttr to access attributes. The attributename can be passed to these routines as a string, or you can use theconstants defined in theGRB.Attr class (e.g.,GRB.Attr.QCRHS).
The full list of attributescan be found in theAttributes section of thisdocument. Examples of how to query and set attributes can also be foundinthis section.
Query the value of a quadratic constraint attribute.
Raises anAttributeError if the requested attribute doesn’t exist orcan’t be queried. Raises aGurobiError if there is a problem withtheQConstr object (e.g., it was removed from the model).
attrname – The attribute being queried.
The current value of the requested attribute.
print(qconstr.getAttr(GRB.Attr.QCSense))print(qconstr.getAttr("qcsense"))
Set the value of a quadratic constraint attribute. Note that, due to our lazy update approach,the change won’t actually take effect until you update the model (usingModel.update), optimize the model (usingModel.optimize), or write the model to disk (usingModel.write).
Raises anAttributeError if the specified attribute doesn’t exist orcan’t be set. Raises aGurobiError if there is a problem with theQConstr object (e.g., it was removed from the model).
attrname – The attribute being modified.
newvalue – The desired new value of the attribute.
constr.setAttr(GRB.Attr.QCRHS,0.0)constr.setAttr("qcrhs",0.0)
Help and Feedback