本文整理汇总了Python中Population.Population.get_individual方法的典型用法代码示例。如果您正苦于以下问题:Python Population.get_individual方法的具体用法?Python Population.get_individual怎么用?Python Population.get_individual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population.Population
的用法示例。
在下文中一共展示了Population.get_individual方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evolve_population
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import get_individual [as 别名]
def evolve_population(population_passed):
print("Evolving population...")
new_population = Population(population_passed.size(), False)
# If Elitism is enabled then copy the best scoring individual to the next generation
if Algorithm.Elitism:
new_population.individuals.append(population_passed.get_fittest())
elitism_off_set = 1
else:
elitism_off_set = 0
#Do crossover over the entire population
for i in range(elitism_off_set, population_passed.size()):
individual1 = Algorithm.tournament_selection(population_passed)
individual2 = Algorithm.tournament_selection(population_passed)
new_individual = Algorithm.crossover(individual1, individual2)
new_population.individuals.append(new_individual)
#Do mutation randomly
for i in range(elitism_off_set, population_passed.size()):
Algorithm.mutate(new_population.get_individual(i))
#Repair any individuals broken by crossover or mutation
for individual in new_population.individuals:
individual.genes = fpl.repairteam(individual.genes)
for i in range(population_passed.size()):
new_population.get_individual(i).reset_score()
return new_population
示例2: evolve
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import get_individual [as 别名]
def evolve(self, population):
new_population = Population(population.get_size(), False)
# Save the best individual for the next generation if elitism is activated
if self.elitism:
new_population.save_individual(0, population.get_fittest())
# Create Crossovers
for i in range(self.elitism_offset, population.get_size()):
parent_1 = self.tournament_selection(population)
parent_2 = self.tournament_selection(population)
child = self.crossover(parent_1, parent_2)
new_population.save_individual(i, child)
# Create mutants
for i in range(self.elitism_offset, new_population.get_size()):
self.mutate(new_population.get_individual(i))
return new_population
示例3: evolve_population
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import get_individual [as 别名]
def evolve_population(population_passed):
print("Evolving population...")
new_population = Population(population_passed.size(), False)
if Algorithm.Elitism:
new_population.individuals.append(population_passed.get_fittest())
elitism_off_set = 1
else:
elitism_off_set = 0
#Do crossover over the entire population
for i in range(elitism_off_set, population_passed.size()):
individual1 = Algorithm.tournament_selection(population_passed)
individual2 = Algorithm.tournament_selection(population_passed)
new_individual = Algorithm.crossover(individual1, individual2)
new_population.individuals.append(new_individual)
#Do mutation randomly
for i in range(elitism_off_set, population_passed.size()):
Algorithm.mutate(new_population.get_individual(i))
return new_population