Performance when using "addSOS" method

325 views
Skip to first unread message

Will

unread,
Apr 21, 2017, 7:38:15 PM4/21/17
to Gurobi Optimization
I am curious about the performance difference between using model.addSOS(...) versus simply adding a constraint that a set must sum to one (or <= 1). Is the "addSOS" method simply a wrapper that creates that constraint, or is there a nuance to SOS's that I'm missing?

model.addSOS(GRB.SOS_TYPE1, [someArray[i] for i in someArrayIndices])

versus

model.addConstr(quicksum(someArray[i] for i in someArrayIndices) <= 1)

Even when I use the latter, the Gurobi command line solver explicitly calls out "Presolved model has 2467 SOS constraint(s)", so obviously Gurobi is recognizing the SOS set regardless, which makes me think there's no difference.

Thanks!

Tobias Achterberg

unread,
Apr 22, 2017, 11:34:11 AM4/22/17
to gur...@googlegroups.com
Are you sure that Gurobi claims to see SOS constraints even though you did not
explicitly add them via addSOS()? This should not happen.

Note that SOS1 constraints are more general than just sum xi <= 1. These two
constraints are only equivalent if all involved variables are binary (or general
integer with lower bounds of zero). But SOS1 can also deal with continuous
variables.

The meaning of SOS1(x1,...,xn) is that at most one of the involved variables can
be non-zero. If al variables are binary, then Gurobi will automatically convert
this into sum xi <= 1. If continuous variables are present, then we can
sometimes convert them into a sum zi <= 1 constraint with auxiliary binary
variables zi that are linked to the continuous xi variables via big-M
constraints. But if the big-M that is required for this translation is too
largen, then the SOS constraint will be kept as is. Such a constraint will not
participate in the LP relaxation, it will only be used for branching. More
precisely, if in an LP solution multiple xi variables take a non-zero value,
then one can branch on

(x1 = ... = xk = 0) or (xk+1 = ... = xn = 0)

with at least one of the non-zero variables being in each of the two sets.

Then, there is another type of SOS constraint, which is SOS2. A constraint
SOS2(x1,...,xn) means that at most two variables can be non-zero, and if there
are two non-zero variables they have to be adjacent in the list. For example, x2
and x4 being non-zero would be invalid, because they are not adjacent. This is
often used to model piece-wise linear functions.

Best regards,

Tobias

Tobias Achterberg

unread,
Apr 22, 2017, 12:06:32 PM4/22/17
to gur...@googlegroups.com
Note that the presolved model may contain SOS constraints if your original model
has semi-continuous or semi-integer variables, or if your original model has
general constraints. This is because sometimes (depending on bounds and other
data) we translate those modeling constructs into SOS constraints during presolve.

The SOS constraint that you are seeing have certainly nothing to do with the
linear constraints sum xi <= 1 that you have added through the model.addConstr()
method.

Regards,

Tobias
Reply all
Reply to author
Forward
0 new messages