當前位置: 首頁>>代碼示例>>Python>>正文


Python Graph.set_edge_filter方法代碼示例

本文整理匯總了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)
開發者ID:xiaohan2012,項目名稱:active-infection-source-finding,代碼行數:29,代碼來源:utils.py


注:本文中的graph_tool.Graph.set_edge_filter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。