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


Python networkx.condensation方法代码示例

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


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

示例1: test_condensation_as_quotient

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_condensation_as_quotient(self):
        """This tests that the condensation of a graph can be viewed as the
        quotient graph under the "in the same connected component" equivalence
        relation.

        """
        # This example graph comes from the file `test_strongly_connected.py`.
        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (2, 11), (2, 12), (3, 4), (4, 3),
                          (4, 5), (5, 6), (6, 5), (6, 7), (7, 8), (7, 9),
                          (7, 10), (8, 9), (9, 7), (10, 6), (11, 2), (11, 4),
                          (11, 6), (12, 6), (12, 11)])
        scc = list(nx.strongly_connected_components(G))
        C = nx.condensation(G, scc)
        component_of = C.graph['mapping']
        # Two nodes are equivalent if they are in the same connected component.
        same_component = lambda u, v: component_of[u] == component_of[v]
        Q = nx.quotient_graph(G, same_component)
        assert_true(nx.is_isomorphic(C, Q)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:21,代码来源:test_minors.py

示例2: test_contract_scc1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_contract_scc1(self):
        G = nx.DiGraph()
        G.add_edges_from([
            (1, 2), (2, 3), (2, 11), (2, 12), (3, 4), (4, 3), (4, 5), (5, 6),
            (6, 5), (6, 7), (7, 8), (7, 9), (7, 10), (8, 9), (9, 7), (10, 6),
            (11, 2), (11, 4), (11, 6), (12, 6), (12, 11),
        ])
        scc = list(nx.strongly_connected_components(G))
        cG = nx.condensation(G, scc)
        # DAG
        assert_true(nx.is_directed_acyclic_graph(cG))
        # nodes
        assert_equal(sorted(cG.nodes()), [0, 1, 2, 3])
        # edges
        mapping={}
        for i, component in enumerate(scc):
            for n in component:
                mapping[n] = i
        edge = (mapping[2], mapping[3])
        assert_true(cG.has_edge(*edge))
        edge = (mapping[2], mapping[5])
        assert_true(cG.has_edge(*edge))
        edge = (mapping[3], mapping[5])
        assert_true(cG.has_edge(*edge)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:26,代码来源:test_strongly_connected.py

示例3: test_condensation_as_quotient

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_condensation_as_quotient(self):
        """This tests that the condensation of a graph can be viewed as the
        quotient graph under the "in the same connected component" equivalence
        relation.

        """
        # This example graph comes from the file `test_strongly_connected.py`.
        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (2, 11), (2, 12), (3, 4), (4, 3),
                          (4, 5), (5, 6), (6, 5), (6, 7), (7, 8), (7, 9),
                          (7, 10), (8, 9), (9, 7), (10, 6), (11, 2), (11, 4),
                          (11, 6), (12, 6), (12, 11)])
        scc = list(nx.strongly_connected_components(G))
        C = nx.condensation(G, scc)
        component_of = C.graph['mapping']
        # Two nodes are equivalent if they are in the same connected component.

        def same_component(u, v):
            return component_of[u] == component_of[v]

        Q = nx.quotient_graph(G, same_component)
        assert_true(nx.is_isomorphic(C, Q)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:test_minors.py

示例4: test_contract_scc1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_contract_scc1(self):
        G = nx.DiGraph()
        G.add_edges_from([
            (1, 2), (2, 3), (2, 11), (2, 12), (3, 4), (4, 3), (4, 5), (5, 6),
            (6, 5), (6, 7), (7, 8), (7, 9), (7, 10), (8, 9), (9, 7), (10, 6),
            (11, 2), (11, 4), (11, 6), (12, 6), (12, 11),
        ])
        scc = list(nx.strongly_connected_components(G))
        cG = nx.condensation(G, scc)
        # DAG
        assert_true(nx.is_directed_acyclic_graph(cG))
        # nodes
        assert_equal(sorted(cG.nodes()), [0, 1, 2, 3])
        # edges
        mapping = {}
        for i, component in enumerate(scc):
            for n in component:
                mapping[n] = i
        edge = (mapping[2], mapping[3])
        assert_true(cG.has_edge(*edge))
        edge = (mapping[2], mapping[5])
        assert_true(cG.has_edge(*edge))
        edge = (mapping[3], mapping[5])
        assert_true(cG.has_edge(*edge)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:test_strongly_connected.py

示例5: compute_condensation_in_topological_order

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def compute_condensation_in_topological_order(dependency_graph: nx.DiGraph, sort_by = lambda x: x):
    if not dependency_graph.number_of_nodes():
        return

    condensed_graph = nx.condensation(dependency_graph)
    assert isinstance(condensed_graph, nx.DiGraph)

    for connected_component_index in nx.lexicographical_topological_sort(condensed_graph, key=sort_by):
        yield list(sorted(condensed_graph.nodes[connected_component_index]['members'], key=sort_by)) 
开发者ID:google,项目名称:tmppy,代码行数:11,代码来源:_graphs.py

示例6: recalculate_template_instantiation_can_trigger_static_asserts_info

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def recalculate_template_instantiation_can_trigger_static_asserts_info(header: ir.Header):
    if not header.template_defns:
        return header

    template_defn_by_name = {template_defn.name: template_defn
                             for template_defn in header.template_defns}
    template_defn_dependency_graph = compute_template_dependency_graph(header.template_defns, template_defn_by_name)

    condensed_graph = nx.condensation(template_defn_dependency_graph)
    assert isinstance(condensed_graph, nx.DiGraph)

    template_defn_dependency_graph_transitive_closure = nx.transitive_closure(template_defn_dependency_graph)
    assert isinstance(template_defn_dependency_graph_transitive_closure, nx.DiGraph)

    # Determine which connected components can trigger static assert errors.
    condensed_node_can_trigger_static_asserts = defaultdict(lambda: False)
    for connected_component_index in reversed(list(nx.lexicographical_topological_sort(condensed_graph))):
        condensed_node = condensed_graph.nodes[connected_component_index]

        # If a template defn in this connected component can trigger a static assert, the whole component can.
        for template_defn_name in condensed_node['members']:
            if _template_defn_contains_static_assert_stmt(template_defn_by_name[template_defn_name]):
                condensed_node_can_trigger_static_asserts[connected_component_index] = True

        # If a template defn in this connected component references a template defn in a connected component that can
        # trigger static asserts, this connected component can also trigger them.
        for called_condensed_node_index in condensed_graph.successors(connected_component_index):
            if condensed_node_can_trigger_static_asserts[called_condensed_node_index]:
                condensed_node_can_trigger_static_asserts[connected_component_index] = True

    template_defn_can_trigger_static_asserts = dict()
    for connected_component_index in condensed_graph:
        for template_defn_name in condensed_graph.nodes[connected_component_index]['members']:
            template_defn_can_trigger_static_asserts[template_defn_name] = condensed_node_can_trigger_static_asserts[connected_component_index]

    return _apply_template_instantiation_can_trigger_static_asserts_info(header, template_defn_can_trigger_static_asserts) 
开发者ID:google,项目名称:tmppy,代码行数:38,代码来源:_recalculate_template_instantiation_can_trigger_static_asserts_info.py

示例7: test_contract_scc_isolate

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_contract_scc_isolate(self):
        # Bug found and fixed in [1687].
        G = nx.DiGraph()
        G.add_edge(1, 2)
        G.add_edge(2, 1)
        scc = list(nx.strongly_connected_components(G))
        cG = nx.condensation(G, scc)
        assert_equal(list(cG.nodes()), [0])
        assert_equal(list(cG.edges()), []) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_strongly_connected.py

示例8: test_contract_scc_edge

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_contract_scc_edge(self):
        G = nx.DiGraph()
        G.add_edge(1, 2)
        G.add_edge(2, 1)
        G.add_edge(2, 3)
        G.add_edge(3, 4)
        G.add_edge(4, 3)
        scc = list(nx.strongly_connected_components(G))
        cG = nx.condensation(G, scc)
        assert_equal(cG.nodes(), [0, 1])
        if 1 in scc[0]:
            edge = (0, 1)
        else:
            edge = (1, 0)
        assert_equal(list(cG.edges()), [edge]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:17,代码来源:test_strongly_connected.py

示例9: test_connected_raise

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_connected_raise(self):
        G=nx.Graph()
        assert_raises(NetworkXNotImplemented, nx.strongly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.kosaraju_strongly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.strongly_connected_components_recursive, G)
        assert_raises(NetworkXNotImplemented, nx.strongly_connected_component_subgraphs, G)
        assert_raises(NetworkXNotImplemented, nx.is_strongly_connected, G)
        assert_raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph())
        assert_raises(NetworkXNotImplemented, nx.condensation, G) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_strongly_connected.py

示例10: attracting_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def attracting_components(G):
    """Generates a list of attracting components in `G`.

    An attracting component in a directed graph `G` is a strongly connected
    component with the property that a random walker on the graph will never
    leave the component, once it enters the component.

    The nodes in attracting components can also be thought of as recurrent
    nodes.  If a random walker enters the attractor containing the node, then
    the node will be visited infinitely often.

    Parameters
    ----------
    G : DiGraph, MultiDiGraph
        The graph to be analyzed.

    Returns
    -------
    attractors : generator of sets
        A generator of sets of nodes, one for each attracting component of G.

    See Also
    --------
    number_attracting_components
    is_attracting_component 
    attracting_component_subgraphs

    """
    scc = list(nx.strongly_connected_components(G))
    cG = nx.condensation(G, scc)
    for n in cG:
        if cG.out_degree(n) == 0:
            yield scc[n] 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:35,代码来源:attracting.py

示例11: test_contract_scc_edge

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_contract_scc_edge(self):
        G = nx.DiGraph()
        G.add_edge(1, 2)
        G.add_edge(2, 1)
        G.add_edge(2, 3)
        G.add_edge(3, 4)
        G.add_edge(4, 3)
        scc = list(nx.strongly_connected_components(G))
        cG = nx.condensation(G, scc)
        assert_equal(sorted(cG.nodes()), [0, 1])
        if 1 in scc[0]:
            edge = (0, 1)
        else:
            edge = (1, 0)
        assert_equal(list(cG.edges()), [edge]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:17,代码来源:test_strongly_connected.py

示例12: test_null_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_null_graph(self):
        G = nx.DiGraph()
        assert_equal(list(nx.strongly_connected_components(G)), [])
        assert_equal(list(nx.kosaraju_strongly_connected_components(G)), [])
        assert_equal(list(nx.strongly_connected_components_recursive(G)), [])
        assert_equal(len(nx.condensation(G)), 0)
        assert_raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph()) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_strongly_connected.py

示例13: test_connected_raise

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def test_connected_raise(self):
        G = nx.Graph()
        assert_raises(NetworkXNotImplemented, nx.strongly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.kosaraju_strongly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.strongly_connected_components_recursive, G)
        assert_raises(NetworkXNotImplemented, nx.is_strongly_connected, G)
        assert_raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph())
        assert_raises(NetworkXNotImplemented, nx.condensation, G)
        # deprecated
        assert_raises(NetworkXNotImplemented, nx.strongly_connected_component_subgraphs, G)

#    Commented out due to variability on Travis-CI hardware/operating systems
#    def test_linear_time(self):
#        # See Issue #2831
#        count = 100  # base case
#        dg = nx.DiGraph()
#        dg.add_nodes_from([0, 1])
#        for i in range(2, count):
#            dg.add_node(i)
#            dg.add_edge(i, 1)
#            dg.add_edge(0, i)
#        t = time.time()
#        ret = tuple(nx.strongly_connected_components(dg))
#        dt = time.time() - t
#
#        count = 200
#        dg = nx.DiGraph()
#        dg.add_nodes_from([0, 1])
#        for i in range(2, count):
#            dg.add_node(i)
#            dg.add_edge(i, 1)
#            dg.add_edge(0, i)
#        t = time.time()
#        ret = tuple(nx.strongly_connected_components(dg))
#        dt2 = time.time() - t
#        assert_less(dt2, dt * 2.3)  # should be 2 times longer for this graph 
开发者ID:holzschu,项目名称:Carnets,代码行数:38,代码来源:test_strongly_connected.py

示例14: attracting_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def attracting_components(G):
    """Generates the attracting components in `G`.

    An attracting component in a directed graph `G` is a strongly connected
    component with the property that a random walker on the graph will never
    leave the component, once it enters the component.

    The nodes in attracting components can also be thought of as recurrent
    nodes.  If a random walker enters the attractor containing the node, then
    the node will be visited infinitely often.

    Parameters
    ----------
    G : DiGraph, MultiDiGraph
        The graph to be analyzed.

    Returns
    -------
    attractors : generator of sets
        A generator of sets of nodes, one for each attracting component of G.

    Raises
    ------
    NetworkXNotImplemented :
        If the input graph is undirected.

    See Also
    --------
    number_attracting_components
    is_attracting_component

    """
    scc = list(nx.strongly_connected_components(G))
    cG = nx.condensation(G, scc)
    for n in cG:
        if cG.out_degree(n) == 0:
            yield scc[n] 
开发者ID:holzschu,项目名称:Carnets,代码行数:39,代码来源:attracting.py

示例15: attracting_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import condensation [as 别名]
def attracting_components(G):
    """Generates a list of attracting components in `G`.

    An attracting component in a directed graph `G` is a strongly connected
    component with the property that a random walker on the graph will never
    leave the component, once it enters the component.

    The nodes in attracting components can also be thought of as recurrent
    nodes.  If a random walker enters the attractor containing the node, then
    the node will be visited infinitely often.

    Parameters
    ----------
    G : DiGraph, MultiDiGraph
        The graph to be analyzed.

    Returns
    -------
    attractors : generator of sets
        A generator of sets of nodes, one for each attracting component of G.

    Raises
    ------
    NetworkXNotImplemented :
        If the input graph is undirected.

    See Also
    --------
    number_attracting_components
    is_attracting_component
    attracting_component_subgraphs

    """
    scc = list(nx.strongly_connected_components(G))
    cG = nx.condensation(G, scc)
    for n in cG:
        if cG.out_degree(n) == 0:
            yield scc[n] 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:40,代码来源:attracting.py


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