資源描述:
《遺傳算法解決二次函數(shù)問地的題目》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、實用標(biāo)準(zhǔn)文案<遺傳算法>技術(shù)文檔問題:??利用遺傳算法求解區(qū)間[0,?31]上的二次函數(shù)y=x2的最大值?VS2005C++環(huán)境C++面向?qū)ο蟮乃枷朐O(shè)計遺傳算法1、各參數(shù)變量的說明(1)shortbitString;//個體的二進(jìn)制編碼(2)shortfitness;//個體的適應(yīng)度(3)staticconstshortbitCount=5;//個體二進(jìn)制碼的長度(4)staticconstshortpopuScale=10;//種群規(guī)模(5)#defineCROSS_MUTATE_PRO_COMP100//交叉、變異的基
2、數(shù)(6)staticconstshortpc=40;//交叉?zhèn)€體數(shù)相對于基數(shù)(7)staticconstshortpm=5;//變異個體數(shù)相對于基數(shù)(8)IndividualpopuArray[popuScale];//種群(9)shortgen=0;//種群進(jìn)化的代數(shù)2、遺傳操作的設(shè)計思想?分別設(shè)計了一個個體類、種群類,種群由個體組成,這是類庫設(shè)計,對用戶來說,分別使用這兩個類來實現(xiàn)遺傳算法,其中選擇中采用輪盤賭來選擇下一代。(1)、個體類設(shè)計如下:#ifndef__INDIVIDUAL_H__#define__INDI
3、VIDUAL_H__#includeclassIndividual{private:shortbitString;//個體的二進(jìn)制編碼shortfitness;//個體的適應(yīng)度public:staticconstshortbitCount=5;//個體二進(jìn)制碼的長度Individual();Individual(shortn);Individual(shortbitStr,intfit);~Individual();shortGetFitness()const;shortGetBitString()co
4、nst;//voidsetBitString();//voidsetFitness();booloperator>(constIndividual&indi)const;booloperator==(constIndividual&indi)const;friendstd::ostream&operator<<(std::ostream&os,constIndividual&indi);voidShowIndividual(void)const;};#endif(2)種群類設(shè)計如下:#ifndef__POPULATION_
5、H__精彩文檔實用標(biāo)準(zhǔn)文案#define__POPULATION_H__#include"individual.h"#defineCROSS_MUTATE_PRO_COMP100//交叉、變異的基數(shù)classPopulation{public:staticconstshortpopuScale=10;//種群規(guī)模private:staticconstshortpc=40;//交叉?zhèn)€體數(shù)相對于基數(shù)staticconstshortpm=5;//變異個體數(shù)相對于基數(shù)IndividualpopuArray[popuScale];p
6、ublic:Population();voidSelection();//選擇voidCrossover();//交叉voidMutation();//變異constIndividual&GetbestIndividual()const;constIndividual&GetRepresatationIndividual()const;friendstd::ostream&operator<<(std::ostream&os,constPopulation&p);voidShowPopulation()const;~Pop
7、ulation();};#endif(3)用戶區(qū)程序代碼(遺傳算法實現(xiàn)):#include#include"individual.h"#include"population.h"voidGA(void);intmain(){GA();}voidGA(void){std::cout<<"Pleaseenterhowmanygenerationsyouwantthepopulationtoevolve!"<>gen;Popula
8、tionbirds;for(inti=0;i