%主程序 gamain.m
clear all
%定义全局变量
global POPSIZE
global POPULATION
global BEATINDIVIDUAL
global CURRENTBEST
global P0 P01 P02 P03
global T
global PC
global PM
global BINDEX WINDEX
global FAVER
global FMAX
POPSIZE=20;
T=30;
PC=0.95;
PM=0.3;
t=1;
bound=[-4 4];
%% 初始化种群
P01=initga(POPSIZE,bound);
P02=initga(POPSIZE,bound);
%% 计算个体适应值
[P01,x2]=gafit(P01,P02,POPSIZE,1);
[P02,x1]=gafit(P02,P01,POPSIZE,1);
%% 最有个体保留
fitne1=P01(:,2);
fitne2=P02(:,2);
fitne=[fitne1,fitne2];
fma1=max(fitne1);
fma2=max(fitne2);
in1=find(fma1==fitne1);
in2=find(fma2==fitne2);
best{t,1}=[P01(in1(1),:),x2;P02(in2(1),:),x1];
%% 搜索最优个体适应值
fmaa=[fma1,fma2];
fma=max(fmaa);
in=find(fma==fmaa);
fmi1=min(fitne1);
fmi2=min(fitne2);
fav=mean(fitne);
BINDEX1=strfind(fitne1',fma1);
BINDEX2=strfind(fitne2',fma2);
WINDEX1=strfind(fitne1',fmi1);
WINDEX2=strfind(fitne2',fmi2);
Bestin1=P01(BINDEX1,:);
Bestin2=P02(BINDEX2,:);
CURRENTBEST1{1,1}=Bestin1;
CURRENTBEST2{1,1}=Bestin2;
while t<T
t=t+1;
P011=selectga(P01,POPSIZE,1);
P012=crossga(P011,POPSIZE,PC,1);
P013=uniformMutate(P012,bound,PM);
P021=selectga(P02,POPSIZE,1);
P022=crossga(P021,POPSIZE,PC,1);
P023=uniformMutate(P022,bound,PM);
[P01,x2]=gafit(P01,P02,POPSIZE,1);
[P02,X1]=gafit(P02,P01,POPSIZE,1);
fitne1=P01(:,2);
fitne2=P02(:,2);
fitne=[fitne1,fitne2];
fma1=max(fitne1);
fma2=max(fitne2);
in1=find(fma1==fitne1);
in2=find(fma2==fitne2);
best{t,1}=[P01(in1(1,1),:),x2(1,1);P02(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=strfind(fitne1',fma1);
BINDEX2=strfind(fitne2',fma2);
WINDEX1=strfind(fitne1',fmi1);
WINDEX2=strfind(fitne2',fmi2);
Bestinl=P01(BINDEX1(1,1),:);
Bestin2=P02(BINDEX2(1,1),:);
if Bestinl(:,2)>CURRENTBEST1{t-1, 1}(:,2)
CURRENTBEST1{t,1}=Bestinl;
else P01(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 P02(WINDEX2(1, 1),:)=CURRENTBEST2{t-1,1};
CURRENTBEST2{t,1}=CURRENTBEST2{t-1,1};
end
end
[P013, x2]=gafit(P013,P023,POPSIZE,1);
P1=P013;
[P023, x1]=gafit(P023,P013,POPSIZE,1);
PO2=P023;
best
for i=1:T
a(:,:,i)=best{i,1};
end
阿里matlab建模师
- 粉丝: 3642
- 资源: 2807
最新资源
- 基于javaweb的网上拍卖系统,采用Spring + SpringMvc+Mysql + Hibernate+ JSP技术
- polygon-mumbai
- Chrome代理 switchyOmega
- GVC-全球价值链参与地位指数,基于ICIO表,(Wang等 2017a)计算方法
- 易语言ADS指纹浏览器管理工具
- 易语言奇易模块5.3.6
- cad定制家具平面图工具-(FG)门板覆盖柜体
- asp.net 原生js代码及HTML实现多文件分片上传功能(自定义上传文件大小、文件上传类型)
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论18