本文整理匯總了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)