yalmip Error

124 views
Skip to first unread message

nadiauir

unread,
Jun 12, 2013, 10:40:56 AM6/12/13
to yal...@googlegroups.com
Hi Mr Lofberg,

i wrote this code in yalmip, and i get an error that i can't understand, can you please help me: ??? Error using ==> compileinterfacedata at 1140
You have NaNs in your constraints!. Please fix model

Error in ==> solvesdp at 260
[interfacedata,recoverdata,solver,diagnostic,F,Fremoved,ForiginalQuadratics] =
compileinterfacedata(F,[],logdetStruct,h,options,0,solving_parametric);

Error in ==> coo at 93
sol= solvesdp(const,obj);

Here is the code:

clear all
clc;

N=10; 
H=24;
STa= [1 3 8 13 20; 2 4 17 18 3; 4 9 15 13 11; 2 4 9 14 15; 1 2 5 7 11; 5 7 12 14 15; 2 4 8 9 19; 2 9 10 13 14; 12 15 3 2 1; 6 7 9 14 15];
ETa= [5 6 12 17 24; 8 9 23 22 8; 10 14 20 18 17; 9 14 17 20 20; 7 8 11 13 16; 9 12 18 19 19; 9 10 12 13 24; 7 13 15 18 19; 16 20 9 7 6; 9 13 14 19 21]; 
nta= [3 2 3 3 3; 5 4 5 3 2; 5 3 4 3 4;6 5 6 5 3; 5 4 3 5 4; 2 3 4 4 3; 6 4 3 2 4; 3 2 4 3 4; 3 4 4 3 4; 2 5 4 3 4];
ct= [0.12,0.12,0.12,0.12,0.12,0.12,0.12,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.12,0.12,0.12,0.12,0.12,0.12]; 
gt= [0.024,0.024,0.024,0.024,0.024,0.024,0.024,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.024,0.024,0.024,0.024,0.024,0.024];% 
taubmin= ones(10,H);
taubmax= (10/3)*ones(10,H);
vbmin= ones(10,H); 
vbmax= (10/3)*ones(10,H);
ichb= 1;
xat= zeros(50,24); % a binary variable that decides wether the activity a starts at time t or not for all users
yt=sdpvar(10,H);% the amount of energy bought from the grid at time t;
zt= sdpvar(10,H);% the amount of energy sold to the grid at time t;
vbtc= sdpvar(10,H); % battery charge rate for each battery and each time slot
vbtd= sdpvar(10,H);% battery discharge rate for each battery and each time slot
wbtc=binvar(10,H);% binary variable equals 1 if battery is charging in time slot t and 0 otherwise
wbtd= binvar(10,H);%binary variable equals 1 if battery is discharging in time slot t and 0 otherwise
ebt= sdpvar(10,H);% energy in battery storage b at time t;
nu=0.95;% battery charge/discharge efficiency; 
pvt= ones(10,H);
m= zeros(10,1);

for i=1:10
pvt(i,:)= pvt(i,:).*[6.7874 7.5774 7.4313 3.9223 6.5548 1.7119 7.0605 0.3183 2.7692 0.4617 0.9713 8.2346 6.9483 3.1710 9.5022 0.3445 4.3874 3.8156 7.6552 7.9520 1.8687 4.8976 4.4559 6.4631];
end

patf= sdpvar(50,H);
lpaf=sdpvar(50,H);
cppin=10*ones(10,H);
gcppin= 100*ones(1,H);

sumpatf=ones(10,H);
bb=1;

for i=1:10
        sumpatf(i,:)= sum(patf(bb:5*i,:));
        bb=5*i+1;
            
end
compt=1;
k=1;
for i=1:10
    for j=compt:5*i  
    xat(j,STa(i,k):STa(i,k)+nta(i,k))=1; 
    k=k+1;
    end
    compt=5*i+1;
    j=compt;
    k=1;
end
        
Emax=(10/3)*ones(10,H); 
lowerbound=1;
upperbound=10;

%Objective function(we minimize the global peak power)
for i=1:10
m(i,1) = sum(ct.*yt(i,:)- gt.*zt(i,:));
end 
obj= sum(m);

% The constraints of the problem
ebt(:,1)=ichb;
for i=1:10
    for j=2:H
        ebt(i,j)=ebt(i,j-1)+ (1/4)*nu*vbtc(i,j)-(1/4)*(1/nu)*vbtd(i,j);
    end
end

%lpatftimesxat represents the product of lpaf and xat
%lpaftimesxat = sdpvar(50,24);
constraint = [xat*lowerbound <= patf <= xat*upperbound ,(1-xat)*lowerbound<=patf-lpaf<=(1-xat)*upperbound];

%v = [];
%val=1;
%for i=1:10
%for j = val:5*i
    %v = [v;sum(xat(j,STa(j):(ETa(j)-nta(j)+1)))];
%end
%val=5*i+1;
%end
cons=[taubmin.*wbtc <=vbtc <=taubmax.*wbtc;  vbmin.*wbtd<=vbtd<=vbmax.*wbtd];
const= [cons;constraint;wbtc+wbtd<=ones(10,H); yt<=cppin; sum(yt)<=gcppin; %;v==ones(50,1)
        yt+pvt+vbtd==zt+sumpatf+vbtc;yt>=0;zt>=0;ebt>=0;pvt>=0;lpaf>=0; ebt<=Emax; zt<=cppin   ];
    
% Solving the problem 
sol= solvesdp(const,obj);
yt= double(yt)
zt=double(zt)


Johan Löfberg

unread,
Jun 12, 2013, 4:03:50 PM6/12/13
to
You cannot do

m = DOUBLE
m
(index) = SDPVAR

since DOUBLE has precedence in MATLAB, and thus the code is equivalent to

m = DOUBLE
m
(index) = DOUBLE(SDPVAR)

You have to build your objective without first defining it as a double and then assigning values in it. In your case, it is trivial, since your code is strange to begin with

You can do
m = [];
for i=1:10
m= [m;sum(ct.*yt(i,:)- gt.*zt(i,:)];
end
obj = sum(m);

or
obj = 0;
for i=1:10
obj = obj + sum(ct.*yt(i,:)- gt.*zt(i,:);
end 

or best, vectorize it, but I leave that as an exercise to you.


Johan Löfberg

unread,
Jun 13, 2013, 4:05:15 AM6/13/13
to yal...@googlegroups.com
Since this is a common problem, I've added some additional information
http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Extra.NANInModel

nadiauir

unread,
Jun 13, 2013, 10:23:56 AM6/13/13
to yal...@googlegroups.com
thanks a lot for your help 
Reply all
Reply to author
Forward
0 new messages