📄 tspsga.h
字号:
#pragma once
#include <math.h>
#include <time.h>
double Crand(long seed);
typedef struct
{
double x;
double y;
}POINT, *PPOINT;
typedef struct
{
char *pChrom;
double fitness;
int xsite;
int parent[2];
}INDIVIDUAL, *PINDIVIDUAL;
typedef struct
{
char *pChrom;
double fitness;
int generation;
}BESTEVER, *PBESTEVER;
class CTSPSGA
{
private:
int m_PopSize; //种群大小
int m_Maxgen; //最大代数
int m_Tour;
double m_Pcross; //交叉率
double m_Pmutation; //变异率
int m_ChromLen; //染色体长度
POINT *m_pCtyPt; //城市坐标
FILE * m_File;
int m_CtyCnt;
int m_Gen; //当前代数
double m_SumFitness; //种群中个体适应度累计
double m_MinFitness; //种群中个体最小适应度
double m_MaxFitness; //种群中个体最大适应度
double m_AvgFitness; //种群中个体平均适应度
PINDIVIDUAL m_POldPop; //当前代种群
PINDIVIDUAL m_PNewPop; //新一代种群
BESTEVER m_BestFit;
public:
CTSPSGA(void);
~CTSPSGA(void);
void InitPop(void);
double ComputeFitness(PINDIVIDUAL pIndividual);
double GetAllDistance(char *Line);
double GetDistance(POINT pt1, POINT pt2);
int WheelSelect(void);
int TourSelect(void);
int CrossOver(const char *Parent1, const char *Parent2, char *Child1, char *Child2);
int Produce(const char *Parent, char *Child, int Pos1, int Pos2);
void Mutation(char* Child);
void Generation(void);
void PreSelect(void);
void Statistics(PINDIVIDUAL pIndividual);
virtual void Report(void);
void StartRun(void);
int SetPopSize(int Size);
int GetPopSize(void);
int SetChromLen(int ChromLen);
int GetChromLen(void);
int SetMaxgen(int Maxgen);
int GetMaxgen(void);
double SetPcross(double Pcross);
double GetPcross(void);
double SetPmutation(int Pmutation);
double GetPmutation(void);
int PrintPops(void);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -