本文整理汇总了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))