• 啭角爱
    了解作者
  • matlab
    开发工具
  • 1KB
    文件大小
  • zip
    文件格式
  • 1
    收藏次数
  • 10 积分
    下载积分
  • 32
    下载次数
  • 2019-03-27 09:03
    上传日期
cplex实例教程,简单易懂,对求解多能源最优帮助最大
micro_cplex2.zip
  • micro_cplex2.m
    3.1KB
内容介绍
clc; clear all; format short; yalmip; Cplex; %变量定义 Ppv=sdpvar(1,24,'full')%光伏出力 Pbat=sdpvar(1,24,'full');%蓄电池出力 Pnet=sdpvar(1,24,'full');%与电网交换功率 Pbuy=sdpvar(1,24,'full');%从电网购电电量 Psell=sdpvar(1,24,'full');%向电网售电电量 Temp_net=binvar(1,24,'full'); % 购|售电标志 0-1型 Temp_cha=binvar(1,24,'full'); %充电标志 Temp_dis=binvar(1,24,'full'); %放电标志 Temp_static=binvar(1,24,'full'); %电池静置标志 Pcha=sdpvar(1,24); Pdis=sdpvar(1,24); Temp_ev=binvar(1,24,'full');%电动汽车 Pev=3.3*Temp_ev; Constraints = []; %常量定义 P0=load('P0.txt'); Load=load('Load2.txt'); %光伏预测出力 Ppv=load('Ppv2.txt'); %分时电价 C_buy=load('C_buy2.txt'); C_sell=load('C_sell2.txt'); C_sub=load('C_sub2.txt');%光电补贴 for k = 1:24 Constraints = [Constraints, -7<=Pnet(1,k)<=7,0<=Pbuy(1,k)<=7, -7<=Psell(1,k)<=0]; %主网功率交换约束 Constraints = [Constraints, Pnet(1,k)+Ppv(1,k)==Load(1,k)+Pbat(1,k)+Pev(1,k)]; %功率平衡约束 Constraints = [Constraints, implies(Temp_net(1,k),[Pnet(1,k)>=0,Pbuy(1,k)==Pnet(1,k),Psell(1,k)==0])]; %购电情况约束 Constraints = [Constraints, implies(1-Temp_net(1,k),[Pnet(1,k)<=0,Psell(1,k)==Pnet(1,k),Pbuy(1,k)==0])]; %售电情况约束 %蓄电池约束 Constraints = [Constraints, -3<=Pbat(1,k)<=3,0<=Pcha(1,k)<=3,-3<=Pdis(1,k)<=0];%电池充放电约束 Constraints = [Constraints, implies(Temp_cha(1,k),[Pbat(1,k)>=0,Pcha(1,k)==Pbat(1,k),Pdis(1,k)==0])];%充电情况约束 Constraints = [Constraints, implies(Temp_dis(1,k),[Pbat(1,k)<=0,Pdis(1,k)==Pbat(1,k),Pcha(1,k)==0])];%放电情况约束 Constraints = [Constraints, implies(Temp_static(1,k),[Pbat(1,k)==0,Pdis(1,k)==0,Pcha(1,k)==0])];%静置情况约束 Constraints = [Constraints,Temp_cha(1,k)+Temp_dis(1,k)+Temp_static(1,k)==1]; Constraints= [Constraints,-1<=sum(Pdis(1,1:k)+Pcha(1,1:k))<=5.5];%SOC约束,电池容量10kwh,初始S0C为0.4,0.3<=SOC<=0.95 Constraints=[Constraints,sum(Pdis+Pcha)==0] ;%ST=S0,始末SOC相等约束 %电动汽车约束 Constraints = [Constraints,sum(Temp_ev)==6]; end %目标函数为用户总支出费用 F=0; for k = 1:24 F = F+C_buy(:,k)*Pbuy(:,k)+C_sell(:,k)*Psell(1,k)+0.15*(abs(Pdis(1,k))+Pcha(1,k))-C_sub(:,k)*Ppv(:,k); end %参数指定程序用cplex求解器 ops=sdpsettings('solver', 'cplex'); optimize(Constraints,F,ops) %输出参数 F=value(F)%费用 Pcha=value(Pcha)%蓄电池充电 Pdis=value(Pdis)%蓄电池放电 %作柱状图 x=1:24; PP_neg=[Psell;-Pcha;P0;-Pev]; PP=[Pbuy;-Pdis;Ppv]; figure bar(PP_neg','stack'); h=legend('交换功率','蓄电池','光伏出力','电动汽车','Location','NorthWest'); set(h,'Orientation','horizon') hold on bar(PP','stack'); plot(x,value(Load),'r','linewidth',2); set(gca,'xtick',(0:2:24)) xlabel('时段');ylabel('功率/kW'); hold off %作蓄电池SOC图 for k=1:24 s(k)=value(sum(Pdis(1,1:k)+Pcha(1,1:k)))/10+0.4; soc(k+1)=s(k); end soc(1)=0.4; xx=0:24; figure plot(xx,soc,'r'); xlabel('时段');ylabel('SOC值'); title('蓄电池SOC状态'); %%%将符号变量转化为数值变量 %P=[Pnet;Ppv;Pbat;Load;Pev]; %p=double(P); %%输出到excel %xlswrite('C:\Users\Administrator\Desktop\出力',p',1,'A1') %G=[C_buy;C_sell;C_sub]; %g=double(G); %xlswrite('C:\Users\Administrator\Desktop\出力',g,4,'A1')
评论
  • 张磊磊 2020-05-27 19:10:26
    楼主,请问仿真中使用的数据,几个txt文件能再分享一下吗!发我邮箱也可以,多谢了2389142903@qq.com
相关推荐