✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
随着世界能源问题和环境问题日益突出,风电,光伏等可再生能源得到迅速发展,电动汽车大规模接入电网,传统配电网已经不能满足新形势下的电力系统发展要求,被动式配电网迫切需要朝着主动式配电网进行转变,以实现电源侧和用电侧之间的双向连接,保证双方都能实时,有效地参与到电力系统的优化调度中.在此背景下,主动配电网应运而生,而与之相应的主动配电网优化调度方法成为研究和发展主动配电网的重要内容之一.
⛄ 部分代码
function [branch1]=zuixiaolufa(branch)
[row,colum]= size(branch);
branch(:,9:23)=0;
m=1;
n=2;
k=1;%用来记录主节点个数
flag=0;
%**********确定主网络*******
branch(row,10)=1;%branch第十列表征主网络节点
zhuwangluojiedian=branch(row,1);%主网络节点
zhuwangluo(k)=branch(row,1);
zhesuanguzhanglv=0;
zhesuanxiufushijian=0;
while zhuwangluojiedian~=branch(1,1)
for i=1:row
if branch(i,2)==zhuwangluojiedian
branch(i,10)=1;
zhuwangluojiedian=branch(i,1);
k=k+1;
zhuwangluo(k)=branch(i,1);
zhesuanguzhanglv=zhesuanguzhanglv+branch(i,4);
zhesuanxiufushijian=zhesuanxiufushijian+branch(i,4)*branch(i,5);
branch(i,22)=zhesuanguzhanglv;
branch(i,23)=zhesuanxiufushijian;
branch(i,23)=zhesuanxiufushijian/branch(i,22);
if branch(i,3)==4
zhesuanguzhanglv=0;
zhesuanxiufushijian=branch(i,7);
end
break
end
end
end
%*******确定孤岛支路*******
m=0;
for i=1:row
if branch(i,9)==0&&branch(i,3)~=7%*****后续改动
for j=1:row
if j~=i
if branch(j,1)==branch(i,1)&&branch(j,3)~=7%*****后续改动
branch(i,9)=branch(i,9)+1;%第九列存放节点的支路数;
m=m+1;
duozhilu(m)=j;
end
end
end
while m~=0
branch(duozhilu(m),9)=branch(i,9);
m=m-1;
end
end
end
branch=gudaojisian(branch);
% branch=gudaojisuanqian(branch);
% branch=gudaojisuanhou(branch);
%********确定最小路*****
% m=1;
% v=1;
% for i=1:row
% if branch(i,3)==7
% % zuixiaozhilu(m,1)=branch(i,1);%zuixiaozhilu中存放所有最小支路
% zuixiaozhilu(m,1)=i;%zuixiaozhilu中存放最小支路的行数
% chuanlianjiedian=branch(i,1);
% while chuanlianjiedian~=branch(1,1)
% for j=1:row
% if branch(j,2)==chuanlianjiedian
% % zuixiaozhilu(m,n)=branch(j,1);
% zuixiaozhilu(m,n)=j;
% if branch(j,10)==2&&branch(j,19)==0&&branch(j,3)==3
% branch(i,19)=branch(i,19)+branch(j,14);
% branch(i,20)=branch(i,20)+branch(j,14)*branch(j,15);
% end
% if branch(j,10)==1&&branch(j,19)~=0
% branch(i,19)=branch(j,4)+branch(i,19)*branch(j,4)*(branch(i,20)+branch(j,5));
% branch(i,20)=branch(j,5)*branch(j,4)+branch(i,20)*branch(j,2)/(branch(i,20)+branch(j,5));
% end
% if branch(j,10)==1&&branch(j,19)==0
% branch(i,19)=branch(i,19)+branch(j,4);
% branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
% end
% n=n+1;
% chuanlianjiedian=branch(j,1);
% break;
% end
% end
% end
% m=m+1;
% n=2;
% end
% end
% l=zuixiaozhilu
%******非最小路上的参数折算*********
%*******首先对主网络上的节点进行折算*****************************************************
%*
m=1;
for i=1:row
if branch(i,3)==7
jiedian=branch(i,1);
hangshu=i;
branch(hangshu,11)=branch(hangshu,4);
branch(hangshu,12)=branch(hangshu,5)*branch(hangshu,4);
while branch(hangshu,9)==0
for j=1:row
if branch(j,2)==jiedian&&branch(j,9)==0
branch(j,11)=branch(j,4)+branch(hangshu,11);%branch的11列12列用来表示非最小路的指标归算——初次归算
branch(j,12)=branch(j,4)*branch(j,5)+branch(hangshu,12);
hangshu=j;
jiedian=branch(j,1);
break
end
if branch(j,2)==jiedian&&branch(j,9)~=0
branch(j,13)=branch(j,13)+1; %用第十三列表示已经进行过归算的标记
branch(j,11)=branch(j,4)+branch(hangshu,11);%branch的11列12列用来表示非最小路的指标归算
branch(j,12)=branch(j,4)*branch(j,5)+branch(hangshu,12);
hangshu=j;
break
end
end
end
branch(j,12)=branch(j,12)/branch(j,11);
end
end
%***************************
for i=1:row
% branch(i,17)=1;%17列表示已归算支路数
if branch(i,13)~=0&&branch(i,16)==0%改动
branch(i,14)=branch(i,11);
branch(i,15)=branch(i,12);
for j=1:row
if branch(j,1)==branch(i,1)&&branch(j,13)~=0&&i~=j
branch(i,14)=branch(i,14)+branch(j,11);
branch(i,15)=branch(i,15)+branch(j,7)*branch(j,11);
% branch(i,14)=branch(i,14)*branch(j,11)*(branch(i,15)+branch(j,12));%用branch的第14,15列表征二次归算
% branch(i,15)=branch(i,15)*branch(j,12)/(branch(i,15)+branch(j,12));
branch(i,16)=2;%用第16列表示二次归算行存放值
branch(j,16)=1;%表示已经进行了二次归算
branch(i,17)=branch(i,17)+1;
end
end
end
if branch(i,17)==branch(i,9)&&branch(i,16)~=0
branch(i,18)=1;%18列表示支路归算完成
end
for t=1:k%k中存放主节点个数
if branch(i,1)==zhuwangluo(t)
if branch(i,10)~=1
branch(i,10)=2;
end
if branch(i,17)==(branch(i,9)-1)&&branch(i,16)~=0
branch(i,18)=1;
break
end
end
end
end
%*******************************
for i=1:row
if branch(i,18)==1&&branch(i,10)~=2%表示已经进行过二次归算且二次归算完毕
sanjiedian=branch(i,1);
panduan=branch(i,10);
while panduan~=2&&panduan~=1%没有到达主节点
for j=1:row
if branch(j,2)==sanjiedian
branch(j,14)=branch(j,4);
branch(j,15)=branch(j,5)*branch(j,4);
branch(j,14)=branch(j,14)+branch(i,14);
branch(j,15)=branch(i,14)*branch(i,15)+branch(j,15);
sanjiedian=branch(j,1);
panduan=branch(j,10);
zhiliudian=j;
if branch(zhiliudian,9)~=0
for t=1:row
if (branch(t,1)==branch(zhiliudian,1)&&t~=zhiliudian&&branch(t,13)==1&&branch(t,16)==0)||(branch(t,1)==branch(zhiliudian,1)&&t~=zhiliudian&&branch(t,16)==2)
if branch(t,14)~=0&&branch(t,3)~=4&&branch(t,3)~=3
% branch(t,14)=branch(t,14)*branch(zhiliudian,14)*(branch(t,15)+branch(zhiliudian,15));%用branch的第14,15列表征二次归算
% branch(t,15)=branch(t,15)*branch(zhiliudian,15)/(branch(t,15)+branch(zhiliudian,15));
branch(t,14)=branch(t,14)+branch(zhiliudian,14);
branch(t,15)=branch(t,15)+branch(zhiliudian,7)*branch(zhiliudian,14);
end
if branch(t,14)==0&&branch(t,3)~=4&&branch(t,3)~=3
% branch(t,14)=branch(t,11)*branch(zhiliudian,14)*(branch(t,12)+branch(zhiliudian,15));%用branch的第14,15列表征二次归算
% branch(t,15)=branch(t,12)*branch(zhiliudian,15)/(branch(t,12)+branch(zhiliudian,15));
branch(t,14)=branch(t,11)+bracn(zhiliudian,14);
branch(t,15)=branch(t,12)+branch(zhiliudian,7)*branch(zhiliudian,14);
end
branch(t,16)=2;
branch(t,17)=branch(t,17)+1;
zhiliudian=t;
if branch(t,17)==branch(t,9)
branch(t,18)=1;
% bianzhijiedian2=branch(t,18);
sanjiedian=branch(t,1);
panduan=branch(t,10);
break
end
if branch(t,17)~=branch(t,9)
break
end
end
if branch(t,1)==branch(zhiliudian,1)&&t~=zhiliudian&&branch(t,13)==0&&branch(t,10)~=1
branch(t,14)=branch(zhiliudian,14);
branch(t,15)=branch(zhiliudian,15);
branch(t,16)=2;
branch(t,17)=branch(t,17)+1;
panduan=2;
break
end
end
end
branch(j,15)=branch(j,15)/branch(j,14);
break
end
end
end
end
end
%************************
for i=1:row
if branch(i,10)==2&&branch(i,21)==0%&&branch(i,16)==2
branch(i,19)=branch(i,14);
branch(i,20)=branch(i,15);
if branch(i,9)==1
branch(i,21)=2;
end
if branch(i,9)~=1&&branch(i,16)==2
for j=1:row
if branch(i,18)==1
branch(i,21)=2;
break
end
if branch(j,1)==branch(i,1)&&branch(j,10)==2&&i~=j&&branch(j,16)==0
if branch(j,14)~=0&&branch(j,3)~=4&&branch(j,3)~=3
% branch(i,19)=branch(i,19)*branch(j,14)*(branch(i,20)+branch(j,15));
% branch(i,20)=branch(i,20)*branch(j,15)/(branch(i,20)+branch(j,15));
branch(i,19)=branch(i,19)+branch(j,14);
branch(i,20)=branch(i,20)+branch(j,7)*branch(j,14);
branch(j,21)=1;
branch(i,21)=2;
end
if branch(j,14)==0&&branch(j,3)~=4&&branch(j,3)~=3
% branch(i,19)=branch(i,19)*branch(j,11)*(branch(i,20)+branch(j,12));
% branch(i,20)=branch(i,20)*branch(j,12)/(branch(i,20)+branch(j,12));
branch(i,19)=branch(i,19)+branch(j,11);
branch(i,20)=branch(i,20)+branch(j,7)*branch(j,11);
branch(j,21)=1;
branch(i,21)=2;
end
end
end
branch(i,20)=branch(i,20)/branch(i,19);
end
end
end
%**************************************************************************
%********最小路参数求解****************************************************
for i=1:row
if branch(i,21)==2
for j=1:row
if branch(j,1)==branch(i,1)&&branch(j,10)==1
branch(j,19)=branch(i,19);
branch(j,20)=branch(i,20);
if branch(i,19)==0%gaidong
branch(j,19)=branch(i,11);
branch(j,20)=branch(i,12);
end
break
end
end
end
end
for i=1:row
if branch(i,10)==1&&branch(i,19)~=0&&branch(i,3)~=4&&branch(i,3)~=3
% branch(i,19)=branch(i,19)*branch(i,22)*(branch(i,20)+branch(i,23));
% branch(i,20)=branch(i,20)*branch(i,23)/(branch(i,20)+branch(i,23));
branch(i,19)=branch(i,19)+0.8*branch(i,22);
branch(i,20)=branch(i,20)+branch(i,7)*branch(i,22);
end
end
% m=1;
% for i=1:v
% shenchajiedian=zuixiaozhilu(i,1);
% while shenchajiedian~=0
% if branch(shenchajiedian,10)==1||branch(shenchajiedian,1)==branch(1,1)
% branch(zuixiaozhilu(i,1),19)=branch(zuixiaozhilu(i,1),19)+branch(zuixiaozhilu(i,m),19)+branch(zuixiaozhilu(i,m),4);
% branch(zuixiaozhilu(i,1),20)=branch(zuixiaozhilu(i,1),20)+branch(zuixiaozhilu(i,m),19)*branch(zuixiaozhilu(i,m),20)+branch(zuixiaozhilu(i,m),4)*branch(zuixiaozhilu(i,m),5);
% end
% m=m+1;
% if m<=(c+1)
% shenchajiedian=zuixiaozhilu(i,m);
% else
% break
% end
% end
% end
%*********************************************************
m=1;
for i=1:row
flag=0;
if branch(i,3)==7%&&branch(i,8)==0
% zuixiaozhilu(m,1)=branch(i,1);%zuixiaozhilu中存放所有最小支路
zuixiaozhilu(m,1)=i;%zuixiaozhilu中存放最小支路的行数
chuanlianjiedian=branch(i,1);
branch(i,19)=branch(i,4);
branch(i,20)=branch(i,4)*branch(i,5);
while chuanlianjiedian~=branch(1,1)
for j=1:row
if branch(j,2)==chuanlianjiedian
% zuixiaozhilu(m,n)=branch(j,1);
zuixiaozhilu(m,n)=j;
if flag==1
if branch(j,9)==0&&branch(j,10)==0
branch(i,19)=branch(i,19)+branch(j,4);
% branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
end
if branch(j,9)~=0&&branch(j,10)==0
branch(i,19)=branch(i,19)+branch(j,4);
% branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
for v=1:row
if branch(v,1)==branch(j,1)&&v~=j&&branch(v,3)~=4
if branch(v,13)~=0
branch(i,19)=branch(i,19)+0.8*branch(v,11);
branch(i,20)=branch(i,20)+branch(v,7)*branch(v,11);
end
if branch(v,13)==0
branch(i,19)=branch(i,19)+0.8*branch(v,14);
branch(i,20)=branch(i,20)+branch(v,7)*branch(v,14);
end
end
end
end
if branch(j,10)==2%&&branch(j,19)==0%&&branch(j,3)==3
branch(i,19)=branch(i,19)+branch(j,4);
% branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
for t=1:row
if branch(t,1)==branch(j,1)&&branch(t,3)~=4&&t~=j%&&branch(t,3)~=3
branch(i,19)=branch(i,19)+0.8*branch(t,14);
% branch(i,20)=branch(i,20)+branch(t,7)*branch(t,4);
end
end
end
if branch(j,10)==1&&branch(j,3)~=4
%branch(i,19)=branch(j,4)+branch(i,19)*branch(j,4)*(branch(i,20)+branch(j,5));
% branch(i,20)=branch(j,5)*branch(j,4)+branch(i,20)*branch
% (j,2)/(branch(i,20)+branch(j,5));
% if flag==0
branch(i,19)=branch(i,19)+branch(j,4);%+branch(j,19);
% branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);%+0.02*branch(j,20);
if branch(j,3)~=4&&branch(j,3)~=3%&&branch(j,3)~=5
branch(i,19)=branch(i,19)+0.2*branch(j,19);
% branch(i,20)=branch(i,20)+branch(j,7)*branch(j,4);
end
end
n=n+1;
chuanlianjiedian=branch(j,1);
break;
end
if flag==0
if branch(j,9)==0&&branch(j,10)==0
branch(i,19)=branch(i,19)+branch(j,4);
branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
end
if branch(j,9)~=0&&branch(j,10)==0
branch(i,19)=branch(i,19)+branch(j,4);
branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
for v=1:row
if branch(v,1)==branch(j,1)&&v~=j&&branch(v,3)~=4
if branch(v,13)~=0
branch(i,19)=branch(i,19)+0.3*branch(v,11);
branch(i,20)=branch(i,20)+0.7*branch(v,7)*branch(v,11);
end
if branch(v,13)==0
branch(i,19)=branch(i,19)+0.3*branch(v,14);
branch(i,20)=branch(i,20)+0.7*branch(v,7)*branch(v,14);
end
end
end
end
if branch(j,10)==2%&&branch(j,19)==0%&&branch(j,3)==3
branch(i,19)=branch(i,19)+branch(j,4);
branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
for t=1:row
if branch(t,1)==branch(j,1)&&branch(t,3)~=4&&t~=j&&branch(t,3)~=3
branch(i,19)=branch(i,19)+0.3*branch(t,14);
branch(i,20)=branch(i,20)+0.7*branch(t,7)*branch(t,14);
end
end
if branch(i,8)==1
% chuanlianjiedian=branch(1,1);
flag=1;
branch(i,20)=branch(i,20)+0.7*branch(j,7)*branch(j,19);
end
end
if branch(j,10)==1&&branch(j,3)~=4
%branch(i,19)=branch(j,4)+branch(i,19)*branch(j,4)*(branch(i,20)+branch(j,5));
% branch(i,20)=branch(j,5)*branch(j,4)+branch(i,20)*branch
% (j,2)/(branch(i,20)+branch(j,5));
% if flag==0
branch(i,19)=branch(i,19)+branch(j,4);%+branch(j,19);
branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);%+0.02*branch(j,20);
if branch(j,3)~=4&&branch(j,3)~=3%&&branch(j,3)~=5
branch(i,19)=branch(i,19)+0.3*branch(j,19);
branch(i,20)=branch(i,20)+0.7*branch(j,7)*branch(j,19);
end
% end
% if flag==1
% branch(i,19)=branch(i,19)+branch(j,4);
% if branch(j,3)~=4&&branch(j,3)~=3
% branch(i,19)=branch(i,19)+0.8*branch(j,19);
% end
% end
end
% if branch(j,10)==1&&branch(j,19)==0
% branch(i,19)=branch(i,19)+branch(j,4);
% branch(i,20)=branch(i,20)+branch(j,4)*branch(j,5);
% end
n=n+1;
chuanlianjiedian=branch(j,1);
break;
end
end
end
end
m=m+1;
n=2;
branch(i,20)=branch(i,20)/branch(i,19);
% if branch(i,3)==7&&branch(i,8)==1
% % branch(i,19)=0.0163;
% % branch(i,20)=3*0.0163;
% jiedian=branch(i,1);
% hang=i;
% while branch(hang,10)~=2
% for j=1:row
% if branch(j,2)==jiedian
% jiedian=branch(j,1);
% hang=j;
% % if branch(j,9)~=0
% % branch(i,19)=branch(i,19)+branch(j,11);
% % branch(i,20)=branch(i,20)+branch(j,12);
% % for t=1:row
% % if branch(t,1)==branch(j,1)&&t~=j
% % if branch(t,14)~=0
% % branch(i,19)=branch(i,19)+branch(t,14);
% % branch(i,20)=branch(i,20)+0.02*branch(t,15);
% % end
% % if branch(t,14)==0
% % branch(i,19)=branch(i,19)+branch(t,11);
% % branch(i,20)=branch(i,20)+0.02*branch(t,12);
% % end
% % end
% % end
% end
% break
% end
% end
% end
% branch(i,20)=branch(i,20)/branch(i,19);
% end
end
end
branch1=branch;
end
⛄ 运行结果
⛄ 参考文献
[1]赵孟雨, 王贤宁, 徐康仪. 基于MATLAB/GUI的电动汽车充电站有序充放电优化调度仿真平台[J]. 电力学报, 2020(2):6.
[2]徐丹. 电动汽车接入配电网需求侧响应模型研究. Diss. 华北电力大学, 2015.