Some Questions About Solvers

75 views
Skip to first unread message

Wrysunny

unread,
Aug 1, 2020, 12:55:08 PM8/1/20
to YALMIP
1.I'm trying to solve MINLP problem using IPOPT and SCIP. Neither of them got reasults. When I applied SCIP, the value of obj is 0. And it reminded that "Original variable <nlobj> not released when freeing SCIP. Consider releasing". I don't know the meaning of "<nlobj>", and how to release it.
2. When I applied IPOPT, I got "IPOPT is not applicable".
3. Then I used BOMIN, but it showed an error that "Error using Bonmin Matlab interface:You have specified a nonexistent BONMIN/IPOPT" option ("pardiso_redo_symbolic_fact_only_if_inertia_wrong").
Any help would be appreciated. The next is my code:
clc
clear

t=1440;

load PP_oneday_neg_row2
load PP_oneday_pos_row2
load solar
c = sdpvar(1,t); 
% for i=1:1440
%     c(i)=1.252;
% end
for i=1:360
    c(i)=0.370;
end
for i=361:480
    c(i)=0.782;
end
for i=481:660
    c(i)=1.252;
end
for i=661:1080
    c(i)=0.782;
end
for i=1081:1260
    c(i)=1.252;
end
for i=1261:1320
    c(i)=0.782;
end    
for i=1321:1440
    c(i)=0.370;
end

Pgrid= sdpvar(1,t);
Pfed= sdpvar(1,t);
Pdemand= sdpvar(1,96);
Pdem=sdpvar(1,1);

Pbatdis= sdpvar(1,t);
Pucdis= sdpvar(1,t);
Pbrake=-PP_oneday_neg1;

Pbatch= sdpvar(1,t);
Pucch= sdpvar(1,t);
Pload=PP_oneday_pos1;

%储能约束涉及的参数
Ebats= sdpvar(1,t);
Eucs= sdpvar(1,t);

Ebatact= sdpvar(1,t);
D= sdpvar(1,t-1);
Lbat= sdpvar(1,t-1);

ubatch=binvar(1,t);
uucch=binvar(1,t);
ubatdis=binvar(1,t);
uucdis=binvar(1,t);

nbatdis=0.8;
nbatch=0.8;
nucdis=0.95;
nucch=0.95;

At=1/60;

SOCbatmin=0.2;
SOCbatmax=0.8;
SOCbat0=0.5;
SOCucmin=0.05;
SOCucmax=0.95;
SOCuc0=0.5;

Spv=3.5;
npv=0.12;
Apv=10000;
Ppv=sdpvar(1,t);
Ppvmax=1e-3*Apv*npv*solar(172,:);

Pgridlimit= max(Pload);
Pfedlimit= max(Pbrake);
ugrid=binvar(1,t);

Ebatr=5;
Eucr=0.33;
Pbatr=3;
Pucr=10;

%% 将所有的约束条件集中 尽量写到一两个循环里,同时 能量矩阵化处理的约束用矩阵处理,能大大加快运行时间。
C=[];%约束
C=[C,Pgrid+Pbatdis+Ppv+Pucdis+Pbrake==Pbatch+Pucch+Pfed+Pload,Ebatact(1)==Ebatr...
    Ebats(1)==SOCbat0*Ebatact(1),Eucs(1)==SOCuc0*Eucr, Ebats(1440)==SOCbat0*Ebatact(1440),Eucs(1440)==SOCuc0*Eucr,...
    Pbatdis>=0,Pucdis>=0,Pbatch>=0,Pucch>=0,Pgrid>=0,Pfed>=0,...
    Pbatdis<=ubatdis*Pbatr,Pbatch<=ubatch*Pbatr,Pucdis<=uucdis*Pucr,Pucch<=uucch*Pucr,...
    Pfed<=bsxfun(@times,(1-ugrid),Pfedlimit),Pgrid<=ugrid*Pgridlimit,...
    ubatdis+ubatch<=1,uucdis+uucch<=1,...%%这条约束约束充放电不能同时进行
    SOCbatmin*Ebatact<=Ebats<=SOCbatmax*Ebatact,SOCucmin*Eucr<=Eucs<=SOCucmax*Eucr,Ppv<=Ppvmax,Ppv<=Spv,Ppv>=0,...
    bsxfun(@minus,Ebats(2:t),Ebats(1:t-1))+bsxfun(@minus,(1/nbatdis)*Pbatdis(1:t-1)*At,nbatch*Pbatch(1:t-1)*At)==0,...
    bsxfun(@minus,Eucs(2:t),Eucs(1:t-1))+bsxfun(@minus,(1/nucdis)*Pucdis(1:t-1)*At,nucch*Pucch(1:t-1)*At)==0
    ];
