📄 generate.cpp
字号:
/*----------------------------------------------------------------------------*/
/* generate.c - create a new generation of individuals */
/*----------------------------------------------------------------------------*/
#include "generate.h"
//#include "sga.h"
#include "external.h"
#include "rselect.h"
#include "srselect.h"
#include "tselect.h"
#include "operators.h"
#include "app.h"
extern int popsize;
void generation()
{
int mate1, mate2, jcross, j = 0;
// printf("generation() ...... ");
/* perform any preselection actions necessary before generation */
t_preselect();
/* select, crossover, and mutation */
do
{
/* pick a pair of mates */
mate1 = t_select();
mate2 = t_select();
/* Crossover and mutation */
jcross = crossover(oldpop[mate1].chrom, oldpop[mate2].chrom,
newpop[j].chrom, newpop[j+1].chrom);
mutation(newpop[j].chrom);
mutation(newpop[j+1].chrom);
/* Decode string, evaluate fitness, & record */
/* parentage date on both children */
objfunc(&(newpop[j]),0); // !!!
newpop[j].parent[0] = mate1+1;
newpop[j].xsite = jcross;
newpop[j].parent[1] = mate2+1;
objfunc(&(newpop[j+1]),0);
newpop[j+1].parent[0] = mate1+1;
newpop[j+1].xsite = jcross;
newpop[j+1].parent[1] = mate2+1;
/* Increment population index */
j = j + 2;
// printf(" %d",j);
}while(j < (popsize-1));
// printf(" OK!\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -