电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

一个简单实用的遗传算法c程序VIP免费

一个简单实用的遗传算法c程序_第1页
1/18
一个简单实用的遗传算法c程序_第2页
2/18
一个简单实用的遗传算法c程序_第3页
3/18
一个简单实用的遗传算法c程序(转载)c++2009-07-2823:09:03阅读418评论0字号:大中小这是一个非常简单的遗传算法源代码,是由DenisCormier(NorthCarolinaStateUniversity)开发的,SitaS.Raghavan(UniversityofNorthCarolinaatCharlotte)修正。代码保证尽可能少,实际上也不必查错。对一特定的应用修正此代码,用户只需改变常数的定义并且定义“评价函数”即可。注意代码的设计是求最大值,其中的目标函数只能取正值;且函数值和个体的适应值之间没有区别。该系统使用比率选择、精华模型、单点杂交和均匀变异。如果用Gaussian变异替换均匀变异,可能得到更好的效果。代码没有任何图形,甚至也没有屏幕输出,主要是保证在平台之间的高可移植性。读者可以从ftp.uncc.edu,目录coe/evol中的文件prog.c中获得。要求输入的文件应该命名为‘gadata.txt’;系统产生的输出文件为‘galog.txt’。输入的文件由几行组成:数目对应于变量数。且每一行提供次序——对应于变量的上下界。如第一行为第一个变量提供上下界,第二行为第二个变量提供上下界,等等。/**************************************************************************//*Thisisasimplegeneticalgorithmimplementationwherethe*//*evaluationfunctiontakespositivevaluesonlyandthe*//*fitnessofanindividualisthesameasthevalueofthe*//*objectivefunction*//**************************************************************************/#include#include#include/*Changeanyoftheseparameterstomatchyourneeds*/#definePOPSIZE50/*populationsize*/#defineMAXGENS1000/*max.numberofgenerations*/#defineNVARS3/*no.ofproblemvariables*/#definePXOVER0.8/*probabilityofcrossover*/#definePMUTATION0.15/*probabilityofmutation*/#defineTRUE1#defineFALSE0intgeneration;/*currentgenerationno.*/intcur_best;/*bestindividual*/FILE*galog;/*anoutputfile*/structgenotype/*genotype(GT),amemberofthepopulation*/{doublegene[NVARS];/*astringofvariables一个变量字符串*/doublefitness;/*GT'sfitness适应度*/doubleupper[NVARS];/*GT'svariablesupperbound变量的上限*/doublelower[NVARS];/*GT'svariableslowerbound变量的下限*/doublerfitness;/*relativefitness相对适应度*/doublecfitness;/*cumulativefitness累计适应度*/};structgenotypepopulation[POPSIZE+1];/*population*/structgenotypenewpopulation[POPSIZE+1];/*newpopulation;*//*replacesthe*//*oldgeneration*//*Declarationofproceduresusedbythisgeneticalgorithm*/voidinitialize(void);doublerandval(double,double);voidevaluate(void);voidkeep_the_best(void);voidelitist(void);voidselect(void);voidcrossover(void);voidXover(int,int);voidswap(double*,double*);voidmutate(void);voidreport(void);/***************************************************************//*Initializationfunction:Initializesthevaluesofgenes*//*withinthevariablesbounds.Italsoinitializes(tozero)*//*allfitnessvaluesforeachmemberofthepopulation.It*//*readsupperandlowerboundsofeachvariablefromthe*//*inputfile`gadata.txt'.Itrandomlygeneratesvalues*//*betweentheseboundsforeachgeneofeachgenotypeinthe*//*population.Theformatoftheinputfile`gadata.txt'is*//*var1_lower_boundvar1_upperbound*//*var2_lower_boundvar2_upperbound...*//***************************************************************/voidinitialize(void){FILE*infile;inti,j;doublelbound,ubound;if((infile=fopen("gadata.txt","r"))==NULL){fprintf(galog,"\nCannotopeninputfile!\n");exit(1);}/*initializevariableswithinthebounds*/for(i=0;i

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

一个简单实用的遗传算法c程序

一米阳光+ 关注
实名认证
内容提供者

爱好英语教学和互联网行业,热爱教育事业,兢兢业业

相关文档

确认删除?
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群