1

When defining a mixed integer linear programming problem using pulp, one may define sos like so:

x1 = LpVariable('x1', cat = LpInteger)
x2 = LpVariable('x2', cat = LpInteger)
prob.sos1['sos'] = x1 + 2*x2

(an "sos", or specially ordered set, is a special constraint specifying that only a single variable in the set may be nonzero).

We see that this allows specifying weights for the sos variables (1,2 in this case). Presumably they define the precedence of each variable, i.e. which variables to allow to be nonzero first when branching.

But how exactly are the weights defined?

The underlying solver is coin-or-cbc, and I couldn't find anything about how they use SOS weights.

Ant6n
  • 1,887
  • 1
  • 20
  • 26

1 Answers1

2

Weights can be used for branching, although not all solvers use them that way. I believe CBC does, but you'll probably need to check the source code to confirm.

Weights in SOS2 are often needed to specify the ordering (SOS2 has the concept of neighbors). SOS1 does not have this issue.

Finally, if you have good bounds, binary variables are often better than SOS1 variables. Solvers do better bounding and generate better cuts when using binary variables. My rule is: if you can formulate a SOS1 structure with binary variables using good big-M values use binary variables. If you cannot find good big-M values, consider SOS1.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • Yes, it seems I can't get SOS to have any positive impact for my problems, where there's already a constraint `sum(bin_var_i, i=0..n) = 1`. This is both for cbc-coin-or and gurobi. I guess you're right that SOS's are more of a fallback when upper bounds aren't known for variables. – Ant6n Sep 19 '18 at 11:25