资源描述:
《解tsp问题的遗传算法c语言程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、解TSP问题的遗传算法C语言程序#include#include#include#include#include#include#include#include#include#definemaxpop100#definemaxstring100structpp{unsignedcharchrom[maxstring]; floatx,fitness; unsignedintparent1,paren
2、t2,xsite; };structpp*oldpop,*newpop,*p1;unsignedintpopsize,lchrom,gem,maxgen,co_min,jrand;unsignedintnmutation,ncross,jcross,maxpp,minpp,maxxy;floatpcross,pmutation,sumfitness,avg,max,min,seed,maxold,oldrand[maxstring];unsignedcharx[maxstring],y[maxstring];float*dd,ff,maxdd,refpd,fm[2
3、01];FILE*fp,*fp1;floatobjfunc(float);voidstatistics();intselect();intflip(float);intcrossover();voidgeneration();voidinitialize();voidreport();floatdecode();voidcrtinit();voidinversion();floatrandom1();voidrandomize1();main(){unsignedintgen,k,j,tt;charfname[10];floatttt;clrscr();co_min
4、=0;if((oldpop=(structpp*)farmalloc(maxpop*sizeof(structpp)))==NULL){printf("memoryrequstfail!");exit(0);}if((dd=(float*)farmalloc(maxstring*maxstring*sizeof(float)))==NULL){printf("memoryrequstfail!");exit(0);}if((newpop=(structpp*)farmalloc(maxpop*sizeof(structpp)))==NULL){printf(
5、"memoryrequstfail!");exit(0);}if((p1=(structpp*)farmalloc(sizeof(structpp)))==NULL){printf("memoryrequstfail!");exit(0);}for(k=0;k