200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 求解tsp的c语言程序 解TSP问题的遗传算法C语言程序.doc

求解tsp的c语言程序 解TSP问题的遗传算法C语言程序.doc

时间:2022-08-17 10:25:29

相关推荐

求解tsp的c语言程序 解TSP问题的遗传算法C语言程序.doc

解TSP问题的遗传算法C语言程序

#include#include#include#include#include#include#include#include#include#define maxpop 100#define maxstring 100struct pp{unsigned char chrom[maxstring];? ?float x,fitness;? ?unsigned int parent1,parent2,xsite;? ?};struct pp *oldpop,*newpop,*p1;unsigned int popsize,lchrom,gem,maxgen,co_min,jrand;unsigned int nmutation,ncross,jcross,maxpp,minpp,maxxy;float pcross,pmutation,sumfitness,avg,max,min,seed,maxold,oldrand[maxstring];unsigned char x[maxstring],y[maxstring];float *dd,ff,maxdd,refpd,fm[201];FILE *fp,*fp1;float objfunc(float);void statistics();int select();int flip(float);int crossover();void generation();void initialize();void report();float decode();void crtinit();void inversion();float random1();void randomize1();main(){unsigned int gen,k,j,tt;char fname[10];float ttt;clrscr();co_min=0;if((oldpop=(struct pp *)farmalloc(maxpop*sizeof(struct pp)))==NULL){printf("memory requst fail!\n");exit(0);}if((dd=(float *)farmalloc(maxstring*maxstring*sizeof(float)))==NULL){printf("memory requst fail!\n");exit(0);}if((newpop=(struct pp *)farmalloc(maxpop*sizeof(struct pp)))==NULL){printf("memory requst fail!\n");exit(0);}if((p1=(struct pp *)farmalloc(sizeof(struct pp)))==NULL){printf("memory requst fail!\n");exit(0);}for(k=0;k

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。