ga_work.h

来自「基本遗传算法 基本遗传算法」· C头文件 代码 · 共 71 行

H
71
字号
#include "stdio.h"
#include "iostream.h"

#define POP              50             //population
#define COV_PRECISE      10000
#define PARA_MIN         -10            //the min. value of variables
#define PARA_MAX         10             //the max. value of variables
#define PARA_MIN_MUL     PARA_MIN*COV_PRECISE            //the min. value of variables after multiply
#define PARA_MAX_MUL     PARA_MAX*COV_PRECISE             //the max. value of variables after multiply
#define M                18             //parameter determined by the precision
#define GENE_NO          M*2            //gene number of individual chromosome

int CRO_POP;                            //population for crossover 
#define CRO_GENE_NO      GENE_NO/2      //gene number for crossover

int MUT_POP;                            //population for mutation
#define MUT_GENE_NO      4              //gene number for mutation

//int C_G;                                //current generation
#define GENERATION       100

//individual class
class individual
{
public:
	double x,y;         
	int gene[GENE_NO];     //genotype
	double fitness;
//	double fitness_2;    //object value
	int Rep_No;                         //replication number
//	double Obj_value;                   //fitness value
};

//1.functions of the GA procedures
extern void Pop_Init();        //2.1.population initial
//extern double (*Fit_fun)(double x,double y);
extern void Fit_fun_1(individual &a);
extern void Fit_fun_2(double x,double y);	
extern void Fitness_Comp(individual &a);  //2.2.fitness value computation
extern void Selection();
extern void Replication();     //2.3.selection and replication
extern void Crossover();       //2.4.crossover
extern void Mutation();        //2.5.mutation
                                                                                                                                                                                                                                                                                                           

//3.assistant functions
extern char Dec2Bin(double &a,double &b);
extern char Dec2Bin(double x);
extern void Bin2Dec(double x);





















⌨️ 快捷键说明

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