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


Python networkx.disjoint_union方法代码示例

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


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

示例1: draw_match

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def draw_match(GA, GB, pairings, size=10):
    G = nx.disjoint_union(GA, GB)
    for i, jj in enumerate(pairings):
        j = len(GA) + jj
        if G.node[i]['label'] == G.node[j]['label']:
            G.add_edge(i, j, label=i, nesting=True)
    draw_graph(
        G,
        size=size,
        vertex_border=False,
        vertex_size=400,
        edge_label=None,
        edge_alpha=.2,
        dark_edge_color='label',
        dark_edge_dotted=False,
        dark_edge_alpha=1,
        colormap='Set2',
        ignore_for_layout='nesting')


# ----------------------------------------------------------------------------- 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:23,代码来源:__init__.py

示例2: test_white_harary_1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_white_harary_1():
    # Figure 1b white and harary (2001)
    # # http://eclectic.ss.uci.edu/~drwhite/sm-w23.PDF
    # A graph with high adhesion (edge connectivity) and low cohesion
    # (vertex connectivity)
    G = nx.disjoint_union(nx.complete_graph(4), nx.complete_graph(4))
    G.remove_node(7)
    for i in range(4, 7):
        G.add_edge(0, i)
    G = nx.disjoint_union(G, nx.complete_graph(4))
    G.remove_node(G.order() - 1)
    for i in range(7, 10):
        G.add_edge(0, i)
    for flow_func in flow_funcs:
        assert_equal(1, nx.node_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
        assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:20,代码来源:test_connectivity.py

示例3: test_degree_relative_to_subgraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_degree_relative_to_subgraph(self, dim):
        """Test that function removes nodes of small degree relative to the subgraph,
        not relative to the entire graph. This is done by creating an unbalanced barbell graph,
        with one "bell" larger than the other. The input subgraph is the small bell (a clique) plus
        a node from the larger bell. The function should remove only the node from the larger
        bell, since this has a low degree within the subgraph, despite having high degree overall"""
        g = nx.disjoint_union(nx.complete_graph(dim), nx.complete_graph(dim + 1))
        g.add_edge(dim, dim - 1)
        subgraph = list(range(dim + 1))
        assert clique.shrink(subgraph, g) == list(range(dim)) 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:12,代码来源:test_clique.py

示例4: __iadd__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def __iadd__(self, other):
        """Extend atoms object by appending atoms from *other*."""
        if isinstance(other, ase.Atom):
            other = self.__class__([other])

        n1 = len(self)
        n2 = len(other)

        for name, a1 in self.arrays.items():
            a = np.zeros((n1 + n2, ) + a1.shape[1:], a1.dtype)
            a[:n1] = a1
            if name == 'masses':
                a2 = other.get_masses()
            else:
                a2 = other.arrays.get(name)
            if a2 is not None:
                a[n1:] = a2
            self.arrays[name] = a

        for name, a2 in other.arrays.items():
            if name in self.arrays:
                continue
            a = np.empty((n1 + n2, ) + a2.shape[1:], a2.dtype)
            a[n1:] = a2
            if name == 'masses':
                a[:n1] = self.get_masses()[:n1]
            else:
                a[:n1] = 0

            self.set_array(name, a)

        if isinstance(other, Gratoms):
            if isinstance(self._graph, nx.MultiGraph) & \
               isinstance(other._graph, nx.Graph):
                other._graph = nx.MultiGraph(other._graph)

            self._graph = nx.disjoint_union(self._graph, other._graph)

        return self 
开发者ID:SUNCAT-Center,项目名称:CatKit,代码行数:41,代码来源:gratoms.py

示例5: __imul__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def __imul__(self, m):
        """In-place repeat of atoms."""
        if isinstance(m, int):
            m = (m, m, m)

        for x, vec in zip(m, self.cell):
            if x != 1 and not vec.any():
                raise ValueError(
                    'Cannot repeat along undefined lattice vector')

        M = np.product(m)
        n = len(self)

        for name, a in self.arrays.items():
            self.arrays[name] = np.tile(a, (M, ) + (1, ) * (len(a.shape) - 1))
            cgraph = self._graph.copy()

        positions = self.arrays['positions']
        i0 = 0

        for m0 in range(m[0]):
            for m1 in range(m[1]):
                for m2 in range(m[2]):
                    i1 = i0 + n
                    positions[i0:i1] += np.dot((m0, m1, m2), self.cell)
                    i0 = i1
                    if m0 + m1 + m2 != 0:
                        self._graph = nx.disjoint_union(self._graph, cgraph)

        if self.constraints is not None:
            self.constraints = [c.repeat(m, n) for c in self.constraints]

        self.cell = np.array([m[c] * self.cell[c] for c in range(3)])

        return self 
开发者ID:SUNCAT-Center,项目名称:CatKit,代码行数:37,代码来源:gratoms.py

示例6: gen_2community_ba

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def gen_2community_ba(n_range, m_range, num_graphs, inter_prob, feature_generators):
    ''' Each community is a BA graph.
    Args:
        inter_prob: probability of one node connecting to any node in the other community.
    '''

    if feature_generators is None:
        mu0 = np.zeros(10)
        mu1 = np.ones(10)
        sigma0 = np.ones(10, 10) * 0.1
        sigma1 = np.ones(10, 10) * 0.1
        fg0 = GaussianFeatureGen(mu0, sigma0)
        fg1 = GaussianFeatureGen(mu1, sigma1)
    else:
        fg0 = feature_generators[0]
        fg1 = feature_generators[1] if len(feature_generators) > 1 else feature_generators[0]

    graphs1 = []
    graphs2 = []
    #for (i1, i2) in zip(np.random.choice(n_range, num_graphs), 
    #                    np.random.choice(n_range, num_graphs)):
    #    for (j1, j2) in zip(np.random.choice(m_range, num_graphs), 
    #                        np.random.choice(m_range, num_graphs)):
    graphs0 = gen_ba(n_range, m_range, num_graphs, fg0)
    graphs1 = gen_ba(n_range, m_range, num_graphs, fg1)
    graphs = []
    for i in range(num_graphs):
        G = nx.disjoint_union(graphs0[i], graphs1[i])
        n0 = graphs0[i].number_of_nodes()
        for j in range(n0):
            if np.random.rand() < inter_prob:
                target = np.random.choice(G.number_of_nodes() - n0) + n0
                G.add_edge(j, target)
        graphs.append(G)
    return graphs 
开发者ID:RexYing,项目名称:diffpool,代码行数:37,代码来源:data.py

示例7: disjoint_union_all

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def disjoint_union_all(graphs):
    """Return the disjoint union of all graphs.

    This operation forces distinct integer node labels starting with 0
    for the first graph in the list and numbering consecutively.

    Parameters
    ----------
    graphs : list
       List of NetworkX graphs

    Returns
    -------
    U : A graph with the same type as the first graph in list

    Notes
    -----
    It is recommended that the graphs be either all directed or all undirected.

    Graph, edge, and node attributes are propagated to the union graph.
    If a graph attribute is present in multiple graphs, then the value
    from the last graph in the list with that attribute is used.
    """
    graphs = iter(graphs)
    U = next(graphs)
    for H in graphs:
        U = nx.disjoint_union(U, H)
    return U 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:30,代码来源:all.py

示例8: test_disjoint_union_multigraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_disjoint_union_multigraph():
    G=nx.MultiGraph()
    G.add_edge(0,1,key=0)
    G.add_edge(0,1,key=1)
    H=nx.MultiGraph()
    H.add_edge(2,3,key=0)
    H.add_edge(2,3,key=1)
    GH=nx.disjoint_union(G,H)
    assert_equal( set(GH) , set(G)|set(H))
    assert_equal( set(GH.edges(keys=True)) , 
                  set(G.edges(keys=True))|set(H.edges(keys=True))) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:13,代码来源:test_binary.py

示例9: test_mixed_type_disjoint_union

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_mixed_type_disjoint_union():
    G = nx.Graph()
    H = nx.MultiGraph()
    U = nx.disjoint_union(G,H) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:6,代码来源:test_binary.py

示例10: graph_example_1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def graph_example_1():
    G = nx.convert_node_labels_to_integers(nx.grid_graph([5,5]),
                                            label_attribute='labels')
    rlabels = nx.get_node_attributes(G, 'labels')
    labels = dict((v, k) for k, v in rlabels.items())

    for nodes in [(labels[(0,0)], labels[(1,0)]),
                    (labels[(0,4)], labels[(1,4)]),
                    (labels[(3,0)], labels[(4,0)]),
                    (labels[(3,4)], labels[(4,4)]) ]:
        new_node = G.order()+1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G,P)
        # Add two edges between the grid and P
        G.add_edge(new_node+1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G,K)
        # Add three edges between P and K5
        G.add_edge(new_node+2,new_node+11)
        G.add_edge(new_node+3,new_node+12)
        G.add_edge(new_node+4,new_node+13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G,K)
        nbrs = G[new_node+10]
        G.remove_node(new_node+10)
        for nbr in nbrs:
            G.add_edge(new_node+17, nbr)
        G.add_edge(new_node+16, new_node+5)

    G.name = 'Example graph for connectivity'
    return G 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:36,代码来源:test_kcutsets.py

示例11: test_white_harary_2

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_white_harary_2():
    # Figure 8 white and harary (2001)
    # # http://eclectic.ss.uci.edu/~drwhite/sm-w23.PDF
    G = nx.disjoint_union(nx.complete_graph(4), nx.complete_graph(4))
    G.add_edge(0, 4)
    # kappa <= lambda <= delta
    assert_equal(3, min(nx.core_number(G).values()))
    for flow_func in flow_funcs:
        assert_equal(1, nx.node_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
        assert_equal(1, nx.edge_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:14,代码来源:test_connectivity.py

示例12: test_white_harary1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_white_harary1():
    # Figure 1b white and harary (2001)
    # A graph with high adhesion (edge connectivity) and low cohesion
    # (node connectivity)
    G = nx.disjoint_union(nx.complete_graph(4), nx.complete_graph(4))
    G.remove_node(7)
    for i in range(4,7):
        G.add_edge(0,i)
    G = nx.disjoint_union(G, nx.complete_graph(4))
    G.remove_node(G.order()-1)
    for i in range(7,10):
        G.add_edge(0,i)
    assert_equal(1, approx.node_connectivity(G)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:15,代码来源:test_connectivity.py

示例13: disjoint_union_all

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def disjoint_union_all(graphs):
    """Returns the disjoint union of all graphs.

    This operation forces distinct integer node labels starting with 0
    for the first graph in the list and numbering consecutively.

    Parameters
    ----------
    graphs : list
       List of NetworkX graphs

    Returns
    -------
    U : A graph with the same type as the first graph in list

    Raises
    ------
    ValueError
       If `graphs` is an empty list.

    Notes
    -----
    It is recommended that the graphs be either all directed or all undirected.

    Graph, edge, and node attributes are propagated to the union graph.
    If a graph attribute is present in multiple graphs, then the value
    from the last graph in the list with that attribute is used.
    """
    if not graphs:
        raise ValueError('cannot apply disjoint_union_all to an empty list')
    graphs = iter(graphs)
    U = next(graphs)
    for H in graphs:
        U = nx.disjoint_union(U, H)
    return U 
开发者ID:holzschu,项目名称:Carnets,代码行数:37,代码来源:all.py

示例14: test_disjoint_union_multigraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_disjoint_union_multigraph():
    G = nx.MultiGraph()
    G.add_edge(0, 1, key=0)
    G.add_edge(0, 1, key=1)
    H = nx.MultiGraph()
    H.add_edge(2, 3, key=0)
    H.add_edge(2, 3, key=1)
    GH = nx.disjoint_union(G, H)
    assert_equal(set(GH), set(G) | set(H))
    assert_equal(set(GH.edges(keys=True)),
                 set(G.edges(keys=True)) | set(H.edges(keys=True))) 
开发者ID:holzschu,项目名称:Carnets,代码行数:13,代码来源:test_binary.py

示例15: test_mixed_type_disjoint_union

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import disjoint_union [as 别名]
def test_mixed_type_disjoint_union():
    G = nx.Graph()
    H = nx.MultiGraph()
    U = nx.disjoint_union(G, H) 
开发者ID:holzschu,项目名称:Carnets,代码行数:6,代码来源:test_binary.py


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