gurobipy.NLConstr#
- class NLConstr#
Gurobi nonlinear constraint object. Nonlinear constraints are always associated with a particular model. You create a nonlinear constraint object by adding a constraint to a model (using
Model.addConstrorModel.addNLConstr), rather than by using theNLConstrconstructor.Nonlinear constraint objects have a number of attributes. Some attributes can only be queried, while others can also be set. Recall that the Gurobi Optimizer employs a lazy update approach, so changes to attributes don’t take effect until the next call to
Model.update,Model.optimize, orModel.writeon the associated model.Attribute values are accessed as
nlc.attr. For example,nlc.NLCNameretrieves the constraint name, andnlc.NLCSense = '<'sets the constraint sense.The section Nonlinear Constraint Attributes lists the attributes specific to this type of constraint. The full list of attributes can be found in the Attributes section of this document. Examples of how to query and set attributes can also be found in this section.
- getAttr(attrname)#
Queries the value of a nonlinear constraint attribute.
Raises an
AttributeErrorif the requested attribute doesn’t exist or can’t be queried. Raises aGurobiErrorif there is a problem with theNLConstrobject (e.g., it was removed from the model).- Parameters:
attrname – The attribute being queried.
- Returns:
The current value of the requested attribute.
- Example:
print(nlconstr.getAttr(GRB.Attr.NLCSense)) print(nlconstr.getAttr("nlcsense"))
- setAttr(attrname, newvalue)#
Sets the value of a nonlinear 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).Raises an
AttributeErrorif the specified attribute doesn’t exist or can’t be set. Raises aGurobiErrorif there is a problem with theNLConstrobject (e.g., it was removed from the model).- Parameters:
attrname – The attribute being modified.
newvalue – The desired new value of the attribute.
- Example:
constr.setAttr(GRB.Attr.NLCRHS, 0.0) constr.setAttr("nlcrhs", 0.0)