📄 decode.c
字号:
/* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -