首页 并行遗传算法

并行遗传算法

举报
开通vip

并行遗传算法//gafx.cpp:定义控制台应用程序的入口点。//本程序试用遗传算法来解决Rosenbrock函数的全局最大值计算问题://maxf(x1,x2)=100(x1^2-x2^2)^2+(1-x1)^2//定义域-2.048#include#include#include#includeusingnamespacestd;#defineT200//最大迭代次数#defineN30//种群大小#definePc0.6//交叉概率#definePm0.02//变异概率structpopulation{intx[20];...

并行遗传算法
//gafx.cpp:定义控制台应用程序的入口点。//本程序试用遗传算法来解决Rosenbrock函数的全局最大值计算问题://maxf(x1,x2)=100(x1^2-x2^2)^2+(1-x1)^2//定义域-2.048<=xi<=2.048///执行了串行GA与并行GA,并进行了比较#include"stdafx.h"#include"omp.h"#include#include#include#include#includeusingnamespacestd;#defineT200//最大迭代次数#defineN30//种群大小#definePc0.6//交叉概率#definePm0.02//变异概率structpopulation{intx[20];doublex1,x2;doublefit;doublecfit;}p[N],p_para[N],pbest,p_para_best;//pbest 记录 混凝土 养护记录下载土方回填监理旁站记录免费下载集备记录下载集备记录下载集备记录下载 具有最高适应值的个体voidinitial(population*p);voiddecode(population*p);voidevaluatefit(population*p);voidselect(population*p);voidcross(population*p);voidmutate(population*p);voidnextgeneration(population*p);voidprint(population*p,intt,intpattern);voidevaluatefit_para(population*p);voidmutate_para(population*p);voidnextgeneration_para(population*p);//--------------------------------------------------------------//--------------------------------------------------------------intrand01(){//随机产生或intr;doubleq;q=rand()/(RAND_MAX+0.0);if(q<0.5)r=0;elser=1;returnr;}doublerandxy(doublex,doubley){//生成(x,y)内一随机数doublec,r;c=y-x;r=x+c*rand()/(RAND_MAX+1.0);returnr;}intfind_the_best(population*p){//返回p中适应度最大的下标intmem,cur_best=0;for(mem=0;memp[cur_best].fit)cur_best=mem;returncur_best;}intfind_the_worst(population*p){//返回p中适应度最小的下标intmem,cur_worst=0;for(mem=0;mem=s){pt[i]=p[j];break;}elsecontinue;}i++;}for(i=0;ipbest.fit){for(inti=0;i<20;i++)pbest.x[i]=p[cur_best].x[i];pbest.fit=p[cur_best].fit;pbest.x1=p[cur_best].x1;pbest.x2=p[cur_best].x2;pbest.cfit=p[cur_best].cfit;}else{for(inti=0;i<20;i++)p[cur_worst].x[i]=pbest.x[i];p[cur_worst].fit=pbest.fit;p[cur_worst].x1=pbest.x1;p[cur_worst].x2=pbest.x2;p[cur_worst].cfit=pbest.cfit;}}voidnextgeneration_para(population*p){intcur_best=find_the_best(p);intcur_worst=find_the_worst(p);if(p[cur_best].fit>p_para_best.fit){for(inti=0;i<20;i++)p_para_best.x[i]=p[cur_best].x[i];p_para_best.fit=p[cur_best].fit;p_para_best.x1=p[cur_best].x1;p_para_best.x2=p[cur_best].x2;p_para_best.cfit=p[cur_best].cfit;}else{for(inti=0;i<20;i++)p[cur_worst].x[i]=p_para_best.x[i];p[cur_worst].fit=p_para_best.fit;p[cur_worst].x1=p_para_best.x1;p[cur_worst].x2=p_para_best.x2;p[cur_worst].cfit=p_para_best.cfit;}}//----------------------------------------------------------------//显示函数--------------------------------------------------------//pattern为代表串行,为代表并行voidprint(population*p,intt,intpattern){printf("-------------------------------------------------------\n");printf("第%d代\n",t);inti,j;for(i=0;i
本文档为【并行遗传算法】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
與因
暂无简介~
格式:pdf
大小:138KB
软件:PDF阅读器
页数:8
分类:
上传时间:2023-01-21
浏览量:0