decode.c
来自「nsga2具体算法代码,用来多目标遗传算法的学习和研究」· C语言 代码 · 共 46 行
C
46 行
/* Routines to decode the population */# include <stdio.h># include <stdlib.h># include <math.h># include "global.h"# include "rand.h"/* Function to decode a population to find out the binary variable values based on its bit pattern */void decode_pop (population *pop){ int i; if (nbin!=0) { for (i=0; i<popsize; i++) { decode_ind (&(pop->ind[i])); } } return;}/* Function to decode an individual to find out the binary variable values based on its bit pattern */void decode_ind (individual *ind){ int j, k; int sum; if (nbin!=0) { for (j=0; j<nbin; j++) { sum=0; for (k=0; k<nbits[j]; k++) { if (ind->gene[j][k]==1) { sum += pow(2,nbits[j]-1-k); } } ind->xbin[j] = min_binvar[j] + (double)sum*(max_binvar[j] - min_binvar[j])/(double)(pow(2,nbits[j])-1); } } return;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?