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


Python Graph.to_prose方法代码示例

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


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

示例1: main

# 需要导入模块: from graphs import Graph [as 别名]
# 或者: from graphs.Graph import to_prose [as 别名]
def main():
    """Parse arguments, read in and analyze a graph, and print the analysis."""
    parser = argparse.ArgumentParser(
        prog='python -m graphs',
        description='''\
        Read in and analyze a weighted, directed graph. Print an analysis of
        the graph to stdout.
        ''',
    )
    parser.add_argument(
        'file',
        help='The file containing a graph description.',
        type=str,
    )
    parser.add_argument(
        '--analysis',
        help='Which type of analysis should be printed?',
        choices=('prose', 'full-graph', 'alt-full-graph', 'component-graph'),
        default='prose',
    )
    args = parser.parse_args()

    # We do work that may not be needed. An application intended for real world
    # use should be smarter about doing work. But this algorithm is intended
    # for educational purposes, and clarity is more important than efficiency.
    full_graph = Graph()
    full_graph.read_file(args.file)
    comp_graph = full_graph.get_component_graph()

    if args.analysis == 'prose':
        print(full_graph.to_prose())
    elif args.analysis == 'full-graph':
        highlight = tuple(chain.from_iterable(get_component_msts(full_graph)))
        print('digraph full {\n\n' + full_graph.to_dot(highlight) + '}\n')
    elif args.analysis == 'alt-full-graph':
        highlight = prim(full_graph, full_graph.get_components()[-1][0])
        print('digraph alt_full {\n\n' + full_graph.to_dot(highlight) + '}\n')
    elif args.analysis == 'component-graph':
        highlight = prim(comp_graph, comp_graph.get_components()[-1][0])
        print('digraph component {\n\n' + comp_graph.to_dot(highlight) + '}\n')
    else:
        warnings.warn('Unhandled argument: {}'.format(args.analysis))
开发者ID:Ichimonji10,项目名称:impedimenta,代码行数:44,代码来源:__main__.py


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