加入了各种统计值。

This commit is contained in:
facat 2013-01-21 21:47:54 +08:00
parent 7ded138066
commit 0f8edee30b
15 changed files with 266 additions and 128 deletions

14
@ForThesis/AddPDQDPGQG.m Normal file
View File

@ -0,0 +1,14 @@
function this=AddPDQDPGQG( this, PD,QD,PG,QG)
%ADDPD Summary of this function goes here
% Detailed explanation goes here
if this.currentPos>this.sampleNum
error('');
return;
end
this.currentPos=this.currentPos+1;
this.PDArray(:,this.currentPos)=PD;
this.QDArray(:,this.currentPos)=QD;
this.PGArray(this.currentPos)=PG;
this.QGArray(this.currentPos)=QG;
end

30
@ForThesis/ForThesis.m Normal file
View File

@ -0,0 +1,30 @@
classdef ForThesis
%UNTITLED Summary of this class goes here
% Detailed explanation goes here
properties
currentPos=0;
sampleNum=0;
LoadNum=0;
PDArray=0;
QDArray=0;
PGArray=0;
QGArray=0;
end
methods
function this=ForThesis(sampleNum,LoadNum)
this.currentPos=0;%100
this.sampleNum=sampleNum;
this.LoadNum=LoadNum;
this.PDArray=zeros(LoadNum,sampleNum);
this.QDArray=zeros(LoadNum,sampleNum);
this.PGArray=zeros(sampleNum,1);
this.QGArray=zeros(sampleNum,1);
end
end
end

View File

@ -0,0 +1,7 @@
function MaxDeviation(this,PG0,QG0,PD0,QD0)
PD0Array=repmat(PD0,1,this.sampleNum);
QD0Array=repmat(QD0,1,this.sampleNum);
PDMaxDev=max(abs(this.PDArray-PD0Array),[],2)
QDMaxDev=max(abs(this.QDArray-QD0Array),[],2)
PG0Array=repmat()
end

11
@ForThesis/MaxDeviation.m Normal file
View File

@ -0,0 +1,11 @@
function [output_arg]=MaxDeviation(this,PG0,QG0,PD0,QD0)
PD0Array=repmat(PD0,1,this.sampleNum);
QD0Array=repmat(QD0,1,this.sampleNum);
PDMaxDev=max(abs( (this.PDArray-PD0Array)./PD0Array ),[],2);
QDMaxDev=max(abs( (this.QDArray-QD0Array)./QD0Array ),[],2);
PG0Array=repmat(PG0,this.sampleNum,1);
QG0Array=repmat(QG0,this.sampleNum,1);
PGMaxDev=max(abs( (PG0Array-this.PGArray)./PG0Array ));
QGMaxDev=max( abs( (QG0Array-this.QGArray)./QG0Array ) );
output_arg=max([PDMaxDev;QDMaxDev;PGMaxDev;QGMaxDev]);
end

7
@ForThesis/MeanPD.m Normal file
View File

@ -0,0 +1,7 @@
function [ output_args ] = MeanPD(this)
%MEANPD Summary of this function goes here
% Detailed explanation goes here
output_args=sum(this.PDArray,2)/this.sampleNum;
end

7
@ForThesis/MeanPG.m Normal file
View File

@ -0,0 +1,7 @@
function [ output_args ] = MeanPG( this )
%MEANPG Summary of this function goes here
% Detailed explanation goes here
output_args=sum(this.PGArray,1)/this.sampleNum;
end

7
@ForThesis/MeanQD.m Normal file
View File

@ -0,0 +1,7 @@
function [ output_args ] = MeanQD(this)
%MEANQD Summary of this function goes here
% Detailed explanation goes here
output_args=sum(this.QDArray,2)/this.sampleNum;
end

7
@ForThesis/MeanQG.m Normal file
View File

@ -0,0 +1,7 @@
function [ output_args ] = MeanQG( this )
%MEAQG Summary of this function goes here
% Detailed explanation goes here
output_args=sum(this.QGArray,1)/this.sampleNum;
end

