📄 unit1.h
字号:
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
/* 全局变量 */
struct individual /* 个体*/
{
unsigned *chrom; /* 染色体 */
double fitness; /* 个体适应度*/
double varible; /* 个体对应的变量值*/
int xsite; /* 交叉位置 */
int parent[2]; /* 父个体 */
int *utility; /* 特定数据指针变量 */
};
struct bestever /* 最佳个体*/
{
unsigned *chrom; /* 最佳个体染色体*/
double fitness; /* 最佳个体适应度 */
double varible; /* 最佳个体对应的变量值 */
int generation; /* 最佳个体生成代 */
};
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TListBox *ListBox1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
struct individual *oldpop; /* 当前代种群 */
struct individual *newpop; /* 新一代种群 */
struct bestever bestfit; /* 最佳个体 */
double sumfitness; /* 种群中个体适应度累计 */
double max; /* 种群中个体最大适应度 */
double avg; /* 种群中个体平均适应度 */
double min; /* 种群中个体最小适应度 */
float pcross; /* 交叉概率 */
float pmutation; /* 变异概率 */
int popsize; /* 种群大小 */
int lchrom; /* 染色体长度*/
int chromsize; /* 存储一染色体所需字节数 */
int gen; /* 当前世代数 */
int maxgen; /* 最大世代数 */
int run; /* 当前运行次数 */
int maxruns; /* 总运行次数 */
int printstrings; /* 输出染色体编码的判断,0 -- 不输出, 1 -- 输出 */
int nmutation; /* 当前代变异发生次数 */
int ncross; /* 当前代交叉发生次数 */
public:
/* 函数定义 */
void __fastcall TForm1::initialize();
void __fastcall TForm1::initdata();
void __fastcall TForm1::initpop();
void __fastcall TForm1::initreport();
void __fastcall TForm1::generation();
void __fastcall TForm1::initmalloc();
void __fastcall TForm1::freeall();
void __fastcall TForm1::nomemory(char *);
void __fastcall TForm1::report();
void __fastcall TForm1::writepop();
void __fastcall TForm1::writechrom(unsigned *);
void __fastcall TForm1::preselect();
int __fastcall TForm1::select();
void __fastcall TForm1::statistics(struct individual *);
void __fastcall TForm1::title();
void __fastcall TForm1::objfunc(struct individual *);
void __fastcall TForm1::mutation(unsigned *);
int __fastcall TForm1::crossover (unsigned *, unsigned *, unsigned *, unsigned *);
void __fastcall TForm1::advance_random();
int __fastcall TForm1::flip(float);
void __fastcall TForm1::randomize();
int __fastcall TForm1::rnd(int, int);
void __fastcall TForm1::GAmain();
double __fastcall TForm1::randomnormaldeviate();
float __fastcall TForm1::randomperc();
void __fastcall TForm1::rndreal(float,float);
void __fastcall TForm1::warmup_random(float);
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -