📄 statistic.c
字号:
//适应度统计
/*----------------------------------------------------------------------------*/
/* statistic.c - compute the fitness statistics */
/*----------------------------------------------------------------------------*/
#include "external.h"
statistics(pop) /* Calculate population statistics */
struct individual *pop;
{
int i, j;
sumfitness = 0.0;
min = pop[0].fitness;
max = pop[0].fitness;
/* Loop for max, min, sumfitness */
for(j = 0; j < popsize; j++)
{
sumfitness = sumfitness + pop[j].fitness; /* Accumulate */
if(pop[j].fitness > max) max = pop[j].fitness; /* New maximum */
if(pop[j].fitness < min) min = pop[j].fitness; /* New minimum */
/* new global best-fit individual */
if(pop[j].fitness > bestfit.fitness)
{
for(i = 0; i < chromsize; i++)
bestfit.chrom[i] = pop[j].chrom[i];
bestfit.fitness = pop[j].fitness;
bestfit.generation = gen;
}
}
/* Calculate average */
avg = sumfitness/popsize;
/* get application dependent stats */
app_stats(pop);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -