本文整理汇总了Python中individual.Individual.random_ind方法的典型用法代码示例。如果您正苦于以下问题:Python Individual.random_ind方法的具体用法?Python Individual.random_ind怎么用?Python Individual.random_ind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类individual.Individual
的用法示例。
在下文中一共展示了Individual.random_ind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from individual import Individual [as 别名]
# 或者: from individual.Individual import random_ind [as 别名]
def __init__(self, size):
self.size = size
self.pop = []
self.selected = []
self.selected_indexes = []
self.fitness_table = []
Individual.mutation_factor = 5
for i in xrange(size):
self.pop.append(Individual.random_ind())
示例2: test_mutation
# 需要导入模块: from individual import Individual [as 别名]
# 或者: from individual.Individual import random_ind [as 别名]
def test_mutation(self):
ind1 = Individual.random_ind()
mutated_gene_index, mutated_value = ind1.mutate_random_gene()
self.assertEqual(ind1.genome[mutated_gene_index], mutated_value)
示例3: test_random
# 需要导入模块: from individual import Individual [as 别名]
# 或者: from individual.Individual import random_ind [as 别名]
def test_random(self):
ind1 = Individual.random_ind()
ind2 = Individual.random_ind(20)
self.assertEqual(len(ind1.genome), 15)
self.assertEqual(len(ind2.genome), 20)
self.assertEqual(ind1.fitness, 0)