當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。