Hello Johan
How to improve the efficiency of the following parts of the code?
I mean, how to vectorize the code and get rid of some of the for loops?
Please find below part of my code (1 loop of the objectve function and 2 sets of constraints).
pru = sdpvar(ndg,g,w);
prd = sdpvar(ndg,g,w);
PDRU = sdpvar(ndr,1);
PDRD = sdpvar(ndr,1);
%Lambda_g is an input matrix
%Part of the Objective
Objective_pr = 0;
for i=1:ndg
for j=1:g
for k=1:w
Objective_pr = Objective_pr + (pru(i,j,k) - prd(i,j,k))*Lambda_g(i,j);
end
end
end
%Constraint set 1&2
for i=1:ndg
for j=1:g
for k=1:w
Constraints = [Constraints, 0 <= pru(i,j,k) <= 3];
Constraints = [Constraints, 0 <= prd(i,j,k) <= 3];
end
end
end
%Constraint set 3&4
for i=1:ndr
for j=1:w
Constraints = [Constraints, sum(pdru(i,:,j)) <= PDRU(i,1)];
Constraints = [Constraints, sum(pdrd(i,:,j)) <= PDRD(i,1)];
end
end