C遗传算法struct individual{unsigned char *chrom;double fitness;double varible;int xsite;int parent[2];int *utility;};struct individual *oldpop;struct individual *newpop;void initmalloc(){unsigned char nbytes;int j;nbytes=popsize*sizeof(struct ind

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/21 00:29:31
C遗传算法struct individual{unsigned char *chrom;double fitness;double varible;int xsite;int parent[2];int *utility;};struct individual *oldpop;struct individual *newpop;void initmalloc(){unsigned char nbytes;int j;nbytes=popsize*sizeof(struct ind
xVmOV+W:9n@Uդ:Mk$7pcGUH%&- kKjB0SŽ}J:r|=9y}O:c׻kѺg!%L$gqE'} PPFa5+c!uLH Q T'IV¤rzi}#vg4t-M]7!_ӭtk Yux5 I6ͮo$\tv9ТQu9 $ EV_C^_)1ȽakATz3!A*ūऒ0 I KZ=TL0R^8o ᚁ9N$e`'7c~P7>'27~uNOkMvqT]W!7ZRk8e00Ҥ4tce^xHdlҁw0Ao[T4")ƽXD•\E|zp=?z

C遗传算法struct individual{unsigned char *chrom;double fitness;double varible;int xsite;int parent[2];int *utility;};struct individual *oldpop;struct individual *newpop;void initmalloc(){unsigned char nbytes;int j;nbytes=popsize*sizeof(struct ind
C遗传算法
struct individual
{
unsigned char *chrom;
double fitness;
double varible;
int xsite;
int parent[2];
int *utility;
};
struct individual *oldpop;
struct individual *newpop;
void initmalloc()
{
unsigned char nbytes;
int j;
nbytes=popsize*sizeof(struct individual);
if((oldpop=(struct individual*)malloc(nbytes))==NULL)
nomemory("oldpop");
if((newpop=(struct individual*)malloc(nbytes))==NULL)
nomemory("newpop");
nbytes=chromsize*sizeof(unsigned char);
for(j=0;j

C遗传算法struct individual{unsigned char *chrom;double fitness;double varible;int xsite;int parent[2];int *utility;};struct individual *oldpop;struct individual *newpop;void initmalloc(){unsigned char nbytes;int j;nbytes=popsize*sizeof(struct ind
一个非常简单的遗传算法源代码,是由Denis Cormier (North Carolina State University)开发的,Sita S.Raghavan (University of North Carolina at Charlotte)修正.代码保证尽可能少,实际上也不必查错.对一特定的应用修正此代码,用户只需改变常数的定义并且定义“评价函数”即可.注意代码的设计是求最大值,其中的目标函数只能取正值;且函数值和个体的适应值之间没有区别.该系统使用比率选择、精华模型、单点杂交和均匀变异.如果用Gaussian变异替换均匀变异,可能得到更好的效果.代码没有任何图形,甚至也没有屏幕输出,主要是保证在平台之间的高可移植性.读者可以从ftp.uncc.edu,目录 coe/evol中的文件prog.c中获得.要求输入的文件应该命名为‘gadata.txt’;系统产生的输出文件为‘galog.txt’.输入的文件由几行组成:数目对应于变量数.且每一行提供次序——对应于变量的上下界.如第一行为第一个变量提供上下界,第二行为第二个变量提供上下界,等等.
//
.
代码太多 你到下面呢个网站看看吧
void main(void)
{
int i;
if ((galog = fopen("galog.txt","w"))==NULL)
{
exit(1);
}
generation = 0;
fprintf(galog,"\n generation best average standard \n");
fprintf(galog," number value fitness deviation \n");
initialize();
evaluate();
keep_the_best();
while(generation<MAXGENS)
{
generation++;
select();
crossover();
mutate();
report();
evaluate();
elitist();
}
fprintf(galog,"\n\n Simulation completed\n");
fprintf(galog,"\n Best member:\n");
for (i = 0; i < NVARS; i++)
{
fprintf (galog,"\n var(%d) = %3.3f",i,population[POPSIZE].gene[i]);
}
fprintf(galog,"\n\n Best fitness = %3.3f",population[POPSIZE].fitness);
fclose(galog);
printf("Success\n");
}
另外,虚机团上产品团购,超级便宜