📄 gp.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 + -