本文整理汇总了Python中Population.Population.addIndividual方法的典型用法代码示例。如果您正苦于以下问题:Python Population.addIndividual方法的具体用法?Python Population.addIndividual怎么用?Python Population.addIndividual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population.Population
的用法示例。
在下文中一共展示了Population.addIndividual方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_GA
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import addIndividual [as 别名]
def run_GA(P, fitnessOp, mutationOp,VEL_POP, MAX_ITER, ERR_THRESHOLD):
fitnessOp.evaluate(P)
gen = 0
print "%5d. gen,\t error: %s" %(gen, fitnessOp.minError)
while gen < MAX_ITER and fitnessOp.minError > ERR_THRESHOLD:
gen += 1
new_P = Population(P.n,0)
new_P.addIndividual(fitnessOp.bestIndividual)
while new_P.populationSize <VEL_POP:
parent1, parent2 = chooseParents(P, fitnessOp)
child = crossover(parent1, parent2)
mutationOp.mutate(child)
new_P.addIndividual(child)
P = new_P
fitnessOp.evaluate(P)
print "%5d. gen,\t error: %s" %(gen, fitnessOp.minError)
return fitnessOp.bestIndividual