View File

@ -0,0 +1,15 @@
function [ output_args ] = StatDeviation( this,PG0,QG0,PD0,QD0 )%ͳ¼ÆÎó²î
%STATDEVIATION Summary of this function goes here
% Detailed explanation goes here
PD0Array=repmat(PD0,1,this.sampleNum);
QD0Array=repmat(QD0,1,this.sampleNum);
PDMaxDev=max(abs(this.PDArray-PD0Array),[],2);
QDMaxDev=max(abs(this.QDArray-QD0Array),[],2);
PG0Array=repmat(PG0,this.sampleNum,1);
QG0Array=repmat(QG0,this.sampleNum,1);
PGMaxDev=max(abs(PG0Array));
QGMaxDev=max(abs(QG0Array));
end

View File

@ -0,0 +1,20 @@
function [ output_args ] = StatDeviation( this,PG0,QG0,PD0,QD0 )%ͳ¼ÆÎó²î
%STATDEVIATION Summary of this function goes here
% Detailed explanation goes here
PD0Array=repmat(PD0,1,this.sampleNum);
QD0Array=repmat(QD0,1,this.sampleNum);
PDDev=(this.PDArray-PD0Array)/0.05;
QDDev=(this.QDArray-QD0Array)/0.05;
PG0Array=repmat(PG0,this.sampleNum,1);
QG0Array=repmat(QG0,this.sampleNum,1);
PGDev=(PG0Array-this.PGArray)/0.01;
QGDev=(QG0Array-this.QGArray)/0.01;
wholeMat=[PDDev;QDDev;PGDev';QGDev'];
t1=wholeMat.^2;
t2=sum(t1,1);
t3=t2/size(t1,1);
t4=t3.^2;
output_args=sum(t4)/length(t4);
end

View File

@ -8,14 +8,14 @@ VoltU=(1.1)*ones(1,Busnum);
%VoltU=10*ones(1,Busnum); %VoltU=10*ones(1,Busnum);
PDU=PD0(Loadi); PDU=PD0(Loadi);
% PDU=noDataTransCapacity; % PDU=noDataTransCapacity;
PDU(PDU>0)=1.200*PDU(PDU>0); PDU(PDU>0)=1.300*PDU(PDU>0);
PDU(PDU<0)=0.800*PDU(PDU<0); PDU(PDU<0)=0.700*PDU(PDU<0);
PDU(PDU==0)=0.400; PDU(PDU==0)=0.400;
%PDU=10*ones(length(Loadi),1); %PDU=10*ones(length(Loadi),1);
QDU=QD0(Loadi); QDU=QD0(Loadi);
QDU(QDU>0)=1.200*QDU(QDU>0); QDU(QDU>0)=1.300*QDU(QDU>0);
QDU(QDU<0)=0.800*QDU(QDU<0); QDU(QDU<0)=0.700*QDU(QDU<0);
QDU(QDU==0)=0.200; QDU(QDU==0)=0.400;
% PF=0.85; % PF=0.85;
% QDU=1.0*PD(Loadi).*sqrt(1 -PF.^2)./PF; % QDU=1.0*PD(Loadi).*sqrt(1 -PF.^2)./PF;
t1=([PU',QU',PDU',QDU',VoltU])'; t1=([PU',QU',PDU',QDU',VoltU])';

View File

