⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.h

📁 C语言编写的遗传算法NSGA2,可以直接套用函数运算
💻 H
字号:
/*This is the file which initializes the population*/
void init(population *pop_ptr);

void init(population *pop_ptr)
{
int i,j,r;
float d;
pop_ptr->ind_ptr = &(pop_ptr->ind[0]);

/*Loop Over the population size*/
for (i = 0 ; i < popsize ; i++)
{

/*Loop over the chromosome length*/
for (j = 0;j < chrom;j++)
{
/*Generate a Random No. if it is less than 0.5 it
generates a 0 in the string otherwise 1*/
d = randomperc();
if(d >= 0.5)
{
pop_ptr->ind_ptr->genes[j] = 1;
}
else
{
pop_ptr->ind_ptr->genes[j] = 0;
}
}
pop_ptr->ind_ptr = &(pop_ptr->ind[i+1]);
}
pop_ptr->ind_ptr = &(pop_ptr->ind[0]);
return;
}


















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -