8.7.8. Constr¶
- class Constr¶
Represents a constraint in the model. The index of the constraint starts at 0 and increases by 1 each time a new constraint is added to the model. Constraints are typically expressed as equations or inequalities.
Properties
The index of the constraint
- index¶
The index of the constraint.
Methods
Obtain the attribute value associated with the constraint
Test whether the constraint is the same as another constraint
Set the attribute value associated with the constraint
- getAttr(attrname)¶
Obtain the attribute value associated with the constraint.
- Parameters
attrname – Attribute name
example:
m = Model() x = m.addVar() c = m.addConstr(2 * x <= 1) print(c.rhs) print(c.getAttr(MDO.Attr.RHS))
Note
Attributes can also be read and written directly through object attributes; in this case, the attribute name is case-insensitive
- sameAs(constr)¶
Test whether the constraint is the same as another constraint.
- Parameters
constr – Another constraint to be tested.
example:
m = Model() x = m.addVar() c = m.addConstr(2 * x <= 1) assert (c.sameAs(m.getConstrs()[0]))
- setAttr(attrname, attrvalue)¶
Set the attribute value associated with the constraint.
- Parameters
attrname – The name of the attribute.
attrvalue – The value of the attribute to be set.
example:
m = Model() x = m.addVar() c = m.addConstr(2 * x <= 1) c.rhs = 2.0 c.setAttr(MDO.Attr.RHS, 2.0)
Note
Attribute can also be read and written directly through object attributes; in this case, the attribute name is case-insensitive.