遗传算法Matlab源代码.docx

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
function[X,MaxFval,BestPop,Trace]=fga(FUN,bounds,MaxEranum,PopSize,options,pCross,pMutation,pInversion)%[X,MaxFval,BestPop,Trace]=fga(FUN,bounds,MaxEranum,PopSize,options,pCross,pMutation,pInversion)%fgasolvesproblemsoftheform:%%%% %fgasolvesproblemsoftheform: % % % % % % % % % % % % % maxF(X)XMaxFvalBestPopTraceFUNboundsMaxEranumPopSizepCrosspMutationpInversionoptionssubjectto:LB maxF(X)XMaxFvalBestPopTraceFUNboundsMaxEranumPopSizepCrosspMutationpInversionoptions -目标函数-自变量范围-种群的代数,取50--500(默认200)-每一代种群的规模;此可取50--200(默认100)-交叉概率,一般取0.5--0.85之间较好(默认0.8)-初始变异概率,一般取0.05-0.2之间较好(默认0.1)倒位概率,一般取0.05-0.3之间较好(默认0.2)-1*2矩阵,options(1)=0二进制编码(默认0),option(1)?=0十进制编码,option(2)设定求解精度(默认1e-4)T1=clock;%检验初始参数ifnargin2,error(FMAXGArequiresatleastthreeinputarguments);endifnargin==2,MaxEranum=150;PopSize=100;options=[11e-4];pCross=0.85;pMutation=0.1;pInversion=0.25;endifnargin==3,PopSize=100;options=[11e-4];pCross=0.85;pMutation=0.1;pInversion=0.25;endifnargin==4,options=[11e-4];pCross=0.85;pMutation=0.1;pInversion=0.25;endifnargin==5,pCross=0.85;pMutation=0.1;pInversion=0.25;endifnargin==6,pMutation=0.1;pInversion=0.25;endifnargin==7,pInversion=0.25;endif(options(1)==0loptions(1)==1)find((bounds(:,1)-bounds(:,2))0) error(数据输入错误,请重新输入:);end%定义全局变量globalmnNewPopchildren1children2VarNum%初始化种群和变量precision=options(2);bits=ceil(log2((bounds(:,2)-bounds(:,1))./precision));%由设定精度划分区间VarNum=size(bounds,1);[Pop]=InitPop(PopSize,bounds,bits,options);%初始化种群[m,n]=size(Pop);fit=zeros(1,m);NewPop=zeros(m,n);children1=zeros(1,n);children2=zeros(1,n);pm0=pMutation;BestPop=zeros(MaxEranum,n);%分配初始解空间BestPop,TraceTrace=zeros(1,MaxEranum); LbUb=ones(PopSize,1)*bounds(:,1);=ones(PopSize,1)*bounds(:,2);%二进制编码采用多点交叉和均匀交叉,并逐步增大均匀交叉概率%浮点编码采用离散交叉(前期)、算术交叉(中期)、AEA重组(后期)OptsCrossOver= LbUb round(unidrnd(2*(MaxEranum-[1:MaxEranum]))/MaxEranum)];%浮点编码时采用两种自适应变异和一种随机变异(自适应变异发生概率为随机变异发生的2倍)OptsMutation=[ones(1,MaxEranum)*options(1);unidrnd(5,1,MaxEranum)];ifoptions(1)==3 D=zeros(n); CityPosition=bounds; D=sqrt((Cit

文档评论(0)

dajiefude2 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档