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


Python ProgressBar.start方法代码示例

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


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

示例1: write_heuristics_data

# 需要导入模块: from ProgressBar import ProgressBar [as 别名]
# 或者: from ProgressBar.ProgressBar import start [as 别名]
def write_heuristics_data(start, n, res_fname, states_fname='data/states.txt', search=a_star, h_name='linear_conflict', heuristic=NPuzzle.linear_conflict):
    """
    Write a file with information on states, depths, expanded nodes, and
    running time for the 3 heuristics implemented on a specific search method.
    """
    from ProgressBar import ProgressBar
    import time
    import re

    with open(res_fname, 'a') as res_f, open(states_fname, 'r') as s_f:
        K = 3
        goal = NPuzzle(K, range(K*K))

        for i in range(start):
            s_f.readline()

        print 'Reading states from file {:s}'.format(states_fname)
        print 'Writing {} states data to file {:s}'.format(n, res_fname)

        pb = ProgressBar() # a simple pogressbar
        pb.start()

        f_format = '{};{};{};{}\n'
        if start == 0:
            columns = ['state', 'steps', h_name + '_nodes', h_name + '_time']
            res_f.write(f_format.format(*columns))

        for i in range(n - start):
            state_str = s_f.readline().strip()
            state = [int (b) for b in re.findall('[0-9]+', state_str)]
            initial = NPuzzle(3, state)

            percent = float(i+start)/(n)
            pb.update(percent)

            try:
                init_time1 = time.time()
                n1, s1, path1 = search(initial, goal, heuristic)
                end_time1 = time.time()
                t1 = end_time1 - init_time1
            except KeyboardInterrupt:
                break
            except:
                t1 = 'NaN'
                n1 = 'NaN'
                s1 = 'NaN'

            res_f.write(f_format.format(initial, s1, n1, t1))
            res_f.flush()
        pb.finish()
开发者ID:jpaulofb,项目名称:NPuzzleSolver,代码行数:52,代码来源:misc.py


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