Is it a normal yalmiptime?

98 views
Skip to first unread message

reza mehrabadi

unread,
Dec 20, 2018, 2:34:59 PM12/20/18
to YALMIP
Hi :). A problem constraint size is [13200,1] and : yalmiptime=25.7s and solver(CPLEX12.8) time=0.2s
Is the yalmiptime OK or slow?  Any suggestions that speed up the constraints build up (no preallocation is used)?
Thanks

Johan Löfberg

unread,
Dec 20, 2018, 2:38:17 PM12/20/18
to YALMIP
It's obviously terribly slow. Impossible to answer such a generic question, it's like asking "my car does not work what should I fix". Lack of vectorization would be the only generic answer

reza mehrabadi

unread,
Dec 20, 2018, 2:56:58 PM12/20/18
to YALMIP
Thanks for reply. I think some more examples comparing a good and bad constraints definitionis required at:  https://yalmip.github.io/faq/itisslow/
Well actually most of the constraints are built up in "for" loops. How much is time difference between these two representations?:
constr=[constr,-pi<=delta(2:B,1:T,1:H)<=pi];

and this:
for t=1:T
 for h=1:H
    for i=1:B
     if (i>1) constr=[constr,-pi<=delta(i,t,h)<=pi]; end
  end
 end
end



Johan Löfberg

unread,
Dec 20, 2018, 3:11:51 PM12/20/18
to YALMIP
such unvectorized code will run very slowly

B=10;
T=20;
H=30;
delta=sdpvar(B,T,H);

tic
constr=-pi<=delta(2:B,1:T,1:H)<=pi;
toc

constr=[];
tic
for t=1:T
    for h=1:H
        for i=1:B
            if (i>1) constr=[constr,-pi<=delta(i,t,h)<=pi]; end
        end
    end
end
toc



reza mehrabadi

unread,
Dec 20, 2018, 3:20:34 PM12/20/18
to YALMIP
much appreciated !

reza mehrabadi

unread,
Dec 22, 2018, 11:55:31 AM12/22/18
to YALMIP
Hi !. By vectorizing most of the code, the time problem reduced significantly. But still this part of the codes consumes about 13 seconds:
for b=1:size(zz,1)
constr=[constr,pij(zz(b,1),zz(b,2),:,:)==0];
end

It's probably an easy trick in Matlab but i can't figure it out. the matrix zz (with M x 2 size) elements should be used as first and second indices of pij.
somthing like
pij(zz,:,:)
or 
pij(zz(:,1),zz(:,2),:,:)
results in error and unwanted sizes respectively.

Johan Löfberg

unread,
Dec 22, 2018, 12:04:21 PM12/22/18
to YALMIP
fastest is likely to run a for-loop first to generate the all linear indicies using sub2ind, and then use that vector pij(index)

reza mehrabadi

unread,
Dec 22, 2018, 1:13:35 PM12/22/18
to YALMIP
Perfect ! about 13 seconds reduced.

pp=zeros(B,B,T,H);k=1;
for z=1:size(zz,1)
 for t=1:T
  for h=1:H  
     index(k)=sub2ind(size(pp),zz(z,1),zz(z,2),t,h);k=k+1;
  end 
 end
end


Reply all
Reply to author
Forward
0 new messages