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


Python networkx.weakly_connected_component_subgraphs方法代码示例

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


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

示例1: plan

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def plan(config, state_info):
    """Defines a startup plan for the MineMeld graph.

    Args:
        config (MineMeldConfig): config
        state_info (dict): state_info for each node

    Returns a dictionary where keys are node names and
    values the satrtup command for the node.
    """
    plan = {}

    graph = _build_graph(config)

    for subgraph in nx.weakly_connected_component_subgraphs(graph, copy=True):
        plan.update(_plan_subgraph(subgraph, config, state_info))

    return plan 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:20,代码来源:startupplanner.py

示例2: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def setUp(self):
        self.undirected = [
            nx.connected_component_subgraphs,
            nx.biconnected_component_subgraphs,
        ]
        self.directed = [
            nx.weakly_connected_component_subgraphs,
            nx.strongly_connected_component_subgraphs,
            nx.attracting_component_subgraphs,
        ]
        self.subgraph_funcs = self.undirected + self.directed
        
        self.D = nx.DiGraph()
        self.D.add_edge(1, 2, eattr='red')
        self.D.add_edge(2, 1, eattr='red')
        self.D.node[1]['nattr'] = 'blue'
        self.D.graph['gattr'] = 'green'

        self.G = nx.Graph()
        self.G.add_edge(1, 2, eattr='red')
        self.G.node[1]['nattr'] = 'blue'
        self.G.graph['gattr'] = 'green' 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:24,代码来源:test_subgraph_copies.py

示例3: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def setUp(self):
        self.undirected = [
            nx.connected_component_subgraphs,
            nx.biconnected_component_subgraphs,
        ]
        self.directed = [
            nx.weakly_connected_component_subgraphs,
            nx.strongly_connected_component_subgraphs,
            nx.attracting_component_subgraphs,
        ]
        self.subgraph_funcs = self.undirected + self.directed

        self.D = nx.DiGraph()
        self.D.add_edge(1, 2, eattr='red')
        self.D.add_edge(2, 1, eattr='red')
        self.D.nodes[1]['nattr'] = 'blue'
        self.D.graph['gattr'] = 'green'

        self.G = nx.Graph()
        self.G.add_edge(1, 2, eattr='red')
        self.G.nodes[1]['nattr'] = 'blue'
        self.G.graph['gattr'] = 'green' 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:test_subgraph_copies.py

示例4: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def setUp(self):
        self.undirected = [
            nx.connected_component_subgraphs,
            nx.biconnected_component_subgraphs,
        ]
        self.directed = [
            nx.weakly_connected_component_subgraphs,
            nx.strongly_connected_component_subgraphs,
            nx.attracting_component_subgraphs,
        ]
        self.subgraph_funcs = self.undirected + self.directed
        
        self.D = nx.DiGraph()
        self.D.add_edge(1, 2, eattr='red')
        self.D.add_edge(2, 1, eattr='red')
        self.D.nodes[1]['nattr'] = 'blue'
        self.D.graph['gattr'] = 'green'

        self.G = nx.Graph()
        self.G.add_edge(1, 2, eattr='red')
        self.G.nodes[1]['nattr'] = 'blue'
        self.G.graph['gattr'] = 'green' 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:24,代码来源:test_subgraph_copies.py

示例5: get_lcc

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def get_lcc(di_graph):
    di_graph = di_graph.to_undirected().to_directed()
    di_graph = max(nx.weakly_connected_component_subgraphs(di_graph), key=len)
    tdl_nodes = di_graph.nodes()
    nodeListMap = dict(zip(tdl_nodes, range(len(tdl_nodes))))
    di_graph = nx.relabel_nodes(di_graph, nodeListMap, copy=True)
    return di_graph, nodeListMap 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:9,代码来源:graph_util.py

示例6: ok_to_remove_node

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def ok_to_remove_node(g,n):
    g0 = copy.deepcopy(g)
    n0 = get_node_by_addr(g0,n.addr)
    g0.remove_node(n0)
    return len([x for x in networkx.weakly_connected_component_subgraphs(g0)]) <= 1 
开发者ID:fiberx,项目名称:fiber,代码行数:7,代码来源:utils_sig.py

示例7: cluster_padding_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def cluster_padding_nodes(cfg,addrs):
    nodes = [get_node_by_addr(cfg,x) for x in addrs]
    sg = cfg.subgraph(nodes)
    gs = [g for g in networkx.weakly_connected_component_subgraphs(sg)]
    return sorted(gs,key=lambda x:len(x)) 
开发者ID:fiberx,项目名称:fiber,代码行数:7,代码来源:utils_sig.py

示例8: _handle_contained_in

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def _handle_contained_in(ctx):
    # for each 'contained' tree, recursively build new trees based on
    # scaling groups with generated ids
    for contained_tree in nx.weakly_connected_component_subgraphs(
            ctx.plan_contained_graph.reverse(copy=True)):
        # extract tree root node id
        node_id = nx.topological_sort(contained_tree)[0]
        _build_multi_instance_node_tree_rec(
            node_id=node_id,
            contained_tree=contained_tree,
            ctx=ctx)
    ctx.deployment_contained_graph = ctx.deployment_node_graph.copy() 
