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

📄 genetic.h

📁 遗传算法
💻 H
字号:
#include"stdafx.h"
#include <stdlib.h>

#define CHROMLENGTH 30  //每条染色体的基因段数
#define BITLENGTH 4   //位长度
#define BITMAX 4   //进制

typedef char ALLELE;// 基因类型
class CtrlPoint
{
public:
	char controlpoint[BITLENGTH];
	int codenumber;
};

class INDIVIDUAL
{
public:
	INDIVIDUAL()
	{ };
	~INDIVIDUAL()
	{ };

public:
    CtrlPoint chrom[CHROMLENGTH];
	//ALLELE *chrom;
	float fitness; // fitness of Chromosome
	float  expectation;//expected value
	float decimal_expectation;//期望值的小数
	 int int_expectation; //期望值的整数
}; // 个体定义

class  CStandardGA // 群体类定义
{
public:
	int populationsize; // Size of population: n
//	int CHROMLENGTH; // Length of chromosome: l
	float sumfitness, averagefitness;
	float sumdecimalexpectation;

	INDIVIDUAL fmin_individual, fmax_individual;
	INDIVIDUAL *pop, *newpop,*temppop;
	float pcross;  // Probability of Crossover
	float pmutation;  // Probability of Mutation
	int gen; // Counter of generation
public:
	void Create_newgeneration();// 产生新的一代
	void Initialize();
	void Decode();
	CStandardGA();
	~CStandardGA();

	void GetFitness(); // 评价函数
	void Statistics(); // 统计函数
	void Select();
	 void Crossover();

	void Mutation();
 
};	 




float Myrand();

⌨️ 快捷键说明

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