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


Python networkx.node_connected_component方法代碼示例

本文整理匯總了Python中networkx.node_connected_component方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.node_connected_component方法的具體用法?Python networkx.node_connected_component怎麽用?Python networkx.node_connected_component使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.node_connected_component方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: remove_cc_with_cycles

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def remove_cc_with_cycles(DG):
    # remove pairend links and unitig links (unoriented)
    edges_to_remove = []
    for edge in DG.edges.data():
        if edge[2]['type'] == '-1M':
            edges_to_remove.append(edge)
            
    for edge in edges_to_remove:
        DG.remove_edge(edge[0],edge[1])
    cycles = list(nx.simple_cycles(DG))
    # sys.stderr.write(f" removed {len(cycles)} cycles\n")    #DEB
    
    # tmpnb=0                                         #DEB
    G=nx.Graph(DG)
    for nodes in cycles:
        first_node_in_cycle = nodes[0]              # get the first node, the other ones in the cycle are in the same CC
        # remove the whole CC:
        CC_with_cycle = nx.node_connected_component(G, first_node_in_cycle)
        for node_id in CC_with_cycle:
            if node_id in DG.nodes():
                # tmpnb+=1                            #DEB
                DG.remove_node(node_id)
    # sys.stderr.write(f" removed {tmpnb} nodes\n")   #DEB 
開發者ID:GATB,項目名稱:DiscoSnp,代碼行數:25,代碼來源:K3000_gfa_post_treatment.py

示例2: add_ccs

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def add_ccs(self):
    curr = set(self.viewer.state.layers['seg'].segments)
    for sid in self.viewer.state.layers['seg'].segments:
      if sid in self.graph:
        curr |= set(nx.node_connected_component(self.graph, sid))

    self.update_segments(curr) 
開發者ID:google,項目名稱:ffn,代碼行數:9,代碼來源:proofreading.py

示例3: pick_connected_component

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def pick_connected_component(G):
    node_list = nx.node_connected_component(G,0)
    return G.subgraph(node_list) 
開發者ID:JiaxuanYou,項目名稱:graph-generation,代碼行數:5,代碼來源:utils.py

示例4: get_connected_nodes

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def get_connected_nodes(self, node):
        """Get the connected nodes of the given node"""
        with self.__lock:
            return nx.node_connected_component(self.networkx_graph, node) 
開發者ID:HaaLeo,項目名稱:swarmlib,代碼行數:6,代碼來源:tsp_graph.py

示例5: remove_cc

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def remove_cc(graph, u):
  graph.remove_nodes_from(nx.node_connected_component(graph, u)) 
開發者ID:andrewowens,項目名稱:multisensory,代碼行數:4,代碼來源:util.py

示例6: test_node_connected_components

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def test_node_connected_components(self):
        ncc = nx.node_connected_component
        G = self.grid
        C = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
        assert_equal(ncc(G, 1), C) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:7,代碼來源:test_connected.py

示例7: test_connected_raise

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def test_connected_raise(self):
        assert_raises(NetworkXNotImplemented, nx.connected_components, self.DG)
        assert_raises(NetworkXNotImplemented, nx.number_connected_components, self.DG)
        assert_raises(NetworkXNotImplemented, nx.connected_component_subgraphs, self.DG)
        assert_raises(NetworkXNotImplemented, nx.node_connected_component, self.DG,1)
        assert_raises(NetworkXNotImplemented, nx.is_connected, self.DG)
        assert_raises(nx.NetworkXPointlessConcept, nx.is_connected, nx.Graph()) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:9,代碼來源:test_connected.py

示例8: test_node_connected_components

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def test_node_connected_components(self):
        ncc = nx.node_connected_component
        G = self.grid
        C = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
        assert_equal(ncc(G, 1), C)

    # deprecated 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:9,代碼來源:test_connected.py

示例9: test_connected_raise

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def test_connected_raise(self):
        assert_raises(NetworkXNotImplemented, nx.connected_components, self.DG)
        assert_raises(NetworkXNotImplemented, nx.number_connected_components, self.DG)
        assert_raises(NetworkXNotImplemented, nx.node_connected_component, self.DG, 1)
        assert_raises(NetworkXNotImplemented, nx.is_connected, self.DG)
        assert_raises(nx.NetworkXPointlessConcept, nx.is_connected, nx.Graph())
        # deprecated
        assert_raises(NetworkXNotImplemented, nx.connected_component_subgraphs, self.DG) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:10,代碼來源:test_connected.py

示例10: next

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import node_connected_component [as 別名]
def next(self, states):
        """ICM between two first samples in the first two input states."""

        if len(states) > 2:
            raise ValueError("exactly two input states required")

        inp1, inp2 = states
        bqm = inp1.problem

        ss1 = inp1.samples.change_vartype(dimod.BINARY, inplace=False)
        ss2 = inp2.samples.change_vartype(dimod.BINARY, inplace=False)

        # sanity check: we operate on the same set of variables
        if ss1.variables ^ ss2.variables:
            raise ValueError("input samples not over the same set of variables")

        # reorder variables, if necessary
        # (use sequence comparison, not set)
        variables = list(ss1.variables)
        if ss2.variables != variables:
            reorder = [ss2.variables.index(v) for v in variables]
            record = ss2.record[:, reorder]
            ss2 = dimod.SampleSet(record, variables, ss2.info, ss2.vartype)

        # samples' symmetric difference (XOR)
        # (form clusters of input variables with opposite values)
        sample1 = ss1.record.sample[0]
        sample2 = ss2.record.sample[0]
        symdiff = sample1 ^ sample2

        # for cluster detection we'll use a reduced problem graph
        graph = bqm.to_networkx_graph()
        # note: instead of numpy mask indexing of `notcluster`, we enumerate
        # non-cluster variables manually to avoid conversion of potentially
        # unhashable variable names to numpy types
        notcluster = [v for v, d in zip(variables, symdiff) if d == 0]
        graph.remove_nodes_from(notcluster)

        # pick a random variable that belongs to a cluster, then select the cluster
        node = self.random.choice(list(graph.nodes))
        cluster = nx.node_connected_component(graph, node)

        # flip variables from `cluster` in both input samples
        flipper = np.array([1 if v in cluster else 0 for v in variables])
        ss1.record.sample[0] ^= flipper
        ss2.record.sample[0] ^= flipper

        # change vartype back to input's type
        ss1.change_vartype(inp1.samples.vartype)
        ss2.change_vartype(inp2.samples.vartype)

        # update sampleset's energies
        ss1.record.energy = bqm.energies(ss1)
        ss2.record.energy = bqm.energies(ss2)

        return States(inp1.updated(samples=ss1), inp2.updated(samples=ss2)) 
開發者ID:dwavesystems,項目名稱:dwave-hybrid,代碼行數:58,代碼來源:composers.py


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