MATLAB遗传算法程序

MATLAB遗传算法程序

ID:37864224

大小:41.00 KB

页数:5页

时间:2019-06-01

MATLAB遗传算法程序_第1页
MATLAB遗传算法程序_第2页
MATLAB遗传算法程序_第3页
MATLAB遗传算法程序_第4页
MATLAB遗传算法程序_第5页
资源描述:

《MATLAB遗传算法程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、function[bestsole,bestpop]=ga_scomplex(num,bounds,ps,pc,pm,b,dtc)%GA_scomple是基于浮点编码的单纯形遗传算法主程序%num定义种群数量% bounds定义参数取值范围,格式为[Var1min,Var1max;Var2min,Var2max;…….];%ps选择概率%pc交叉概率%pm变异概率%b 变异程度系数%dtc 迭代次数%$Date:2005/5/25$%%email:damao_pq@yahoo.com.cnnumvars=siz

2、e(bounds,1);xzomelength=numvars+1;flag=1;n=1;[pop]=initializega(num,bounds);while(n<=dtc&flag>0.00001)[newpop]=select(pop,ps);[crosspop]=crossover(bounds,newpop,pc);[mupop]=mutation(crosspop,bounds,pm,[b,n,dtc]);spop=[newpop;crosspop;mupop];[y,x]=sort(spop(:

3、,xzomelength));spop=spop(x,:);n_spop=size(spop,1);bestpop=spop(n_spop:-1:n_spop-num+1,:);[scopop]=scomplex(bounds,bestpop(1,1:numvars),100);% 加入单纯形算法bestpop(num,:)=scopop;bestpop(num,xzomelength)=-scopop(xzomelength);trace1(n)=mean(bestpop(:,xzomelength));be

4、stsole=bestpop(1,1:numvars);trace2(n)=bestpop(1,xzomelength);flag=abs(trace2(n)-trace1(n));bmax=max(bestpop(:,1:numvars));bmin=min(bestpop(:,1:numvars));bounds=[bmin',bmax'];pop=bestpop;n=n+1;endt=1:n-1;plot(t,trace1,'r-',t,trace2,'g-');legend('均值','最优解');to

5、c%%初始种群值生成子程序%%%%%%%%%%%%%%%%%%%%%%%%%function[pop]=initializega(num,bounds)numvars=size(bounds,1);rng=(bounds(:,2)-bounds(:,1))';xzomelength=numvars+1;pop=zeros(num,xzomelength);pop(:,1:numvars)=(ones(num,1)*rng).*(rand(num,numvars))+(ones(num,1)*bounds(:,1

6、)');pop(:,xzomelength)=fitness(pop(:,1:numvars));%%选择子程序%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5function[newpop]=select(oldpop,options)q=options;e=size(oldpop,2);n=size(oldpop,1);fit=zeros(n,1);x=zeros(n,2);x(:,1)=[n:-1:1]';[y,x(:,2)]=sort(oldpop(:,e));r=q/(1-(1-q)

7、.^n);fit(x(:,2))=r*(1-q).^(x(:,1)-1);fit=cumsum(fit);rnums=sort(rand(n,1));fitin=1;newin=1;whilenewin<=nif(rnums(newin)

8、crossover(bounds,newpop,ops)pc=ops;sn=size(newpop,1);sz=size(newpop,2)-1;nc=pc*sn*sz;cs=1;whilecs<=ncnsite=round(rand(2,1).*sn+0.5);zsite=round(rand*sz+0.5);r=rand;newpop(nsite,zsite)=[r,1-r;1-r

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。