sdpvar index multiplication problem

15 views
Skip to first unread message

Qianyuan Zheng

unread,
Oct 18, 2019, 4:32:53 AM10/18/19
to YALMIP
Hi everyone,

I met a problem when I want sdpvar(sdpvar) * sdpvar(sdpvar).

Part of my code is as follow:

price_f=rand(48,1)
t_var = intvar(1,1);
p_ev = sdpvar(48,1);
price_el=sdpvar(48,1);

% objective
price_ev = 0;
power = 0;

for i =0:4
    
    power = power + p_ev(t_var+i);
    price_ev = price_ev + p_ev(t_var+i) * price_el(t_var+i);
    
end
% constr
price_constr = [price_el == price_f];


where p_ev(t_var+i) and price_el(t_var+i) are both "Nonlinear scalar (real, models 'milpsubsref', 1 variable)", 
but p_ev(t_var+i) * price_el(t_var+i) has no output.





Johan Löfberg

unread,
Oct 18, 2019, 4:52:42 AM10/18/19
to YALMIP
Why are you adding price_el == price_f afterwards?

The model you create now is extremely hard and bad (decision variables in indexing and bilinear products)

If you really have price_el = price_f, a much better model (linear) is to simply enumerate the cases using a binary representation

which = binvar(1,48);
t_var = which*(1:48)';
powers = sdpvar(5,1);
price_evs = sdpvar(5,1);
Model = [sum(which)==1];
for i = 0:4
    for j = 1:48
        if j + i <= 48
            Model = [Model, implies(which(j),powers(i+1) == p_ev(j + i))];
            Model = [Model, implies(which(j),price_evs(i+1) == p_ev(j + i)*price_f(j+i))];
        end
    end
end
power = sum(powers);
price_ev = sum(price_evs);





Reply all
Reply to author
Forward
0 new messages