基于基本遗传算法的函数最优化 ok

基于基本遗传算法的函数最优化 ok

ID:18276493

大小:66.00 KB

页数:24页

时间:2018-09-16

基于基本遗传算法的函数最优化 ok_第1页
基于基本遗传算法的函数最优化 ok_第2页
基于基本遗传算法的函数最优化 ok_第3页
基于基本遗传算法的函数最优化 ok_第4页
基于基本遗传算法的函数最优化 ok_第5页
资源描述:

《基于基本遗传算法的函数最优化 ok》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、基于基本遗传算法的函数最优化ok/******************************************************************//*基于基本遗传算法的函数最优化SGA.C*//*AFunctionOptimizerusingSimpleGeneticAlgorithm*//*developedfromthePascalSGAcodepresentedbyDavidE.Goldberg*//*同济大学计算机系王小平2000年5月*//**************************************************

2、****************/#include#include#include#include/*全局变量*/structindividual/*个体*/{unsigned*chrom;/*染色体*/doublefitness;/*个体适应度*/doublevarible;/*个体对应的变量值*/intxsite;/*交叉位置*/intparent[2];/*父个体*/int*utility;/*特定数据指针变量*/};structbestever/*最佳个体*/{unsigned*chrom

3、;/*最佳个体染色体*/doublefitness;/*最佳个体适应度*/doublevarible;/*最佳个体对应的变量值*/intgeneration;/*最佳个体生成代*/};structindividual*oldpop;/*当前代种群*/structindividual*newpop;/*新一代种群*/structbesteverbestfit;/*最佳个体*/doublesumfitness;/*种群中个体适应度累计*/doublemax;/*种群中个体最大适应度*/doubleavg;/*种群中个体平均适应度*/doublemin;/*种群中个体最小适应

4、度*/floatpcross;/*交叉概率*/floatpmutation;/*变异概率*/intpopsize;/*种群大小*/intlchrom;/*染色体长度*/intchromsize;/*存储一染色体所需字节数*/intgen;/*当前世代数*/intmaxgen;/*最大世代数*/intrun;/*当前运行次数*/intmaxruns;/*总运行次数*/intprintstrings;/*输出染色体编码的判断,0--不输出,1--输出*/intnmutation;/*当前代变异发生次数*/intncross;/*当前代交叉发生次数*//*随机数发生器使用的静

5、态变量*/staticdoubleoldrand[55];staticintjrand;staticdoublerndx2;staticintrndcalcflag;/*输出文件指针*/FILE*outfp;/*函数定义*/voidadvance_random();intflip(float);rnd(int,int);voidrandomize();doublerandomnormaldeviate();floatrandomperc(),rndreal(float,float);voidwarmup_random(float);voidinitialize(),in

6、itdata(),initpop();voidinitreport(),generation(),initmalloc();voidfreeall(),nomemory(char*),report();voidwritepop(FILE*),writechrom(unsigned*);voidpreselect();voidstatistics(structindividual*);voidrepchar(FILE*,char*,int);//titlemissposvoidskip(FILE*,int);intselect();voidobjfunc(structin

7、dividual*);intcrossover(unsigned*,unsigned*,unsigned*,unsigned*);voidmutation(unsigned*);voidinitialize()/*遗传算法初始化*/{/*键盘输入遗传算法参数*/initdata();/*确定染色体的字节长度*/chromsize=(lchrom/(8*sizeof(unsigned)));if(lchrom%(8*sizeof(unsigned)))chromsize++;/*分配给全局数据结构空间*/initmalloc();/*初始化

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

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

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