📄 cacs4fun.h
字号:
////////////////////////////////////////////////////////////////////////
// Class Name: Ant Colony System for Function Optimization //
// Version: 0.11 //
// Author: Chen Ye (Sichuan University) //
// E-mail: arrowcy@163.com, chenye84@gmail.com //
// Blog: http://www.mscenter.edu.cn/blog/chenye //
// Date: 2006-07-01 //
////////////////////////////////////////////////////////////////////////
class CAcs4Fun
{
public:
float alpha;// 即a,是求选择下一个城市概率的参数。
float rho; //挥发系数
float p0; //
//float tau_min, tau_max;
float tau0; //信息素浓度初值
int dimension; //空间的维数
int *gbant; //global best ant,全局最优蚂蚁
float gbfit; //global best fit,全局最佳适应度
float gby; //global best y,全局最佳y值
float *gbx; //global best x,全局最优x值
int num_layers; //number of layers,层数
int num_ants; //number of ants,蚂蚁数
int num_iters; //maximum number of iterations,迭代次数的最大值
protected:
float ***tau; //信息素浓度
int **ant; //蚂蚁数
float *fit; //适应度值
float *y; //y值
float **x; //x[i][j] stands for the j-th dimension of the variant decoded from the i-th ant,第i只蚂蚁的第j维解码
int *ibant; //iteration best ant,最优蚂蚁的迭代
int ibant_no; //NO. of iteration best ant,最优蚂蚁的迭代次数
float ibfit; //iteration best fit,最佳适应度的迭代
float iby; //iteration best y,y的迭代
int cur_iter; //current iteration,当前的迭代
//int *startpos; //start position of ...,初始位置
bool need_release; //memory has been allocated,内存的分配
int layers_per_dimension; //number of layers to represent one dimension of the variants
//assume to represent each dimension in the same accuracy
public:
void allocate_vars(); //allocate memory for variables,为变量分配内存
void release_vars(); //release memory allocated for variables,释放内存
void start(); //初始化
void init_vars(); //initialize variables used in searching process,用于搜寻过程中的初始化变量
void ant_move(int ant_no, int layer);//蚂蚁的移动
//the ant_no-th ant chooses an node in the layer-th layer
void local_update(int ant_no, int layer);//局部优化
//the arguments are similar to function ant_move
void get_best_ant(); //find out the best ant of current iteration and update the global best ant
void global_update();//全局优化
virtual void evaluate();
virtual void decode();//解码
CAcs4Fun();
~CAcs4Fun(); //call release_vars
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -