本文整理汇总了Python中population.Population.nextGeneration方法的典型用法代码示例。如果您正苦于以下问题:Python Population.nextGeneration方法的具体用法?Python Population.nextGeneration怎么用?Python Population.nextGeneration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类population.Population
的用法示例。
在下文中一共展示了Population.nextGeneration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_simulation
# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import nextGeneration [as 别名]
def run_simulation(repo_path, gen_max):
logger.info("Running simulation with: REPO_PATH={}, GENERATION_MAX={}"
.format(repo_path, gen_max))
# Init base system
sys=System(repo_path=repo_path)
sys.setLowestVersions()
sys.dump()
# Init goal (latest version)
goal=System.latestVersion(sys)
goal.dump()
# Init population
pop=Population(DEFAULT_POP_SIZE, sys, goal)
# Init dataframe for storing results
## TODO
logger.info("Starting simulation...")
for i in range(gen_max):
'''
For each generation we need to go through all the genomes
and evolve them (mutate/crossover/rebel) and test. The more
successful a genome is (more programs installed/tests), the
more likely it is to create offspring for the next generation
'''
logger.info("Generation #{}".format(i))
for genome in pop.getGenomes():
# TODO some evaluation, score, record
logger.info("\t{}".format(genome))
#Check if objective has been met yet
if pop.isGoalMet():
# TODO
logger.info("Goal configuration has been found!")
break
pop=pop.nextGeneration()
logger.debug("System state at end of this generation")
pop.sys.dump()
#TODO do some final reporting
logger.info("Final configuration after {} generations looks like:".format(i))
pop.sys.dump()