开发者ID:cloudify-cosmo,项目名称:cloudify-dsl-parser,代码行数:14,代码来源:rel_graph.py

示例9: components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def components(self) -> List['DAGCircuit']:
        """Split DAGCircuit into independent components"""
        comps = nx.weakly_connected_component_subgraphs(self.graph)
        return [DAGCircuit(comp) for comp in comps] 
开发者ID:rigetti,项目名称:quantumflow,代码行数:6,代码来源:dagcircuit.py

示例10: get_lcc

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def get_lcc(di_graph):
    di_graph = max(nx.weakly_connected_component_subgraphs(di_graph), key=len)
    tdl_nodes = list(di_graph.nodes())
    nodeListMap = dict(zip(tdl_nodes, range(len(tdl_nodes))))
    nx.relabel_nodes(di_graph, nodeListMap, copy=False)
    return di_graph, nodeListMap 
开发者ID:palash1992,项目名称:GEM,代码行数:8,代码来源:graph_util.py

示例11: test_connected_component_subgraphs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def test_connected_component_subgraphs(self):
        wcc = nx.weakly_connected_component_subgraphs
        cc = nx.connected_component_subgraphs
        for G, C in self.gc:
            U = G.to_undirected()
            w = {frozenset(g) for g in wcc(G)}
            c = {frozenset(g) for g in cc(U)}
            assert_equal(w, c) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_connected.py

示例12: test_weakly_connected_component_subgraphs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def test_weakly_connected_component_subgraphs(self):
        wcc = nx.weakly_connected_component_subgraphs
        cc = nx.connected_component_subgraphs
        for G, C in self.gc:
            U = G.to_undirected()
            w = {frozenset(g) for g in wcc(G)}
            c = {frozenset(g) for g in cc(U)}
            assert_equal(w, c) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_weakly_connected.py

示例13: is_forest

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def is_forest(G):
    """
    Returns True if `G` is a forest.

    A forest is a graph with no undirected cycles.

    For directed graphs, `G` is a forest if the underlying graph is a forest.
    The underlying graph is obtained by treating each directed edge as a single
    undirected edge in a multigraph.

    Parameters
    ----------
    G : graph
        The graph to test.

    Returns
    -------
    b : bool
        A boolean that is True if `G` is a forest.

    Notes
    -----
    In another convention, a directed forest is known as a *polyforest* and
    then *forest* corresponds to a *branching*.

    See Also
    --------
    is_branching

    """
    if len(G) == 0:
        raise nx.exception.NetworkXPointlessConcept('G has no nodes.')

    if G.is_directed():
        components = nx.weakly_connected_component_subgraphs
    else:
        components = nx.connected_component_subgraphs

    return all(len(c) - 1 == c.number_of_edges() for c in components(G)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:41,代码来源:recognition.py

示例14: test_connected_raise

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def test_connected_raise(self):
        G = nx.Graph()
        assert_raises(NetworkXNotImplemented, nx.weakly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.number_weakly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.is_weakly_connected, G)
        # deprecated
        assert_raises(NetworkXNotImplemented, nx.weakly_connected_component_subgraphs, G) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_weakly_connected.py

示例15: prep_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 别名]
def prep_graph(G, relabel=True, del_self_loops=True, maincc=True):
    r"""
    Preprocess a graphs according to the parameters provided.
    By default the (digraphs) graphs are restricted to their main (weakly) connected component.
    Trying to embed graphs with several CCs may cause some algorithms to put them infinitely far away.

    Parameters
    ----------
    G : graph
        A NetworkX graph
    relabel : bool, optional
        Determines if the nodes are relabeled with consecutive integers 0..N
    del_self_loops : bool, optional
        Determines if self loops should be deleted from the graph. Default is True.
    maincc : bool, optional
        Determines if the graphs should be restricted to the main connected component or not. Default is True.

    Returns
    -------
    G : graph
       A preprocessed NetworkX graph
    Ids : list of tuples
       A list of (OldNodeID, NewNodeID). Returns None if relabel=False.
    """
    # Remove self loops
    if del_self_loops:
        G.remove_edges_from(G.selfloop_edges())

    # Restrict graph to its main connected component
    if maincc:
        if G.is_directed():
            Gcc = max(nx.weakly_connected_component_subgraphs(G), key=len)
        else:
            Gcc = max(nx.connected_component_subgraphs(G), key=len)
    else:
        Gcc = G

    # Relabel graph nodes in 0...N
    if relabel:
        Grl = nx.convert_node_labels_to_integers(Gcc, first_label=0, ordering='sorted')
        # A list of (oldNodeID, newNodeID)
        ids = list(zip(sorted(Gcc.nodes), sorted(Grl.nodes)))
        return Grl, ids
    else:
        return Gcc, None 
开发者ID:Dru-Mara,项目名称:EvalNE,代码行数:47,代码来源:preprocess.py


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