《基于遗传算法的无功优化与控制毕业设计》由会员分享,可在线阅读,更多相关《基于遗传算法的无功优化与控制毕业设计(5页珍藏版)》请在金锄头文库上搜索。
1、本文格式为Word版,下载可任意编辑基于遗传算法的无功优化与控制 毕业设计 基于遗传算法的无功优化与操纵 LD=fscanf(fid,%g,4,NLD); %离散电抗补偿装置位置、上下限档数、单档容量 rmin=fscanf(fid,%d,1,1); %处治因子的最小取值 fclose(fid);%关闭数据文件 Gnumber=Gnumber; LC=LC; T=T; CD=CD; LD=LD; initial子程序: function x,fitness,n,n1,isb,pr,iternu,X,B1,B2=initial(popsize,NV,Gnumber,NLC,NT,NCD,NLD,
2、node,VGmax,VGmin,Vjmax,Vjmin,LC,T,CD,LD,rmin) x=zeros(popsize,NV+NLC+NT+NCD+NLD); DV=zeros(1,NV); DLC=zeros(1,NLC); DNT=zeros(1,NT); DCD=zeros(1,NCD); DLD=zeros(1,NLD); fitness=zeros(1,popsize); B1,B2,n,n1,isb,pr,iternu,X=readnet(node);%读取网络参数 k=1;%disp(LC) while kfitness_newmax fitness_newmax=fitne
3、ss_new(i); end end fitness_newavg=fitness_newsum/popsize; x=X_new; fitness=fitness_new; crossover子程序: function x,fitness=crossover(x,fitness,popsize,Fitness_newavg,Fitness_newmax,NV,NLC,NT,NCD,NLD) pc1=0.99; pc2=0.7; for i=2:popsize/2 if fitness(i)fitness(popsize/2+i) f=fitness(i); else f=fitness(po
4、psize/2+i); end if fFitness_newavg 第 44 页, 共 47页 基于遗传算法的无功优化与操纵 pc=pc1-(pc1-pc2)*(f-Fitness_newavg)/(Fitness_newmax-Fitness_newavg); else pc=pc1; end crossr=rand; if crossr crossp=round(rand(1,NV+NLC+NT+NCD+NLD); for m=1:NV+NLC+NT+NCD+NLD a=rand; temp=x(i,m); if crossp(1,m)=1 if mNV+NLC x(i,m)=round
5、(a*x(i,m)+(1-a)*x(popsize/2+i,m); x(popsize/2+i,m)=round(a*x(popsize/2+i,m)+(1-a)*temp); else x(i,m)=a*x(i,m)+(1-a)*x(popsize/2+i,m); x(popsize/2+i,m)=a*x(popsize/2+i,m)+(1-a)*temp; end end end end end mutition子程序: function x,fitness=mutation(x,fitness,popsize,fitness_newavg,fitness_newmax,NV,NLC,NT
6、,NCD,NLD,VGmax,VGmin,LC,T,CD,LD) pm1=0.1; pm2=0.001; for i=2:popsize if fitness(i)fitness_newavg pm=pm1-(pm1-pm2)*(fitness(i)-fitness_newavg)/(fitness_newmax-fitness_newavg); else pm=pm1; end 第 45 页, 共 47页 基于遗传算法的无功优化与操纵 mutationr=rand; if mutationr mutationp=round(rand(1,NV+NLC+NT+NCD+NLD); for m=1
7、:NV+NLC+NT+NCD+NLD if mutationp(1,m)=0 if mNV+NLC+NT+NCD x(i,m)=round(x(i,m)-(x(i,m)-LD(m-(NV+NLC+NT+NCD),3)*rand); elseif mNV+NLC+NT elseif mNV+NLC x(i,m)=round(x(i,m)-(x(i,m)-T(m-(NV+NLC),4)*rand); elseif mNV x(i,m)=x(i,m)-(x(i,m)-LC(m-NV,3)*rand; else x(i,m)=x(i,m)-(x(i,m)-VGmin)*rand; end else i
8、f mNV+NLC+NT+NCD x(i,m)=round(x(i,m)+(LD(m-(NV+NLC+NT+NCD),2)-x(i,m)*rand); elseif mNV+NLC+NT x(i,m)=round(x(i,m)+(CD(m-(NV+NLC+NT),2)-x(i,m)*rand); elseif mNV+NLC x(i,m)=round(x(i,m)+(T(m-(NV+NLC),3)-x(i,m)*rand); elseif mNV x(i,m)=x(i,m)+(LC(m-NV,2)-x(i,m)*rand; else x(i,m)=x(i,m)+(VGmax-x(i,m)*rand; end end end end end adapting子程序: function 第 46 页, 共 47页 x(i,m)=round(x(i,m)-(x(i,m)-CD(m-(NV+NLC+NT),3)*rand); 5