# Matlab, CVX, mosek, gurobi, Special ordered set (SOS) variables in MILP

(Quentin_EE) #1

CVX has employed the mosek solver to solve the MILP. While in MILP, there exists a special ordered set (SOS), which is quite useful for coverting the MINLP (mixed-integer nonlinear program) into a standard MILP. Thus, I’m writing to ask how to specify such kinds of vectors in CVX?

For example, if in the problem, some varoables can only take one values in a set {a1, a2, a3, a4}, how to present this?

Thank your very much. For the SOS, you may refer to the following link on wiki.

SOS

The constaint I want to express is shown in the following: where v_i and u_{i,p} are SOS1 but the non-zero elements are not necessary 1, and can be e.g., integers less than 20. The v’i and u’{i,p} are binary SOS1 vectors. Thus, can anyone help on how to express this constraints in CVX? Thanks.

Gurobi MILP CVX
(Mark L. Stone) #2

In CVX, you’ll have to do this “manually” using declared binary variables.

If you really want to deal with SOS variables as such, you may be better off using some way other than CVX to specify your model and call the solver.

(Quentin_EE) #3

Thanks for the reply. How can I declare a vector, in which only one entry is an integer and the other entries are all zero in CVX？or can this be achieved by using some constraints?

Btw, how to specify the range of the integer variables? For example, if the non-zero entry can only choose from [ 2 3 5 9].

Thank you very much.

(Erling D.Andersen) #4

Normally you model SOS1 sets with

\sum_j x_j = 1 \mbox{ and } x_j \in \{0,1\}.

You could

t = 2 x_1 + 3 x_2 + 5 x_3 + 9x_4

and x should binary and sum to 1.

(Quentin_EE) #5

Thank you very much for your reply. I know that for the binary SOS1 vector, it is easy to use the trick as your mentioned to express. While, currently, I met a problem with two vector variables: say x1 and x2 having the same length. In my problem, they have the different non-zero values at the same index, like [0 a1 0 0] and [0 1 0 0]. As a1 is an integer and also an optimziation variable, I do not knw how how to express x1. Could you help on this issue ?

(Quentin_EE) #6

The constaint I want to express is shown in the following: where v_i and u_{i,p} are SOS1 but the non-zero elements are not necessary 1, and can be e.g., integers less than 20. The v’i and u’{i,p} are binary SOS1 vectors. Thus, can anyone help on how to express this constraints in CVX? Thanks.

(Quentin_EE) #7

Hi Mark, I have clearly presented my problem as in the following reply. Could you take a look at it? Thanks.

(Quentin_EE) #8

Mosek is a very good solver. I just tried to use it to solve the above problem, but do not know how to implement this non-binary vector.

(Erling D.Andersen) #9

You have to look in the CVX documentation to see how you specify general integer variables since you do not call Mosek directly.

To declare integer rather than binary, use integer rather than binary in the variable declaration, per http://cvxr.com/cvx/doc/basics.html#variables .