@ -7,14 +7,14 @@ QL=-5*ones(length(PVQL(:,1)),1);
VoltL=(0.9)*ones(1,Busnum); VoltL=(0.9)*ones(1,Busnum);
%VoltL=-10*ones(1,Busnum); %VoltL=-10*ones(1,Busnum);
PDL=PD0(Loadi); PDL=PD0(Loadi);
PDL(PDL>0)=0.800*PDL(PDL>0); PDL(PDL>0)=0.700*PDL(PDL>0);
PDL(PDL<0)=1.200*PDL(PDL<0); PDL(PDL<0)=1.300*PDL(PDL<0);
PDL(PDL==0)=-0.400; PDL(PDL==0)=-0.400;
%PDL=-10*ones(length(Loadi),1); %PDL=-10*ones(length(Loadi),1);
QDL=QD0(Loadi); QDL=QD0(Loadi);
QDL(QDL>0)=0.800*QDL(QDL>0); QDL(QDL>0)=0.700*QDL(QDL>0);
QDL(QDL<0)=1.200*QDL(QDL<0); QDL(QDL<0)=1.300*QDL(QDL<0);
QDL(QDL==0)=-0.200; QDL(QDL==0)=-0.400;
% QDL=0*PD(Loadi).*sqrt((1-PF.^2))./PF; % QDL=0*PD(Loadi).*sqrt((1-PF.^2))./PF;
t1=([PL',QL',PDL',QDL',VoltL])'; t1=([PL',QL',PDL',QDL',VoltL])';
t2=Mat_G-Init_L'-t1; t2=Mat_G-Init_L'-t1;

View File

@ -51,7 +51,8 @@ QD0(Loadi)=QD0(Loadi).*(1+normrnd(0,0.05,length(Loadi),1));
PG0(PGi)=PG0(PGi).*(1+normrnd(0,0.01,length(PGi),1)); PG0(PGi)=PG0(PGi).*(1+normrnd(0,0.01,length(PGi),1));
QG0(PVi)=QG0(PVi).*(1+normrnd(0,0.01,length(PVi),1)); QG0(PVi)=QG0(PVi).*(1+normrnd(0,0.01,length(PVi),1));
%% 读变压器容量 %% 读变压器容量
[noDataTransNum noDataTransCapacity noDataTransPowerFactor]=ReadNoDataTrans(fileName); %[noDataTransNum noDataTransCapacity noDataTransPowerFactor]=ReadNoDataTrans('C:/b/东际911_2751267_2012-09-05/iPso_东际911_2751267_2012-09-05_变压器无负载.txt');
noDataTransCapacity=0;
while(abs(Gap)>Precision) while(abs(Gap)>Precision)
if KK>kmax if KK>kmax
break; break;
@ -83,7 +84,7 @@ while(abs(Gap)>Precision)
Mat_H=FormH(Busnum,Volt,PG,PD,QG,QD,Y,UAngel,r,c,Angle,QD_NON_ZERO,QD_NON_ZERO_IND,Loadi); Mat_H=FormH(Busnum,Volt,PG,PD,QG,QD,Y,UAngel,r,c,Angle,QD_NON_ZERO,QD_NON_ZERO_IND,Loadi);
Ly=Mat_H; Ly=Mat_H;
Lz=FormLz(Mat_G,Init_L,GenL,Busnum,PVQL,PD,PD0,QD0,Loadi,KK,PF); Lz=FormLz(Mat_G,Init_L,GenL,Busnum,PVQL,PD,PD0,QD0,Loadi,KK,PF);
Lw=FormLw(Mat_G,Init_U,GenU,Busnum,PVQU,PD,PD0,QD0,Loadi,KK,PF); Lw=FormLw(Mat_G,Init_U,GenU,Busnum,PVQU,PD,PD0,QD0,Loadi,KK,PF,noDataTransCapacity);
Lx=FormLx(deltF,deltH,Init_Y,deltG,Init_Z,Init_W); Lx=FormLx(deltF,deltH,Init_Y,deltG,Init_Z,Init_W);
YY=FormYY(Lul,Lz,Ly,Luu,Lw,Lx); YY=FormYY(Lul,Lz,Ly,Luu,Lw,Lx);
%% 开始解方程 %% 开始解方程
@ -97,7 +98,7 @@ while(abs(Gap)>Precision)
end end
fprintf('迭代次数%d\n',KK); fprintf('迭代次数%d\n',KK);
fprintf('目标值%f\n',full(ObjectiveFun(PG,PG0,PGi,QG,QG0,PVi,PD,PD0,QD,QD0,wPG,wQG,wPD,wQD,Loadi))); fprintf('目标值%f\n',full(ObjectiveFun(PG,PG0,PGi,QG,QG0,PVi,PD,PD0,QD,QD0,wPG,wQG,wPD,wQD,Loadi)));
DrawGap(plotGap); % DrawGap(plotGap);
%% %%
%Volt=full(Volt'); %Volt=full(Volt');
%PD=full(PD); %PD=full(PD);

