本文整理汇总了Python中individual.Individual.evaluate_against方法的典型用法代码示例。如果您正苦于以下问题:Python Individual.evaluate_against方法的具体用法?Python Individual.evaluate_against怎么用?Python Individual.evaluate_against使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类individual.Individual
的用法示例。
在下文中一共展示了Individual.evaluate_against方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from individual import Individual [as 别名]
# 或者: from individual.Individual import evaluate_against [as 别名]
class TestEvaluateAgainst:
def setup(self):
self.individual_a = Individual('0123456789')
def test_identical(self):
chars = self.individual_a.chars
assert_true(self.individual_a.evaluate_against(chars) == len(chars))
def test_no_similarity(self):
assert_true(self.individual_a.evaluate_against('a tallship') == 0)
示例2: Mutator
# 需要导入模块: from individual import Individual [as 别名]
# 或者: from individual.Individual import evaluate_against [as 别名]
from individual import Individual
from mutator import Mutator
num_tries = 0
num_moves = 0
TARGET = "Methinks it is like a weasel"
mutator = Mutator(2)
ind = Individual(len(TARGET))
fitness = ind.evaluate_against(TARGET)
while fitness < len(TARGET):
new_ind = mutator.reproduce_asexually(ind)
new_fitness = new_ind.evaluate_against(TARGET)
num_tries = num_tries + 1
if new_fitness > fitness:
ind = new_ind
fitness = new_fitness
num_moves = num_moves + 1
print(new_ind)
print("Found in",num_tries,"tries and",num_moves,"moves.")