120 lines
3.6 KiB
Plaintext
120 lines
3.6 KiB
Plaintext
clear
|
|
clc
|
|
% yalmip('clear')
|
|
addpath('.\Powerflow')
|
|
[~, ~, ~, ~,Volt,Vangle,Y,Yangle,r,c,newwordParameter,PG,QG,PD,QD,Balance]=pf('ieee14.dat', '0');
|
|
%% 量测量
|
|
% 电压 节点电流 支路电流 节点功率 支路功率
|
|
%%
|
|
%% 状态量
|
|
% 电压 相角
|
|
%%
|
|
%% 开始生成量测量
|
|
sigma=0.01;% 标准差
|
|
%% 电压
|
|
%电压幅值
|
|
rVolt=Volt; %幅值
|
|
mVolt=rVolt.*(normrnd(0,sigma,length(Volt),1)+1);%电压量测量
|
|
rVAngel=Vangle;
|
|
%% 电流
|
|
%注入电流
|
|
cmpY=Y.*exp(1j*sparse(r,c,Yangle,length(Y),length(Y)));%复数导纳矩阵
|
|
cmpV=Volt.*exp(1j*Vangle); %复数电压
|
|
cmpI=cmpY*cmpV;% 注入电流
|
|
rI=abs(cmpI); %注入电流量测量要的是电流幅值
|
|
mI=rI.*(normrnd(0,sigma,length(rI),1)+1);%电流量测量
|
|
%% 支路电流
|
|
% 支路电流
|
|
lineI=newwordParameter.line.lineI;
|
|
lineJ=newwordParameter.line.lineJ;
|
|
lineR=newwordParameter.line.lineR;
|
|
lineX=newwordParameter.line.lineX;
|
|
lineB2=newwordParameter.line;
|
|
|
|
cmpBranchI=(cmpV(lineI)-cmpV(lineJ))./(lineR+1j*lineX);%复数支路电流
|
|
rBranchI=abs(cmpBranchI);% 支路电流幅值
|
|
mBranchI=rBranchI.*(normrnd(0,sigma,length(rBranchI),1)+1);%支路电流量测量
|
|
%% 支路功率
|
|
rBranchP=real((cmpV(lineI)-cmpV(lineJ)).*conj(cmpBranchI));
|
|
mBranchP=rBranchP.*(normrnd(0,sigma,length(rBranchP),1)+1);%支路功率量测量
|
|
rBranchQ=imag((cmpV(lineI)-cmpV(lineJ)).*conj(cmpBranchI));
|
|
mBranchQ=rBranchQ.*(normrnd(0,sigma,length(rBranchQ),1)+1);%支路功率量测量
|
|
%% 注入功率
|
|
rPD=PD;
|
|
PDi=find(PD~=0);
|
|
rQD=QD;
|
|
QDi=find(QD~=0);
|
|
rPG=PG;
|
|
PGi=find(PG~=0);
|
|
rQG=QG;
|
|
QGi=find(QG~=0);
|
|
mPD=rPD.*(normrnd(0,sigma,length(rPD),1)+1);
|
|
mQD=rQD.*(normrnd(0,sigma,length(rQD),1)+1);
|
|
mPG=rPG.*(normrnd(0,sigma,length(rPG),1)+1);
|
|
mQG=rQG.*(normrnd(0,sigma,length(rQG),1)+1);
|
|
%% 0注入节点
|
|
zerosInjectionIndex=1:length(Volt);
|
|
zerosInjectionIndex=zerosInjectionIndex( ~(PD~=0|QD~=0|PG~=0|QG~=0) );
|
|
%% 变压器功率
|
|
rTransP=TransPower( newwordParameter,cmpY,rVolt,rVAngel );
|
|
rTransQ=TransReactivePower( newwordParameter,cmpY,rVolt,rVAngel );
|
|
mTransP=rTransP.*(normrnd(0,sigma,length(rTransP),1)+1);
|
|
mTransQ=rTransQ.*(normrnd(0,sigma,length(rTransQ),1)+1);
|
|
%% 发电机注入功率
|
|
% 先找到只有发电机的节点
|
|
PDQDi=union(PDi,QDi);
|
|
onlyPG=setdiff(PGi,PDQDi);
|
|
onlyQG=setdiff(QGi,PDQDi);
|
|
%% 冗余度计算
|
|
stateVarCount=2*length(Volt);
|
|
measurements=length(mVolt)+length(mBranchI)+length(mBranchP)+length(mBranchQ)+length(mPG)+length(mQG)+length(mTransP)+length(mTransQ);
|
|
fprintf('冗余度 %f\n',measurements/stateVarCount);
|
|
%% Opti ToolBox
|
|
Busnum=length(Volt);
|
|
seOpti=SEOpti();
|
|
%% save
|
|
% save('mVolt','mVolt');
|
|
% save('mPG','mPG');
|
|
% save('mQG','mQG');
|
|
% save('mBranchI','mBranchI');
|
|
% save('mBranchP','mBranchP');
|
|
% save('mBranchQ','mBranchQ');
|
|
% save('mTransP','mTransP');
|
|
% save('mTransQ','mTransQ');
|
|
%% load
|
|
load('mVolt');
|
|
load('mPG');
|
|
load('mQG');
|
|
load('mBranchI');
|
|
load('mBranchP');
|
|
load('mBranchQ');
|
|
load('mTransP');
|
|
load('mTransQ');
|
|
seOpti=seOpti.init(Busnum, mVolt,sigma,newwordParameter,zerosInjectionIndex,cmpY,onlyPG,onlyQG,mPG,mQG,Balance,mBranchI,mBranchP,mBranchQ,mTransP,mTransQ);
|
|
opts = optiset('solver','ipopt');
|
|
opts.maxiter=85500;
|
|
opts.maxtime=3000;
|
|
opts.maxfeval=85000;
|
|
opts.maxnodes=85000;
|
|
opts.tolrfun=1e-4;
|
|
opts.tolafun=1e-4;
|
|
opts.warnings='all';
|
|
opts.display='off';
|
|
% x0=[ones(Busnum,1);zeros(Busnum,1)];
|
|
x0=[rVolt;rVAngle];
|
|
[~,seOpti]=seOpti.equ(x0);
|
|
nlrhs=seOpti.nlrhs();
|
|
nle=seOpti.nle();
|
|
Opt = opti('fun',@seOpti.fun,'ndec',length(Volt)*2,'nlmix',@seOpti.equ,nlrhs,nle,'options',opts)
|
|
% Opt = opti('fun',@seOpti.fun,'ndec',length(Volt)*2,'options',opts)
|
|
[x,fval,exitflag,info] = solve(Opt,x0);
|
|
info
|
|
%% 输出结果
|
|
SEVolt=x(1:length(Volt));
|
|
SEVAngel=x(length(Volt)+Balance:2*length(Volt));
|
|
fprintf('目标函数为:%f\n',fval);
|
|
fprintf('相对误差\n');
|
|
(abs(rVolt-double(SEVolt)))./(rVolt)
|
|
MaxDeviation(rVolt,SEVolt,rVAngel,SEVAngel)
|
|
plotAndComparison( rVolt,rVAngel,SEVolt,SEVAngel )
|
|
seOpti.fun(x); |