def mutation(self, mutation_type):
if mutation_type not in MUTATION_TYPES:
raise GenomeError("mutation type not supported")
threshold = random.uniform(self.mutation_lower_threshold, self.mutation_higher_threshold)
if threshold < self.mutation_threshold:
return
if mutation_type == "add_node":
self.mutate_add_node()
elif mutation_type == "remove_node":
self.mutate_remove_node()
elif mutation_type == "add_connection":
self.mutate_add_connection()
elif mutation_type == "remove_connection":
self.mutate_remove_connection()
else:
raise GenomeError("something wrong happened in mutation.")
评论列表
文章目录