%主程序 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建模师
- 粉丝: 5003
- 资源: 2908
最新资源
- 计算机行业2025年1月投资策略:国产deepseek 豆包发力,海内外大模型刺激推理算力.pdf
- 计算机行业2025年1月投资策略:国产deepseek 豆包发力,海内外大模型刺激推理算力.pdf
- 家用电器-25W5周观点:春节消费专题:可选消费表现靓丽,关注对美关税变动与DeepSeek.pdf
- 家用电器-25W5周观点:春节消费专题:可选消费表现靓丽,关注对美关税变动与DeepSeek.pdf
- 家用电器-25W5周观点:春节消费专题:可选消费表现靓丽,关注对美关税变动与DeepSeek.pdf
- 科技行业:DeepSeek之AI大模型解读:模型成本大幅下降,国产化全方位加速.pdf
- 全球产业趋势跟踪:DeepSeek推出开源第二代MoE模型-招商证券.pdf
- 全球大类资产观察:DeepSeek的扰动与关税再敲门.pdf
- 人工智能动态跟踪:计算机行业:DeepSeek提振国产大模型信心,有望促进AI行业发展.pdf
- 人工智能-DeepSeek领衔,国产大模型竞争力加速迭代.pdf
- 通信-行业周报:DeepSeek-V3推进技术突破与创新,降低模型开发门槛-AI行业跟踪45期.pdf
- DeepSeek-AI指令合集大全,从AI创作到内容分析,一手掌握 副业!
- 信息技术-计算机行业:比较试用DeepSeek看模型走向应用的新迹象-广发证券.pdf
- 信息技术-计算机行业AI 点评系列报告(二十五):Deepseek持续迭代,中美大模型竞争升级-华创证券.pdf
- 信息技术-通信行业:DeepSeek模型引动巨震,有望加速完善产业生态-华西证券.pdf
- ACM竞赛备赛指南:从基础知识到实战经验的全方位解析与应对策略
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论18