本文整理汇总了Python中algorithm.Algorithm.fitness_function方法的典型用法代码示例。如果您正苦于以下问题:Python Algorithm.fitness_function方法的具体用法?Python Algorithm.fitness_function怎么用?Python Algorithm.fitness_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类algorithm.Algorithm
的用法示例。
在下文中一共展示了Algorithm.fitness_function方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import fitness_function [as 别名]
def main():
parser = argparse.ArgumentParser(description='Highway builder.')
parser.add_argument('-a', required=True, type=float, help='Roads length factor.')
parser.add_argument('-b', required=True, type=float, help='Path length factor.')
parser.add_argument('-i', default=20, type=int, help='Number of iterations.')
args = parser.parse_args()
if args.a < 0:
print('Roads length factor should be greater or equal 0.')
exit()
if args.b < 0:
print('Path length factor should be greater or equal 0.')
exit()
if args.i < 1:
print('Number of iterations should be greater than 0.')
point_tuples = read_cities()
alg = Algorithm(point_tuples, roads_length_factor=args.a, paths_length_factor=args.b, iterations=args.i)
iters_ended = alg.simulated_annealing()
fitness = alg.fitness_function(alg.state)
file_name = "result"
millis = int(round(time.time() * 1000))
file_name += str(millis)
header = str(fitness) \
+ "\na = " + str(alg.roads_length_factor) \
+ "\nb = " + str(alg.paths_length_factor) \
+ "\niterations = " + str(alg.iterations) \
+ "\nended after = " + str(iters_ended) \
+ "\nsame_state = " + str(alg.max_same_state_iterations) \
+ "\n" + str(point_tuples)
save_result(alg.state, header, file_name)