MConstr


MConstr

Gurobi matrix constraint object. An MConstr object is an array-like data structure that represents multiple linear constraints (in contrast to a Constr object, which represents a single constraint). It behaves similar to NumPy's ndarrays, e.g., it has a shape and can be indexed and sliced. Matrix constraints are always associated with a particular model. You typically create these objects with Model.addConstr, using overloaded comparison operators on matrix variables and linear matrix expressions, or with the method Model.addMConstr.

Constraint objects have a number of attributes. The full list can be found in the Attributes section of this document. Some constraint 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.

We should point out a few things about constraint attributes. Consider the rhs attribute. The values for a matrix constraint mc can be queried using mc.rhs. The Gurobi library ignores letter case in attribute names, so it can also be queried as mc.RHS. Attribute values are returned as a NumPy ndarray that has the same shape as mc. An attribute can be set, using a standard assignment statement (e.g., constr.rhs = b), with b being either an ndarray with the appropriate shape, or a scalar which is then applied to all of the associated constraints. However, as mentioned earlier, attribute modification is done in a lazy fashion, so you won't see the effect of the change immediately. And some attributes can not be set (e.g., the Pi attribute), so attempts to assign new values to them will raise an exception.

You can also use MConstr.getAttr/ MConstr.setAttr to access attributes. The attribute name can be passed to these routines as a string, or you can use the constants defined in the GRB.Attr class (e.g., GRB.Attr.RHS).



Subsections