Specially ordered set variables of type 2 (SOS2)

Top  Previous  Next

At most two variables within a specially ordered set of type 2 (SOS2) can take on non-zero values.  The two non-zero values have to be for adjacent variables in that set.  Specially ordered sets of type 2 variables are declared as follows:

 

SOS2 Variable s2(i), t2(k,j), w2(i,j,k) ;

 

The members of the right-most index for each named item are defined as belonging to a special (SOS2) group or set of variables of which at most one of which can be non zero.

For example, in the SOS1 variables defined above,

s2 forms one group of SOS2 variables of which at most 2 can be non zero and they must be adjacent in terms of the set i.  The adjacency means if the set i has elements /a,b,c,d,f,g/  that one could have any 2 variables like the ones associated with set elements a and b but never a and c since the set elements are not adjacent.  This means the sets used must be ordered as discussed in the Sets chapter.
t2 defines a separate SOS2 set for each element of k and within each of those sets no more than 2 variables can be non zero.  Further, they they must be adjacent in terms of the set j.  The adjacency means if the set j has elements /j1,j2,j3,j4,j5,j6/  that one could have any 2 variables like j3 and j4 but never j1 and j6 since the set elements are not adjacent.  This means the set j must be ordered as discussed in the Sets chapter.
w2 defines a separate SOS2 set for each pair of elements in i and k.  Within each of those sets no more than 2 variables can be non zero and they must be adjacent in terms of the set j.  The adjacency means if the set j has elements /j1,j2,j3,j4,j5,j6/  that one could have any 2 variables like j3 and j4 but never j2 and j4 since the set elements are not adjacent.  This means the set j must be ordered as discussed in the Sets chapter.

Example:

prodschx.gms from the model library shows formulations with binary, SOS1 and SOS2 sets.

Notes:

The most common use of SOS2 sets is to model piece-wise linear approximations to nonlinear functions using separable programming.
One must use a mixed integer (MIP) solver to solve any model containing SOS2 variables.  But, the SOS2 variables do not have to take on integer solution levels.
The MIP solver is required because the solution process needs to impose both adjacency restrictions and the restrictions that no more than 2 nonzero level values can be present and to do this the solvers implicitly defines an additional set of zero one variables, then solves the problem as a MIP.
The default bounds for SOS2 variables are 0 to plus infinity.  As with any other variable, the user may set these bounds to whatever is required.
Not all MIP solvers allow SOS2 variables.  Furthermore, among the solvers that allow their use, the precise definition can vary from solver to solver.  Thus a model that contains these variables may not be perfectly transferable among solvers.  Please verify how the solver you are using handles SOS2 variables by checking the relevant section of the Solver Manual.