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 the Model.remove method.

An SOS constraint can be of type 1 or 2 (GRB.SOS_TYPE1 or GRB.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 one attribute, IISSOS, which can be queried with the SOS.getAttr method.

getAttr(attrname)#

Query the value of an SOS attribute. The full list of available attributes can be found in the Attributes section.

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 SOS 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(sos.getAttr(GRB.Attr.IISSOS))
property index#

This property returns the current index, or order, of the SOS constraint in the underlying model.

Note that the index of an SOS constraint may change after subsequent model modifications.

Returns:

-2: removed, -1: not in model, otherwise: index of the SOS constraint in the model

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 (using Model.optimize), or write the model to disk (using Model.write).

The full list of available attributes can be found in the Attributes section.

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 SOS object (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)