Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

gurobipy.SOS#

classSOS#

Gurobi SOS constraint object. SOS constraints are always associated witha particular model. You create an SOS object by adding an SOS constraintto a model (usingModel.addSOS), rather than by using an SOSconstructor. Similarly, SOS constraints are removed using theModel.remove method.

An SOS constraint can be of type 1 or 2 (GRB.SOS_TYPE1 orGRB.SOS_TYPE2). A type 1 SOS constraint is a set of variables whereat most one variable in the set may take a value other than zero. A type2 SOS constraint is an ordered set of variables where at most twovariables in the set may take non-zero values. If two take non-zerovalues, they must be contiguous in the ordered set.

SOS constraint objects have a number of attributes,e.g.,IISSOS, which can bequeried with theSOS.getAttr method.

The full list of attributescan be found in theAttributes section of thisdocument. Examples of how to query and set attributes can also be foundinthis section.

getAttr(attrname)#

Query the value of an SOS attribute.

Raises anAttributeError if the requested attribute doesn’t exist orcan’t be queried. Raises aGurobiError if there is a problem withtheSOS 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))
propertyindex#

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

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

Returns:

-2: removed, -1: not in model, otherwise: index of the SOSconstraint 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 (usingModel.update), optimize the model (usingModel.optimize), or write the model to disk (usingModel.write).

Raises anAttributeError if the specified attribute doesn’t exist orcan’t be set. Raises aGurobiError if there is a problem with theSOS 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)

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp