本文整理汇总了Python中Population.Population.get_total_distance方法的典型用法代码示例。如果您正苦于以下问题:Python Population.get_total_distance方法的具体用法?Python Population.get_total_distance怎么用?Python Population.get_total_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population.Population
的用法示例。
在下文中一共展示了Population.get_total_distance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import get_total_distance [as 别名]
def main(self):
herd = Population(30)
selection = SelectionStrategies()
recombination = RecombinationStrategies()
reinsertion = ReinsertionStrategies()
herd.main()
generations = 100
# Display the first generation
print "Generation 1"
# for individual in range(1, len(herd.population)):
# print '--> ' .join(herd.population[individual]),
# print ' = ',herd.objective_values[individual], 'km'
x = herd.objective_values
population = herd.population
for count in range(generations):
population,x = selection.sort_by_fitness(population,x)
parent1, parent2 = selection.tournament(population, x)
child1,child2 = recombination.crossover(parent1, parent2)
fitness_of_child1 = herd.get_total_distance(child1, herd.city_names, herd.routes)
fitness_of_child2 = herd.get_total_distance(child2, herd.city_names, herd.routes)
population,x = reinsertion.tournament(child1, child2, population, x, fitness_of_child1, fitness_of_child2)
print "Generation ",count +2
for individual in range(len(herd.population)):
# print '--> ' .join(population[individual]),
# print ' = ',x[individual], 'km'
print ' ',x[individual],
print