資源簡介
一個簡單遺傳算法的模板,提供兩種交叉方式,網友可自己更改,對各種問題要做相應更改
代碼片段和文件信息
#include
#include
#include
#include
#include
using?namespace?std;
namespace?GA
{
??//???隨機數函數
??//???開機的毫秒數作為隨機種子
??float?lewis(){
????static?long?double?seed=GetTickCount();
????seed=seed+214;
???????seed=fmod(float(seed*16807.)float(?2147483647.));
???????return(seed/2147483647.);
??};
??//基因型結構體
??//包括基因串及長度
??class?Gen{
??public:
????char?*?bufs;
????int?numbers;
float?adarate;
????Gen(){bufs=NULL;};
????~Gen(){?delete?[]?bufs;}
??};
??//結果結構體
??//包括結果及代數
??typedef?struct?resoulst{
????int?generations;
????int?resou;
??}resoult;
??class?GA
??{
????int?allada;
????int?counts;????????????????//種群數量
????int?length;?????????????????//基因位數
????resoult?*rs;
????float?(*eva
- 上一篇:HMac_SHA512哈希算法
- 下一篇:IEC104規約的VC++實現
評論
共有 條評論