资源描述:
《15316188xiaoshengjinyichuansuanfa小生境遗传算法源程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、http://www.pudn.com/downloads73/sourcecode/math/detail11491.html/************************************************************//*遗传优化神经网络结构GA_NN.C*//*同济大学计算机系王小平2000年5月*//************************************************************/#include#include#include<
2、graphics.h>#include#include#include#include"graph.c"#include"operator.c"/*宏定义*/#definePOP_SIZE20#defineS_RATE0.4#defineM_RATE0.01#defineI_MAX5#defineH_MAX20#defineO_MAX5#defineP_MAX100#defineMAX_G_LENGTH100#defineGX1360#defineGY166#defineGX2360#defi
3、neGY2257#defineGXR250#defineGYR100#defineGSTEP2/*全局变量*/unsignedchargene[POP_SIZE][MAX_G_LENGTH];/*个体遗传基因*/unsignedchari_unit[I_MAX],h_unit[H_MAX],o_unit[O_MAX];unsignedcharp_i_unit[P_MAX][I_MAX];unsignedcharp_o_unit[P_MAX][O_MAX];doublefitness[POP_SIZE];doublemax_fit,avg_fit
4、;inti_num,h_num,o_num,t_num;intp_num;intg_length;longintcalc_g_length(){inti;longintnum;num=0;for(i=1;i<=h_num;i++)num=num+i_num+(i-1);num=num+o_num*(i_num+h_num);return(num);}voidset_network(){inti,ok;longintwork;charchoice[2];settextstyle(0,0,4);gprintf(215,15,4,0,"GA-NN")
5、;setcolor(9);disp_hz24("遗传优化神经网络结构",170,50,25);disp_hz16("同济大学计算机系王小平",150,100,20);disp_hz16("=========确定网络结点数==========",10,150,20);ok=1;while(ok==1){setcolor(9);disp_hz16("输入结点数:",10,180,20);gscanf(300,180,9,15,3,">s",choice);i_num=atoi(choice);setcolor(9);disp_hz16("隐结点数:
6、",10,210,20);gscanf(300,210,15,15,3,">s",choice);h_num=atoi(choice);setcolor(9);disp_hz16("输出结点数:",10,240,20);gscanf(300,240,15,0,4,">s",choice);o_num=atoi(choice);t_num=i_num+h_num+o_num;work=calc_g_length();if(work>MAX_G_LENGTH)disp_hz16("结点数太多,请重输入。",10,250,20);else{g_len
7、gth=(int)work;setcolor(9);disp_hz16("ok?1:no,2:yes",10,270,20);gscanf(300,270,4,0,4,">s",choice);ok=atoi(choice);}}}voidset_problem(){inti,j;FILE*fopen(),*fpt;if((fpt=fopen("\ga\sample","r"))==NULL)exit(-1);else{fscanf(fpt,">d",&amt;p_num);for(i=1;i<=p_num;i++){for(j=1;j<=
8、i_num;j++)fscanf(fpt,">d",&amt;p_i_unit[i-1][j-1]);for(j=1;j<=o_num;j++)fsc