152
OPF.m
View File

@ -1,59 +1,62 @@
tic tic
clc clc
clear clear
[kmax,Precision,UAngel,Volt,Busnum,PVi,PVu,Balance,Y,Angle,P0,Q0,r,c,GB,Linei,Linej,Transfori,Transforj,GenU,GenL,GenC,PG,QG,PD,QD,CenterA,PGi,PVQU,PVQL,Liner,Linex,Lineb,Transforr,Transforx,Transfork0]= ... thesis=ForThesis(4,8);
pf('c:/newFIle.txt'); for II=1:4
%pf('D:\Project\\\\\9223-1_0.5_120%.txt'); [kmax,Precision,UAngel,Volt,Busnum,PVi,PVu,Balance,Y,Angle,P0,Q0,r,c,GB,Linei,Linej,Transfori,Transforj,GenU,GenL,GenC,PG,QG,PD,QD,CenterA,PGi,PVQU,PVQL,Liner,Linex,Lineb,Transforr,Transforx,Transfork0]= ...
%pf('D:\Project\\\919.txt'); pf('c:/newFIle.txt');
%pf('c:/file31.txt'); %pf('D:\Project\\\\\9223-1_0.5_120%.txt');
%pf('D:\Project\\\919.txt');
%pf('c:/file31.txt');
%% %%
Loadi=QD~=0 | PD~=0; Loadi=QD~=0 | PD~=0;
PF=sqrt(PD(Loadi).^2./(QD(Loadi).^2+PD(Loadi).^2)) PF=sqrt(PD(Loadi).^2./(QD(Loadi).^2+PD(Loadi).^2))
%% %%
Volt; Volt;
UAngel*180/3.1415926; UAngel*180/3.1415926;
%% PG %% PG
AngleIJ=sparse(r,c,UAngel(r)-UAngel(c)-Angle',Busnum,Busnum); AngleIJ=sparse(r,c,UAngel(r)-UAngel(c)-Angle',Busnum,Busnum);
PGBal=PD+diag(Volt)*Y.*cos(AngleIJ)*Volt'; PGBal=PD+diag(Volt)*Y.*cos(AngleIJ)*Volt';
QGBal=QD+diag(Volt)*Y.*sin(AngleIJ)*Volt'; QGBal=QD+diag(Volt)*Y.*sin(AngleIJ)*Volt';
%% - %% -
PG0=PG; PG0=PG;
QG0=QG; QG0=QG;
PD0=PD; PD0=PD;
QD0=QD; QD0=QD;
PDReal=PD;% PDReal=PD;%
QDReal=QD;% QDReal=QD;%
%PD0(12)=PD0(12)+0.001; %PD0(12)=PD0(12)+0.001;
%% %%
PG0(Balance)=PGBal(Balance); PG0(Balance)=PGBal(Balance);
PG(Balance)=PGBal(Balance); PG(Balance)=PGBal(Balance);
QG0(Balance)=QGBal(Balance); QG0(Balance)=QGBal(Balance);
QG0(PVi)=QGBal(PVi); QG0(PVi)=QGBal(PVi);
QG(PVi)=QGBal(PVi); QG(PVi)=QGBal(PVi);
%% %%
[Volt,UAngel,Init_Z,Init_W,Init_L,Init_U,Init_Y,PG,QG,RestraintCount,wPG,wQG,wPD,wQD,PD,PD0,QD,randPDind,Loadi]=OPF_Init(Busnum,Balance,PG,QG,Volt,GenU,GenL,PVi,PGi,PVQU,PVQL,PD0,QD0,QD,PD); [Volt,UAngel,Init_Z,Init_W,Init_L,Init_U,Init_Y,PG,QG,RestraintCount,wPG,wQG,wPD,wQD,PD,PD0,QD,randPDind,Loadi]=OPF_Init(Busnum,Balance,PG,QG,Volt,GenU,GenL,PVi,PGi,PVQU,PVQL,PD0,QD0,QD,PD);
Gap=(Init_L*Init_Z'-Init_U*Init_W'); Gap=(Init_L*Init_Z'-Init_U*Init_W');
KK=0; KK=0;
plotGap=zeros(1,60); plotGap=zeros(1,60);
ContrlCount=size(PVi,1)+size(PGi,1)+size(Loadi,1)*2+Busnum*2; ContrlCount=size(PVi,1)+size(PGi,1)+size(Loadi,1)*2+Busnum*2;
kmax=60; kmax=60;
%% 20120523 %% 20120523
QD_NON_ZERO=QD(PD==0 & QD~=0); QD_NON_ZERO=QD(PD==0 & QD~=0);
QD_NON_ZERO_IND=find(PD==0 & QD~=0); QD_NON_ZERO_IND=find(PD==0 & QD~=0);
%% %%
Precision=Precision/1; Precision=Precision/10;
%% %%
PD0(Loadi)=PD0(Loadi).*(1+normrnd(0,0.05,length(Loadi),1)); PD0(Loadi)=PD0(Loadi).*(1+normrnd(0,0.05,length(Loadi),1));
QD0(Loadi)=QD0(Loadi).*(1+normrnd(0,0.05,length(Loadi),1)); QD0(Loadi)=QD0(Loadi).*(1+normrnd(0,0.05,length(Loadi),1));
PG0(PGi)=PG0(PGi).*(1+normrnd(0,0.01,length(PGi),1)); % PG0(PGi)=PG0(PGi).*(1+normrnd(0,0.01,length(PGi),1));
QG0(PVi)=QG0(PVi).*(1+normrnd(0,0.01,length(PVi),1)); % QG0(PVi)=QG0(PVi).*(1+normrnd(0,0.01,length(PVi),1));
%% %%
%[noDataTransNum noDataTransCapacity noDataTransPowerFactor]=ReadNoDataTrans('C:/b/911_2751267_2012-09-05/iPso_911_2751267_2012-09-05_.txt'); %[noDataTransNum noDataTransCapacity noDataTransPowerFactor]=ReadNoDataTrans('C:/b/911_2751267_2012-09-05/iPso_911_2751267_2012-09-05_.txt');
noDataTransCapacity=0; noDataTransCapacity=0;
while(abs(Gap)>Precision)
while(abs(Gap)>Precision)
if KK>kmax if KK>kmax
break; break;
end end
@ -95,26 +98,35 @@ while(abs(Gap)>Precision)
[Init_Z,Init_L,Init_W,Init_U,Init_Y,PG,QG,Volt,UAngel,PD,QD]=Modification(Init_Z,Init_L,Init_W,Init_U,Init_Y,deltZ,deltL,deltW,deltU,deltX,deltY,PG,QG,Volt,UAngel,PVi,ContrlCount,Balance,Busnum,PGi,PD,QD,Loadi); [Init_Z,Init_L,Init_W,Init_U,Init_Y,PG,QG,Volt,UAngel,PD,QD]=Modification(Init_Z,Init_L,Init_W,Init_U,Init_Y,deltZ,deltL,deltW,deltU,deltX,deltY,PG,QG,Volt,UAngel,PVi,ContrlCount,Balance,Busnum,PGi,PD,QD,Loadi);
Gap=(Init_L*Init_Z'-Init_U*Init_W'); Gap=(Init_L*Init_Z'-Init_U*Init_W');
KK=KK+1; KK=KK+1;
end
fprintf('%d\n',KK);
fprintf('%f\n',full(ObjectiveFun(PG,PG0,PGi,QG,QG0,PVi,PD,PD0,QD,QD0,wPG,wQG,wPD,wQD,Loadi)));
% DrawGap(plotGap);
%%
%Volt=full(Volt');
%PD=full(PD);
%% PD
% absPDLoad=abs( (PD(Loadi)-PD0(Loadi))./PD0(Loadi) );
absPDLoad=abs( (PD(Loadi)-PDReal(Loadi))./PDReal(Loadi) );
maxPDError=max(absPDLoad(absPDLoad<10))
absQDLoad=abs( (QD(Loadi)-QDReal(Loadi))./QDReal(Loadi) );
maxQDError=max(absQDLoad(absQDLoad<10))
disp('index');
%Loadi(absPDLoad==maxPDError);
%% 线
totalLoss=(sum(PG)-sum(PD(Loadi)))*100;
fprintf('%f(MW )\n',full(totalLoss));
fprintf('线 %f\n',full(totalLoss/sum(PG)));
%% 线
%Lineloss(Linei,Linej,Liner,Linex,Lineb,Transfori,Transforj,Transforr,Transforx,Transfork0,Volt,UAngel);
thesis=thesis.AddPDQDPGQG(PD(Loadi),QD(Loadi),PG(Balance),QG(PVi));
end end
fprintf('%d\n',KK); PD(Loadi)=thesis.MeanPD();
fprintf('%f\n',full(ObjectiveFun(PG,PG0,PGi,QG,QG0,PVi,PD,PD0,QD,QD0,wPG,wQG,wPD,wQD,Loadi))); QD(Loadi)=thesis.MeanQD();
DrawGap(plotGap); PG(Balance)=thesis.MeanPG();
%% QG(PVi)=thesis.MeanQG();
%Volt=full(Volt'); thesis.MaxDeviation(PG0(Balance),QG0(PVi),PD0(Loadi),QD0(Loadi));
%PD=full(PD); thesis.StatDeviation(PG0(Balance),QG0(PVi),PD0(Loadi),QD0(Loadi))
%% PD
% absPDLoad=abs( (PD(Loadi)-PD0(Loadi))./PD0(Loadi) );
absPDLoad=abs( (PD(Loadi)-PDReal(Loadi))./PDReal(Loadi) );
maxPDError=max(absPDLoad(absPDLoad<10))
absQDLoad=abs( (QD(Loadi)-QDReal(Loadi))./QDReal(Loadi) );
maxQDError=max(absQDLoad(absQDLoad<10))
disp('index');
%Loadi(absPDLoad==maxPDError);
%% 线
totalLoss=(sum(PG)-sum(PD(Loadi)))*100;
fprintf('%f(MW )\n',full(totalLoss));
fprintf('线 %f\n',full(totalLoss/sum(PG)));
%% 线
%Lineloss(Linei,Linej,Liner,Linex,Lineb,Transfori,Transforj,Transforr,Transforx,Transfork0,Volt,UAngel);
toc toc

View File

@ -17,8 +17,8 @@ tPL=sparse(GenL(:,2));%
tQL=sparse(PVQL(:,1));% tQL=sparse(PVQL(:,1));%
PG(PGi)=(tPU+tPL)/2; PG(PGi)=(tPU+tPL)/2;
QG(PVi)=(tQU+tQL)/2; QG(PVi)=(tQU+tQL)/2;
wPG=100*ones(size(PGi,1),1); wPG=0*ones(size(PGi,1),1);
wQG=100*ones(size(PVi,1),1); wQG=0*ones(size(PVi,1),1);
%randInt=randperm(size(Loadi,1)); %randInt=randperm(size(Loadi,1));
%randPDind=randInt(1:10); %randPDind=randInt(1:10);
randPDind=0; randPDind=0;