Special Ordered Sets (SOSs)
A Special Order Set (SOS) is a modeling tool for constraining a small number of consecutive variables in a vector to be nonzero. The Xpress Python interface allows for defining a SOS as follows:
sos (indices, weights, type, name)
The first argument, indices, is a list of variables, while weights is a list of floating point numbers. The type of SOS (either 1 or 2) is specified by type. While indices and weights are mandatory parameters, type and name are not; type is set to a default of 1 when not specified. Examples follow:
set1 = xp.sos (x, [0.5 + i*0.1 for i in range(10)], type = 2) set2 = xp.sos ([y[i] for i in range(5)], [i+1 for i in range(5)]) set3 = xp.sos ([v1, v2], [2, 5], 2)
One or more SOS can be added to a problem via the problem.addSOS method:
set1 = xp.sos (x, [0.5 + i*0.1 for i in range(10)], type = 2) m.addSOS (set1) n = 10 w = [xp.var () for i in range (n)] m.addSOS ([xp.sos ([w[i],w[i+1]], [2,3], type = 2) for i in range (n-1)])
The name member of a SOS object can be read and written by the user.