当前位置: 首页>>代码示例>>Python>>正文


Python Algorithm.simulated_annealing方法代码示例

本文整理汇总了Python中algorithm.Algorithm.simulated_annealing方法的典型用法代码示例。如果您正苦于以下问题:Python Algorithm.simulated_annealing方法的具体用法?Python Algorithm.simulated_annealing怎么用?Python Algorithm.simulated_annealing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.simulated_annealing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import simulated_annealing [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)
开发者ID:5james,项目名称:Highway-Constructor,代码行数:38,代码来源:main.py


注:本文中的algorithm.Algorithm.simulated_annealing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。