Optimize n variables, but valued with only specified number variables

66 views
Skip to first unread message

jingqiao hu

unread,
Nov 25, 2019, 9:33:28 AM11/25/19
to YALMIP
Dear Löfberg,

Is it possible that yalmip optimize n variables, but valued with only specified number variables?

For example, I defined 5 sdpvars x = [x1,x2,x3,x4,x5]. For 100 elements, every element is assigned a variable (one of x) with some constraints. I want to get the specific value x in each element. 

I defined this problem as follows:

cons1 = [];
cons2 = [];
cons5 = [];
for i = 1:5
        E{i} = sdpvar(3);
        cons2 = [cons2, E{i} >= 0]; 
        cons1 = [cons1, l <= trace(E{i}) <= u]; 
        cons5 = [cons5,E{i} - delta*eye(3) >= 0];        
end

trE = 0;
cons6 = [];
for i = 1:100
        idx{i} = intvar(1);
        cons6 = [cons6, 1 <= idx{i} <= 5];
            
        Ei = E{idx{i}};
        trE = trE + trace(Ei);

        sE(:, i) = [Ei(1, 1); Ei(1, 2); Ei(1, 3); Ei(2, 2); Ei(2, 3); Ei(3, 3)];
end

But the yalmip said "Unable to use a value of type sdpvar as an index."

How to define the problem correctly?

Thank you in  advance.

Johan Löfberg

unread,
Nov 25, 2019, 1:43:15 PM11/25/19
to YALMIP
As it says, YALMIP does not support z = x(y) for both x and y decision variables.

You have to implement the logic manually through binary variables and implications etc. Essentially

cases = binvar(n,1)
Model = [sum(cases)==1,implies(cases(1),[y == 1,z ==x(1)]),implies(cases(2),[y == 2,z==x(2)]),...]


Johan Löfberg

unread,
Nov 25, 2019, 2:04:13 PM11/25/19
to YALMIP
I spoke too early. x(y) is supported

>> sdpvar x
>> intvar y
>> x(y)
Nonlinear scalar (real, models 'milpsubsref', 1 variable)
Coefficients range: 1 to 1

You have x{y} which is something very different. Hence, here it would be

sdpvar trEi
trE = trE + trEi;
Model = [sum(cases)==1, implies(cases(1),[idx{i}==1, trEi == trace(E{1})]),...



jingqiao hu

unread,
Nov 26, 2019, 2:44:18 AM11/26/19
to YALMIP
Thank you so much, Dr. Löfberg.

Implications seem not applicable to my problem. In each implication, I need to get the corresponding SDP-matrix value (for the following constraint) and its trace. Thus I change to

Model = [Model, sum(cases)==1, implies(cases(1),[trEi == trace(E{1}), Em{i} == E{1}]),...

But with the warning: "Warning: You have unbounded variables in IMPLIES leading to a lousy big-M relaxation."

The var trEi has explicit bounds, but Em{ionly has lower bound. 

I tried to add fake upbound for Em{i}, big-M relaxation waring still exists.

Model = [Model, l <= trEi <= u,
           0<= Em{i}<=100, % Em{i}<=100 is fake upbound
           Em{i} - delta*eye(3) >= 0];

All codes are in the attachment. How to get rid of the big-M relaxation?

getK.m
main.m

Johan Löfberg

unread,
Nov 26, 2019, 2:54:31 AM11/26/19
to YALMIP
You cannot get rid of the big-M relaxation. You have a constraint which requires it if you intend to solve the problem using a mixed-integer solver, and thus you have to impose bounds on all variables involved in your logic constraints

Note that you need elementwise bounds, so 0<= Em{i}(:) <=100 (you can have semidefinite too if you want, but elementwise is required)

Johan Löfberg

unread,
Nov 26, 2019, 3:02:50 AM11/26/19
to YALMIP
Also note that your code indicates that you think mosek can be used to solve a mixed-integer SDP. It cannot. YALMIP has built-in MISDP solvers though

Johan Löfberg

unread,
Nov 26, 2019, 3:05:10 AM11/26/19
to YALMIP
and the code can be simplified by using tr(Em{i}) and removing trEi

jingqiao hu

unread,
Nov 26, 2019, 7:36:56 AM11/26/19
to YALMIP
Thank you so much, Dr. Löfberg.

I changed the solver to "bnb" and "cutsdp" and added elementwise bounds, the solution is totally wrong. I will reconstruct my problem in a valid way.

Johan Löfberg

unread,
Nov 26, 2019, 7:42:54 AM11/26/19
to yal...@googlegroups.com
You would have to explain what you mean with totally wrong (and supply reproducible code)
Reply all
Reply to author
Forward
0 new messages