-
大小: 4KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-06-11
- 语言: Matlab
- 标签:
资源简介
标准合作型协同进化遗传算法matlab源程序,对函数进行优化
代码片段和文件信息
function CoGA
%COGA Summary of this function goes here
% Detailed explanation goes here
% 标准合作型协同进化遗传算法
clc;
clear all;
global POPSIZE POPULATION BESTINDIVIDUAL CURRENTBEST
global P0 P1 P2 P3 T PC PM BINDEX WINDEX FAVER FMAX
POPSIZE=20;T=3;Pc=0.95;Pm=0.3;
t=1;
bound=[-4 4];
PO1=initga(POPSIZEbound);
PO2=initga(POPSIZEbound);
%caculate the individual fitness
[PO1x2]=gafit(PO1PO2POPSIZE1);
[PO2x1]=gafit(PO2PO1POPSIZE1);
%maitain the best individuals
fitne1=PO1(:2)‘;fitne2=PO2(:2)‘;
fitne=[fitne1fitne2];
fma1=max(fitne1);fma2=max(fitne2);
in1=find(fma1==fitne1);
in2=find(fma2==fitne2);
best{t1}=[PO1(in1(1):)x2;PO2(in2(1):)x1];
%search for the best fitness
fmaa=[fma1fma2];fma=max(fmaa);
in=find(fma==fmaa);
fmi1=min(fitne1);fmi2=min(fitne2);
fav=mean(fitne);
BINDEX1=findstr(fitne1fma1); % the best fitness index of PO1
BINDEX2=findstr(fitne2fma2);
WINDEX1=findstr(fitne1fmi1); % the worst fitness index of PO1
WINDEX2=findstr(fitne2fmi2); % the worst fitness index of PO1
Bestin1=PO1(BINDEX1:);Bestin2=PO2(BINDEX2:);
CURRENTBEST1{11}=Bestin1;
CURRENTBEST2{11}=Bestin2;
while t < T
t=t+1;
% generate the next time population
%PO1
PO11=selectga(PO1POPSIZE1);
PO12=crossga(PO11POPSIZEPC1);
PO13=uniformMutate(PO12boundPM);
%PO2
PO21=selectga(PO2POPSIZE1);
PO22=crossga(PO21POPSIZEPC1);
PO23=uniformMutate(PO22boundPM);
%caculate the individual fitness
[PO1x2]=gafit(PO1PO2POPSIZE1);
[PO2x1]=gafit(PO2PO1POPSIZE1);
%caculate the individual fitness
[PO1x2]=gafit(PO1PO2POPSIZE1);
[PO2x1]=gafit(PO2PO1POPSIZE1);
fitne1=PO1(:2)‘;fitne2=PO2(:2)‘;
fitne=[fitne1fitne2];
fma1=max(fitne1);fma2=max(fitne2);
in1=find(fma1==fitne1);
in2=find(fma2==fitne2);
best{t1}=[PO1(in1(11):)x2(11);PO2(in2(11):)x1(11)];
fmaa=[fma1fma2];fma=max(fmaa);
in=find(fma==fmaa);
fmi1=min(fitne1);fmi2=min(fitne2);
fav=mean(fitne);
BINDEX1=findstr(fitne1fma1); % the best fitness index of PO1
BINDEX2=findstr(fitne2fma2);
WINDEX1=findstr(fitne1fmi1); % the worst fitness index of PO1
WINDEX2=findstr(fitne2fmi2); % the worst fitness index of PO1
Bestin1=PO1(BINDEX1(11):);Bestin2=PO2(BINDEX2(11):);
if Bestin1(:2)>CURRENTBEST1{t-11}(:2)
CURRENTBEST1{t1}=Bestin1;
else
PO1(WINDEX1(11):)=CURRENTBEST1{t-11};
CURRENTBEST1{t1}=CURRENTBEST1{t-11};
end
if Bestin2(:2)>CURRENTBEST2{t-11}(:2)
CURRENTBEST2{t1}=Bestin2;
else
PO2(WINDEX2(11):)=CURRENTBEST2{t-11};
CURRENTBEST2{t1}=CURRENTBEST2{t-11};
end
[PO13x2]=gafit(PO13PO23POPSIZE1);
PO1=PO13;
[PO23x1]=gafit(PO23PO13POPSIZE1);
PO2=PO23;
end
best
for i=1:T
a(::i)=best{i1};
end
a
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2949 2010-11-24 16:40 CoGA\CoGA.asv
文件 2956 2010-11-24 16:43 CoGA\CoGA.m
文件 116 2010-11-24 15:25 CoGA\crossga.asv
文件 438 2010-11-24 16:26 CoGA\crossga.m
文件 149 2010-11-24 16:00 CoGA\eliga.asv
文件 1018 2010-11-24 16:40 CoGA\eliga.m
文件 209 2010-11-24 15:35 CoGA\gafit.asv
文件 310 2010-11-24 16:23 CoGA\gafit.m
文件 209 2010-11-23 15:37 CoGA\initga.m
文件 333 2010-11-24 16:26 CoGA\selectga.m
文件 237 2010-11-24 15:33 CoGA\uniformMutate.m
目录 0 2010-11-29 16:45 CoGA
----------- --------- ---------- ----- ----
8924 12
- 上一篇:基于Gram-schmidt法的QR分解。
- 下一篇:JPEG压缩算法 MATLAB
评论
共有 条评论