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

📄 gp.h

📁 遗传算法求解TSP问题的源码.遗传代数和种群规模比较大,所以整个求解过程比较长
💻 H
字号:
#ifndef  LiuYongJin_XMU_CSD_2007_12_11_GP
#define	 LiuYongJin_XMU_CSD_2007_12_11_GP

#include "../Type.h"

typedef struct _individual
{
	double fitness;
	Path	path;
}Individual;


const int NGene=500;			//遗传代数
const int PEOPLE_SIZE=300;		//种群大小
const double P_CROSS = 0.8;		//交叉概率
const double P_MUTATION = 0.05;	//变异概率

class CGpTsp
{
public:
	CGpTsp(int nCitys, Position *position);
	~CGpTsp(void);

	void GetBestPath(Path *bestpath);

private:
	int	m_nCity;		//城市个数
	Position *m_xyPosition;	//每个城市的坐标

	Individual *m_Generation; //当前代
	
	void InitGene(Individual *ind);
	void InitCurGeneration();

	void Mutation(Individual *ind);				//变异
	void Copy(Individual * dst, Individual * src);			//复制

	void Turn(int *path, int index, int n);
	double Distance(int *path, int index1, int index2);
	int Find(int *path, int value, int n);
	void Crossover(Individual *ind1, Individual *ind2);		//交叉
	
	void Sort();
	int  Select();
	void Evaluate();
	void Reproduce();
};

#endif

⌨️ 快捷键说明

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