%     bsxfun(@plus,bsxfun(@minus,Ebatact(2:t),Ebatact(1:1439)),bsxfun(@times,Ebatr,1./Lbat(1:1439)))==0,...
%     bsxfun(@minus,Lbat,(bsxfun(@times,58.7.*D.^(-1.98),exp((-0.016).*D))))==0,...%Lbat(i)=24090*exp(-9.346*D(i))+6085*exp(-1.319*D(i)); 
%     bsxfun(@minus,Ebatact(2:1440),Ebatact(1:1439))+bsxfun(@times,Ebatr,1./Lbat(1:1439))==0    
for i=1:1439
    C=[C,D(i)==(Pbatdis(i)+Pbatch(i))*At/Ebatact(i),...
        Lbat(i)==58.7*D(i)^(-1.98)*exp((-0.016)*D(i)),...%Lbat(i)=24090*exp(-9.346*D(i))+6085*exp(-1.319*D(i)); 
        Ebatact(i+1)==Ebatact(i)-Ebatr/Lbat(i)];
       
%     if Ebatact(i+1)<=Erep
%         true=0;
%         Ebatact(i+1)=Ebatr;
%     end
    
end

% % 
%     C=[C,D==(Pbatdis+Pbatch).*At./Ebatact,...
%         Lbat==58.7.*D.^(-1.98).*exp((-0.016).*D),...%Lbat(i)=24090*exp(-9.346*D(i))+6085*exp(-1.319*D(i)); 
%         Ebatact(2:1440)==Ebatact(1:1439)-Ebatr./Lbat(1:1439)];
%         
%        
%     if Ebatact(i+1)<=Erep
%         true=0;
%         Ebatact(i+1)=Ebatr;
%     end

for i=1:96 
   C=[C, Pdemand(i)==mean(Pgrid((i-1)*15+1:i*15)),Pdem>=Pdemand(i)];
end

%% electricity
ECC=bsxfun(@times,c,Pgrid*1000*At);
ECC=sum(ECC);
PC=bsxfun(@times,c,Pfed*1000*At);
PC=sum(PC);
DC=Pdem*1.4*1000;
obj=ECC+DC+PC;

ops = sdpsettings('verbose',1,'debug',1,'solver','scip''savesolveroutput',1,'savesolverinput',1);
%ops.cplex.exportmodel='abc.lp';
sol=solvesdp(C, obj,ops);

y=value(obj);
E_bat=value(Ebats);
Pbatch1=value(Pbatch);
Pbatdis1=value(Pbatdis);
T_bat_hr=sum(value(ubatch+ubatdis))/60; %operation hours
T_uc_hr=sum(value(uucch+uucdis))/60;

Johan Löfberg

unread,
Aug 1, 2020, 2:53:54 PM8/1/20
to YALMIP
ipopt is not applicable (does not support integers) and bonmin is for convex problems (which yours isn't)

beyond that impossible to say anything as your code does not run (missing data)

Wrysunny

unread,
Aug 1, 2020, 10:36:28 PM8/1/20
to YALMIP
Thank you for reply. 
It was my fault. I forgot to upload the data. Here is the missing data.
PP_oneday_neg_row2.mat
PP_oneday_pos_row2.mat
solar.mat

Johan Löfberg

unread,
Aug 2, 2020, 9:25:41 AM8/2/20
to YALMIP
Why are you doing all this messy bsxfun stuff. You can use +-*.* etc just like normal

Having said that, there is no solver today that is capable of solving this problem straight off. You will have to do a lot of clever tricks to get anywhere, or develop a specialized solver.

And as always, before you play around with t=1440, see if you can get any solver to get anywhere for, say, t=10. Then try 20,...

To begin with, try with linear approximations, and then perhaps pwa approximations/sos2 approximations 

and never multiply a binary with a continuous to model on/off (I think you do that, not sure though)


and there is no official command in YALMIP called solvesdp

Wrysunny

unread,
Aug 2, 2020, 10:39:13 AM8/2/20
to YALMIP
Thanks for your suggestion. I'll try with linear approximations. 
There are no continuous variables in my code.
But I cannot understand the meaning of "never multiply a binary with a continuous to model on/off". 
Why can't I multiply a binary with a continuous to model on/off? 

Johan Löfberg

unread,
Aug 2, 2020, 10:48:28 AM8/2/20
to YALMIP
You have loads of continuous variables (Pgrid, Pfed,...)

You don't multiply those as you get nonlinear terms unnecessarily and thus very hard nonconvexity.  x*y where x is binary can be written using linear logic, as described in the unit commitment example and in depth here https://yalmip.github.io/tutorial/logicprogramming/

Wrysunny

unread,
Aug 2, 2020, 10:56:33 AM8/2/20
to YALMIP
Thank you for your patient reply. I am really a noob. I am trying to understand the examples you gave me.
Reply all
Reply to author
Forward
0 new messages