資源簡介
python遺傳算法 源代碼python遺傳算法 源代碼python遺傳算法 源代碼

代碼片段和文件信息
import?numpy?as?np
import?ObjFunction
class?GAIndividual:
????‘‘‘
????individual?of?genetic?algorithm
????‘‘‘
????def?__init__(self??vardim?bound):
????????‘‘‘
????????vardim:?dimension?of?variables
????????bound:?boundaries?of?variables
????????‘‘‘
????????self.vardim?=?vardim
????????self.bound?=?bound
????????self.fitness?=?0.
????def?generate(self):
????????‘‘‘
????????generate?a?random?chromsome?for?genetic?algorithm
????????‘‘‘
????????len?=?self.vardim
????????rnd?=?np.random.random(size=len)
????????self.chrom?=?np.zeros(len)
????????for?i?in?range(0?len):
????????????self.chrom[i]?=?self.bound[0?i]?+?\
????????????????(self.bound[1?i]?-?self.bound[0?i])?*?rnd[i]
????def?calculateFitness(self):
????????‘‘‘
????????calculate?the?fitness?of?the?chromsome
????????‘‘‘
????????self.fitness?=?ObjFunction.GrieFunc(
????????????self.vardim?self.chrom?self.bound)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-24?10:04??遺傳算法\
?????目錄???????????0??2018-04-24?19:34??遺傳算法\.idea\
?????文件?????????185??2018-04-24?08:58??遺傳算法\.idea\misc.xm
?????文件?????????276??2018-04-24?08:58??遺傳算法\.idea\modules.xm
?????文件???????18950??2018-04-24?19:34??遺傳算法\.idea\workspace.xm
?????文件?????????455??2018-04-24?08:59??遺傳算法\.idea\遺傳算法.iml
?????文件?????????923??2018-04-24?10:04??遺傳算法\GAIndividual.py
?????文件????????6523??2018-04-24?10:01??遺傳算法\GeneticAlgorithm.py
?????文件?????????528??2018-04-24?08:59??遺傳算法\ObjFunction.py
?????目錄???????????0??2018-04-24?10:04??遺傳算法\__pycache__\
?????文件????????1281??2018-04-24?10:04??遺傳算法\__pycache__\GAIndividual.cpython-36.pyc
?????文件?????????767??2018-04-24?09:14??遺傳算法\__pycache__\ObjFunction.cpython-36.pyc
評論
共有 條評論