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.addConstr or Model.addNLConstr), rather than by using the NLConstr constructor.

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, or Model.write on the associated model.

Attribute values are accessed as nlc.attr. For example, nlc.NLCName retrieves the constraint name, and nlc.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 AttributeError if the requested attribute doesn’t exist or can’t be queried. Raises a GurobiError if there is a problem with the NLConstr 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(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 (using Model.optimize), or write the model to disk (using Model.write).

Raises an AttributeError if the specified attribute doesn’t exist or can’t be set. Raises a GurobiError if there is a problem with the NLConstr object (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)