gurobipy.SOS#
- class SOS#
Gurobi SOS constraint object. SOS constraints are always associated with a particular model. You create an SOS object by adding an SOS constraint to a model (using
Model.addSOS), rather than by using an SOS constructor. Similarly, SOS constraints are removed using theModel.removemethod.An SOS constraint can be of type 1 or 2 (
GRB.SOS_TYPE1orGRB.SOS_TYPE2). A type 1 SOS constraint is a set of variables where at most one variable in the set may take a value other than zero. A type 2 SOS constraint is an ordered set of variables where at most two variables in the set may take non-zero values. If two take non-zero values, they must be contiguous in the ordered set.SOS constraint objects have a number of attributes, e.g., IISSOS, which can be queried with the
SOS.getAttrmethod.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)#
Query the value of an SOS attribute.
Raises an
AttributeErrorif the requested attribute doesn’t exist or can’t be queried. Raises aGurobiErrorif there is a problem with theSOSobject (e.g., it was removed from the model).- Parameters:
attrname – The attribute being queried.
- Returns:
The current value of the requested attribute.
- Example:
print(sos.getAttr(GRB.Attr.IISSOS))
- setAttr(attrname, newvalue)#
Set the value of an SOS 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 theSOSobject (e.g., it was removed from the model).- Parameters:
attrname – The attribute being modified.
newvalue – The desired new value of the attribute.
- Example:
sos.setAttr(GRB.Attr.IISSOSForce, 1) var.setAttr("IISSOSForce", 0.0)