遗传算法c程序.doc

遗传算法c程序.doc

ID:56265753

大小:54.50 KB

页数:15页

时间:2020-06-04

遗传算法c程序.doc_第1页
遗传算法c程序.doc_第2页
遗传算法c程序.doc_第3页
遗传算法c程序.doc_第4页
遗传算法c程序.doc_第5页
资源描述:

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

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

2、ess;/*最佳个体适应度*/doublevarible;/*最佳个体对应的变量值*/intgeneration;/*最佳个体生成代*/};structindividual*oldpop;/*当前代种群*/structindividual*newpop;/*新一代种群*/structbesteverbestfit;/*最佳个体*/doublesumfitness;/*种群中个体适应度累计*/doublemax;/*种群中个体最大适应度*/doubleavg;/*种群中个体平均适应度*/doublemin;/*种群中个体最小适应度*/floatpcross;/*交叉概率*/floa

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

4、ticintjrand;staticdoublerndx2;staticintrndcalcflag;/*输出文件指针*/FILE*outfp;/*函数定义*/voidadvance_random();intflip(float);rnd(int,int);voidrandomize();doublerandomnormaldeviate();floatrandomperc(),rndreal(float,float);voidwarmup_random(float);voidinitialize(),initdata(),initpop();voidinitreport(),g

5、eneration(),initmalloc();voidfreeall(),nomemory(char*),report();voidwritepop(),writechrom(unsigned*);voidpreselect();voidstatistics(structindividual*);voidtitle(),repchar(FILE*,char*,int);voidskip(FILE*,int);intselect();voidobjfunc(structindividual*);intcrossover(unsigned*,unsigned*,unsigned*

6、,unsigned*);voidmutation(unsigned*);voidinitialize()/*遗传算法初始化*/{/*键盘输入遗传算法参数*/initdata();/*确定染色体的字节长度*/chromsize=(lchrom/(8*sizeof(unsigned)));if(lchrom%(8*sizeof(unsigned)))chromsize++;/*分配给全局数据结构空间*/initmalloc();/*初始化随机数发生器*/randomize();/*初始化全局计数变量和一些数值*/nmutation=0;ncross=0;bestfit.fitness

7、=0.0;bestfit.generation=0;/*初始化种群,并统计计算结果*/initpop();statistics(oldpop);initreport();}voidinitdata()/*遗传算法参数输入*/{charanswer[2];setcolor(9);disp_hz16("种群大小(20-100):",100,150,20);gscanf(320,150,9,15,4,"%d",&popsize);if((popsize%2)!=0){fprintf(o

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

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

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