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


Python Field.load_by_json方法代码示例

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


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

示例1: analyze

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import load_by_json [as 别名]
def analyze():
    # gen = scripts.load_template_ascii_gen_from_file('mx.tl')
    # fields, _ = scripts.init_correct_field_by_ascii_gen(gen)
    # field = fields[0]

    # with T():
    #     covers_ret = pickle_cover.to_cover(field, max_spear=18, max_answer=20000)
    #     covers = [cov[1] for cov in covers_ret]
    #
    # with T():
    #     with open(conf['field'], 'w') as f:
    #         f.write(field.take_json())
    #     pickle_cover.dump(covers, conf['covers'])

    # with T('alternative_path_lens'):
    #     apl = map(scripts.alternative_path_lens, scripts.covered(t_field, covers))
    #     pickle_cover.dump(apl, conf['apl'])

    # with T('ans_len'):
    #     ans_len = map(len, itertools.imap(solver.solve_one, scripts.covered(t_field, covers)))
    #     pickle_cover.dump(ans_len, conf['ans_len'])

    # with T('walked_spear'):
    #     sc = scripts
    #     isec = lambda f: set(solver.solve_one(c)) & set(c.get_spear_coords())
    #     walked_spear = [len(isec(c)) for c in sc.covered(t_field, covers)]
    #     pickle_cover.dump(walked_spear, conf['walked_spear'])

    # with T('field_min_max'):
    #     lens = map(len, solver.solve(t_field))
    #     field_min_max = min(lens), max(lens)
    #     pickle_cover.dump(field_min_max, conf['field_min_max'])

    with T('Load'):
        t_field = Field.load_by_json(conf['field'])
        covers = pickle_cover.load(conf['covers'])
        apl = pickle_cover.load(conf['apl'])
        ans_len = pickle_cover.load(conf['ans_len'])
        walked_spear = pickle_cover.load(conf['walked_spear'])
        field_min_max = pickle_cover.load(conf['field_min_max'])

    with T('work'):
        dp = DataProcessing(t_field, covers)
        dp.solver
        dp.alternative_path_len

    """
开发者ID:hard7,项目名称:level-generator,代码行数:49,代码来源:main.py

示例2: dump_current_field_covers

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import load_by_json [as 别名]
def dump_current_field_covers(path_, i_):
    def unique_append(list_, item):
        if item not in list_:
            list_.append(item)
        return list_.index(item)

    pr_periods = list()
    pr_cells = list()
    pr_paths = list()
    pr_covers = list()
    pr_cover_paths = list()

    base = Field.load_by_json('%s/base_%i.json' % (path_, i_))

    with T():
        path_and_spears_group = pickle_cover.to_cover(base, max_spear=20, max_answer=50000)

    for path, spears in path_and_spears_group:
        new_cover = list()
        for spear in spears:
            cell, period = spear[:2], spear[2:]
            cell_id = unique_append(pr_cells, cell)
            period_id = unique_append(pr_periods, period)
            new_cover.append((cell_id, period_id))
        pr_covers.append(tuple(new_cover))

        new_path = list()
        for cell in path[0]:
            cell_id = unique_append(pr_cells, cell)
            new_path.append(cell_id)
        path_id = unique_append(pr_paths, tuple(new_path))
        pr_cover_paths.append(path_id)

    dump_dict = dict()
    dump_dict['base'] = base.take_json()
    dump_dict['periods'] = pr_periods
    dump_dict['cells'] = pr_cells
    dump_dict['paths'] = pr_paths
    dump_dict['covers'] = pr_covers
    dump_dict['cover_paths'] = pr_cover_paths

    with open('%s/covers/case_%i.dump' % (path_, i_), 'w') as f:
        cPickle.dump(dump_dict, f)
开发者ID:hard7,项目名称:level-generator,代码行数:45,代码来源:main.py

示例3: show_count_paths

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import load_by_json [as 别名]
def show_count_paths(path_, i_):
    base = Field.load_by_json('/home/anosov/data/hard_base/base_%i.json' % (i_, ))
    with T():
        res = solver.solve(base)
    print len(res)
开发者ID:hard7,项目名称:level-generator,代码行数:7,代码来源:main.py


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