本文整理汇总了Python中program.Program.mutate方法的典型用法代码示例。如果您正苦于以下问题:Python Program.mutate方法的具体用法?Python Program.mutate怎么用?Python Program.mutate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类program.Program
的用法示例。
在下文中一共展示了Program.mutate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mutate
# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import mutate [as 别名]
def mutate(self, programs_population):
"""
Generates mutation chances and mutate the team if it is a valid mutation.
"""
if Config.USER['advanced_training_parameters']['use_agressive_mutations']:
mutation_chance = 1
while (mutation_chance > random.random()
and len(self.programs) > Config.USER['training_parameters']['team_size']['min']):
self._randomly_remove_program()
mutation_chance = mutation_chance * Config.USER['training_parameters']['mutation']['team']['remove_program']
mutation_chance = 1
while (mutation_chance > random.random()
and len(self.programs) < Config.USER['training_parameters']['team_size']['max']):
self._randomly_add_program(programs_population)
mutation_chance = mutation_chance * Config.USER['training_parameters']['mutation']['team']['add_program']
else:
if len(self.programs) > Config.USER['training_parameters']['team_size']['min']:
mutation_chance = random.random()
if mutation_chance <= Config.USER['training_parameters']['mutation']['team']['remove_program']:
self._randomly_remove_program()
if len(self.programs) < Config.USER['training_parameters']['team_size']['max']:
mutation_chance = random.random()
if mutation_chance <= Config.USER['training_parameters']['mutation']['team']['add_program']:
self._randomly_add_program(programs_population)
to_mutate = []
while len(to_mutate) == 0:
for program in self.programs:
mutation_chance = random.random()
if mutation_chance <= Config.USER['training_parameters']['mutation']['team']['mutate_program']:
to_mutate.append(program)
for program in to_mutate:
clone = Program(self.generation, copy.deepcopy(program.instructions), program.action)
clone.mutate()
self._add_program(clone)
programs_population.append(clone)
if self._is_ok_to_remove(program):
self.remove_program(program)
return programs_population