本文整理汇总了Python中graph_tool.Graph.set_edge_filter方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.set_edge_filter方法的具体用法?Python Graph.set_edge_filter怎么用?Python Graph.set_edge_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.set_edge_filter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_minimum_tree
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import set_edge_filter [as 别名]
def build_minimum_tree(g, root, terminals, edges, directed=True):
"""remove redundant edges from `edges` so that root can reach each node in terminals
"""
# build the tree
t = Graph(directed=directed)
for _ in range(g.num_vertices()):
t.add_vertex()
for (u, v) in edges:
t.add_edge(u, v)
# mask out redundant edges
vis = init_visitor(t, root)
pbfs_search(t, source=root, terminals=list(terminals), visitor=vis)
minimum_edges = {e
for u in terminals
for e in extract_edges_from_pred(t, root, u, vis.pred)}
# print(minimum_edges)
efilt = t.new_edge_property('bool')
efilt.a = False
for u, v in minimum_edges:
efilt[u, v] = True
t.set_edge_filter(efilt)
return filter_nodes_by_edges(t, minimum_edges)