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(POPSIZE,bound);
PO2=initga(POPSIZE,bound);
%计算个体的适应度
[PO1,x2]=gafit(PO1,PO2,POPSIZE,1);
[PO2,x1]=gafit(PO2,PO1,POPSIZE,1);
%maitain the best individuals
fitne1=PO1(:,2)';fitne2=PO2(:,2)';
fitne=[fitne1,fitne2];
fma1=max(fitne1);fma2=max(fitne2);
in1=find(fma1==fitne1);
in2=find(fma2==fitne2);
best{t,1}=[PO1(in1(1),:),x2;PO2(in2(1),:),x1];
%search for the best fitness
fmaa=[fma1,fma2];fma=max(fmaa);
in=find(fma==fmaa);
fmi1=min(fitne1);fmi2=min(fitne2);
fav=mean(fitne);
BINDEX1=findstr(fitne1,fma1); % the best fitness index of PO1
BINDEX2=findstr(fitne2,fma2);
WINDEX1=findstr(fitne1,fmi1); % the worst fitness index of PO1
WINDEX2=findstr(fitne2,fmi2); % the worst fitness index of PO1
Bestin1=PO1(BINDEX1,:);Bestin2=PO2(BINDEX2,:);
CURRENTBEST1{1,1}=Bestin1;
CURRENTBEST2{1,1}=Bestin2;
while t < T
t=t+1;
% generate the next time population
%PO1
PO11=selectga(PO1,POPSIZE,1);
PO12=crossga(PO11,POPSIZE,PC,1);
PO13=uniformMutate(PO12,bound,PM);
%PO2
PO21=selectga(PO2,POPSIZE,1);
PO22=crossga(PO21,POPSIZE,PC,1);
PO23=uniformMutate(PO22,bound,PM);
%caculate the individual fitness
[PO1,x2]=gafit(PO1,PO2,POPSIZE,1);
[PO2,x1]=gafit(PO2,PO1,POPSIZE,1);
%caculate the individual fitness
[PO1,x2]=gafit(PO1,PO2,POPSIZE,1);
[PO2,x1]=gafit(PO2,PO1,POPSIZE,1);
fitne1=PO1(:,2)';fitne2=PO2(:,2)';
fitne=[fitne1,fitne2];
fma1=max(fitne1);fma2=max(fitne2);
in1=find(fma1==fitne1);
in2=find(fma2==fitne2);
best{t,1}=[PO1(in1(1,1),:),x2(1,1);PO2(in2(1,1),:),x1(1,1)];
fmaa=[fma1,fma2];fma=max(fmaa);
in=find(fma==fmaa);
fmi1=min(fitne1);fmi2=min(fitne2);
fav=mean(fitne);
BINDEX1=findstr(fitne1,fma1); % the best fitness index of PO1
BINDEX2=findstr(fitne2,fma2);
WINDEX1=findstr(fitne1,fmi1); % the worst fitness index of PO1
WINDEX2=findstr(fitne2,fmi2); % the worst fitness index of PO1
Bestin1=PO1(BINDEX1(1,1),:);Bestin2=PO2(BINDEX2(1,1),:);
if Bestin1(:,2)>CURRENTBEST1{t-1,1}(:,2)
CURRENTBEST1{t,1}=Bestin1;
else
PO1(WINDEX1(1,1),:)=CURRENTBEST1{t-1,1};
CURRENTBEST1{t,1}=CURRENTBEST1{t-1,1};
end
if Bestin2(:,2)>CURRENTBEST2{t-1,1}(:,2)
CURRENTBEST2{t,1}=Bestin2;
else
PO2(WINDEX2(1,1),:)=CURRENTBEST2{t-1,1};
CURRENTBEST2{t,1}=CURRENTBEST2{t-1,1};
end
[PO13,x2]=gafit(PO13,PO23,POPSIZE,1);
PO1=PO13;
[PO23,x1]=gafit(PO23,PO13,POPSIZE,1);
PO2=PO23;
end
best
for i=1:T
a(:,:,i)=best{i,1};
end
a
IT狂飙
- 粉丝: 4842
- 资源: 2650
最新资源
- 10-【附件】-10-续签劳动合同补充协议书.docx
- 10-【附件】-14-劳动合同到期人员续签审批表.xlsx
- 10-【附件】-11-续订劳动合同意向通知书及回执.docx
- 10-【附件】-07-终止劳动合同通知书.docx
- 10-【附件】-12-劳动合同终止办理情况登记表.docx
- 10-【附件】-08-终止劳动合同证明书.docx
- 10-【附件】-13-劳动合同签收备案表.xlsx
- 11-【员工手册】-06-公司员工手册.docx
- 四旋翼无人机PID控制的MATLAB仿真.zip
- 四足机器人线性MPC控制平台Webots MATLAB.zip
- 睡眠波分析是一个开源的matlab工具箱,用于对睡眠脑电图数据中的各种波形进行评分和分析.zip
- 随机森林的MATLAB实现支持任意弱学习者,你可以定义.zip
- 它包含与我的机器学习笔记相关的所有MATLAB演示代码.zip
- 孙宏福QSM重构管道的MATLAB代码.zip
- 它是用MATLAB开发的用于建筑或暖通空调系统能源系统建模的小型软件.zip
- 提供的函数将您从实时脚本生成的latex转换为markdown,以便它可以轻松地生成带有MATLAB代码方程和图形的R.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