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


Python networkx.lollipop_graph方法代码示例

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


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

示例1: test_correct_resize

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_correct_resize(self):
        """Test if function correctly resizes on a fixed example where the ideal resizing is
        known. The example is a lollipop graph of 6 fully connected nodes and 2 nodes on the
        lollipop stick. An edge between node zero and node ``dim - 1`` (the lollipop node
        connecting to the stick) is removed and a starting subgraph of nodes ``[2, 3, 4, 5,
        6]`` is selected. The objective is to add-on 1 and 2 nodes and remove 1 node."""
        dim = 6
        g = nx.lollipop_graph(dim, 2)
        g.remove_edge(0, dim - 1)

        s = [2, 3, 4, 5, 6]
        min_size = 4
        max_size = 7

        ideal = {
            4: [2, 3, 4, 5],
            5: [2, 3, 4, 5, 6],
            6: [1, 2, 3, 4, 5, 6],
            7: [0, 1, 2, 3, 4, 5, 6],
        }
        resized = subgraph.resize(s, g, min_size, max_size)

        assert ideal == resized 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:25,代码来源:test_subgraph.py

示例2: test_swap_degree

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_swap_degree(self, dim):
        """Test if function performs correct swap operation when degree-based node selection is
        used. Input graph is a lollipop graph, consisting of a fully connected graph with a
        single additional node connected to just one of the nodes in the graph. Additionally,
        a connection between node ``0`` and ``dim - 1`` is removed as well as a connection
        between node ``0`` and ``dim - 2``. A clique of the first ``dim - 2`` nodes is then
        input. In this case, C1 consists of nodes ``dim - 1`` and ``dim - 2``. However,
        node ``dim - 1`` has greater degree due to the extra node in the lollipop graph. This
        test confirms that the resultant swap is performed correctly."""
        graph = nx.lollipop_graph(dim, 1)
        graph.remove_edge(0, dim - 1)
        graph.remove_edge(0, dim - 2)
        s = list(range(dim - 2))
        result = set(clique.swap(s, graph, node_select="degree"))
        expected = set(range(1, dim - 2)) | {dim - 1}
        assert result == expected 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:18,代码来源:test_clique.py

示例3: _gen_lollipop

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def _gen_lollipop(self, n):
        for _ in range(n):
            num_v = np.random.randint(self.min_num_v, self.max_num_v)
            path_len = np.random.randint(2, num_v // 2)
            g = nx.lollipop_graph(m=num_v - path_len, n=path_len)
            self.graphs.append(g)
            self.labels.append(3) 
开发者ID:dmlc,项目名称:dgl,代码行数:9,代码来源:minigc.py

示例4: test_expected_growth

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_expected_growth(self):
        """Test if function performs a growth and swap phase, followed by another growth and
        attempted swap phase. This is carried out by starting with a 4+1 node lollipop graph,
        adding a connection from node 4 to node 2 and starting with the [3, 4] clique. The local
        search algorithm should first grow to [2, 3, 4] and then swap to either [0, 2, 3] or [1,
        2, 3], and then grow again to [0, 1, 2, 3] and being unable to swap, hence returning [0,
        1, 2, 3]"""

        graph = nx.lollipop_graph(4, 1)
        graph.add_edge(4, 2)

        c = [3, 4]
        result = clique.search(c, graph, iterations=100)
        assert result == [0, 1, 2, 3] 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:16,代码来源:test_clique.py

示例5: test_grow_maximal_degree

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_grow_maximal_degree(self, dim):
        """Test if function grows to expected maximal graph when degree-based node selection is
        used. The chosen graph is a fully connected graph with only the final node being
        connected to an additional node. Furthermore, the ``dim - 2`` node is disconnected from
        the ``dim - 1`` node. Starting from the first ``dim - 3`` nodes, one can either add in
        the ``dim - 2`` node or the ``dim - 1`` node. The ``dim - 1`` node has a higher degree
        due to the lollipop graph structure, and hence should be selected."""
        graph = nx.lollipop_graph(dim, 1)
        graph.remove_edge(dim - 2, dim - 1)
        s = set(range(dim - 2))
        target = s | {dim - 1}
        assert set(clique.grow(s, graph, node_select="degree")) == target 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:14,代码来源:test_clique.py

示例6: test_is_output_clique

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_is_output_clique(self, dim):
        """Test that the output subgraph is a valid clique, in this case the maximum clique
        in a lollipop graph"""
        graph = nx.lollipop_graph(dim, dim)
        subgraph = list(range(2 * dim))  # subgraph is the entire graph
        resized = clique.shrink(subgraph, graph)
        assert clique.is_clique(graph.subgraph(resized))
        assert resized == list(range(dim)) 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:10,代码来源:test_clique.py

示例7: test_correct_c_0

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_correct_c_0(self, dim):
        """Tests that :math:`c_0` is generated correctly for the lollipop graph"""
        g = nx.lollipop_graph(dim, 1)
        s = set(range(int(dim / 2)))
        res = set(clique.c_0(s, g))

        assert res not in s
        assert {dim + 1} not in res
        assert res | s == set(range(dim)) 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:11,代码来源:test_clique.py

示例8: random_layout

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def random_layout(G, dim=2, scale=1., center=None):
    """Position nodes uniformly at random.

    For every node, a position is generated by choosing each of dim
    coordinates uniformly at random on the default interval [0.0, 1.0),
    or on an interval of length `scale` centered at `center`.

    NumPy (http://scipy.org) is required for this function.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
       A position will be assigned to every node in G.

    dim : int
       Dimension of layout.

    scale : float (default 1)
        Scale factor for positions

    center : array-like (default scale*0.5 in each dim)
       Coordinate around which to center the layout.

    Returns
    -------
    pos : dict
       A dictionary of positions keyed by node

    Examples
    --------
    >>> G = nx.lollipop_graph(4, 3)
    >>> pos = nx.random_layout(G)
    """
    import numpy as np

    shape = (len(G), dim)
    pos = np.random.random(shape) * scale
    if center is not None:
        pos += np.asarray(center) - 0.5 * scale
    return dict(zip(G, pos)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:42,代码来源:layout.py

示例9: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def setUp(self):
        G1 = cnlti(nx.grid_2d_graph(2, 2), first_label=0, ordering="sorted")
        G2 = cnlti(nx.lollipop_graph(3, 3), first_label=4, ordering="sorted")
        G3 = cnlti(nx.house_graph(), first_label=10, ordering="sorted")
        self.G = nx.union(G1, G2)
        self.G = nx.union(self.G, G3)
        self.DG = nx.DiGraph([(1, 2), (1, 3), (2, 3)])
        self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1)

        self.gc = []
        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (2, 8), (3, 4), (3, 7), (4, 5),
                          (5, 3), (5, 6), (7, 4), (7, 6), (8, 1), (8, 7)])
        C = [[3, 4, 5, 7], [1, 2, 8], [6]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (1, 3), (1, 4), (4, 2), (3, 4), (2, 3)])
        C = [[2, 3, 4],[1]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (3, 2), (2, 1)])
        C = [[1, 2, 3]]
        self.gc.append((G,C))

        # Eppstein's tests
        G = nx.DiGraph({0:[1], 1:[2, 3], 2:[4, 5], 3:[4, 5], 4:[6], 5:[], 6:[]})
        C = [[0], [1], [2],[ 3], [4], [5], [6]]
        self.gc.append((G,C))

        G = nx.DiGraph({0:[1], 1:[2, 3, 4], 2:[0, 3], 3:[4], 4:[3]})
        C = [[0, 1, 2], [3, 4]]
        self.gc.append((G, C)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:36,代码来源:test_connected.py

示例10: __init__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def __init__(self):
        # G1 is a disconnected graph
        self.G1 = nx.Graph()
        self.G1.add_nodes_from([1, 2, 3])
        # G2 is a cycle graph
        self.G2 = nx.cycle_graph(4)
        # G3 is the triangle graph with one additional edge
        self.G3 = nx.lollipop_graph(3, 1) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_efficiency.py

示例11: test_maximal_by_cardinality

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def test_maximal_by_cardinality(self):
        """Tests that the maximal clique is computed according to maximum
        cardinality of the sets.

        For more information, see pull request #1531.

        """
        G = nx.complete_graph(5)
        G.add_edge(4, 5)
        clique = max_clique(G)
        assert_greater(len(clique), 1)

        G = nx.lollipop_graph(30, 2)
        clique = max_clique(G)
        assert_greater(len(clique), 2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:17,代码来源:test_clique.py

示例12: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def setUp(self):
        G1 = cnlti(nx.grid_2d_graph(2, 2), first_label=0, ordering="sorted")
        G2 = cnlti(nx.lollipop_graph(3, 3), first_label=4, ordering="sorted")
        G3 = cnlti(nx.house_graph(), first_label=10, ordering="sorted")
        self.G = nx.union(G1, G2)
        self.G = nx.union(self.G, G3)
        self.DG = nx.DiGraph([(1, 2), (1, 3), (2, 3)])
        self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1)

        self.gc = []
        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (2, 8), (3, 4), (3, 7), (4, 5),
                          (5, 3), (5, 6), (7, 4), (7, 6), (8, 1), (8, 7)])
        C = [[3, 4, 5, 7], [1, 2, 8], [6]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (1, 3), (1, 4), (4, 2), (3, 4), (2, 3)])
        C = [[2, 3, 4], [1]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (3, 2), (2, 1)])
        C = [[1, 2, 3]]
        self.gc.append((G, C))

        # Eppstein's tests
        G = nx.DiGraph({0: [1], 1: [2, 3], 2: [4, 5], 3: [4, 5], 4: [6], 5: [], 6: []})
        C = [[0], [1], [2], [3], [4], [5], [6]]
        self.gc.append((G, C))

        G = nx.DiGraph({0: [1], 1: [2, 3, 4], 2: [0, 3], 3: [4], 4: [3]})
        C = [[0, 1, 2], [3, 4]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        C = []
        self.gc.append((G, C)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:40,代码来源:test_connected.py

示例13: random_layout

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def random_layout(G, center=None, dim=2):
    """Position nodes uniformly at random in the unit square.

    For every node, a position is generated by choosing each of dim
    coordinates uniformly at random on the interval [0.0, 1.0).

    NumPy (http://scipy.org) is required for this function.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Examples
    --------
    >>> G = nx.lollipop_graph(4, 3)
    >>> pos = nx.random_layout(G)

    """
    import numpy as np

    G, center = _process_params(G, center, dim)
    shape = (len(G), dim)
    pos = np.random.random(shape) + center
    pos = pos.astype(np.float32)
    pos = dict(zip(G, pos))

    return pos 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:41,代码来源:layout.py

示例14: generate_adjlist

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def generate_adjlist(G, delimiter = ' '):
    """Generate a single line of the graph G in adjacency list format.

    Parameters
    ----------
    G : NetworkX graph

    delimiter : string, optional
       Separator for node labels

    Returns
    -------
    lines : string
        Lines of data in adjlist format.

    Examples
    --------
    >>> G = nx.lollipop_graph(4, 3)
    >>> for line in nx.generate_adjlist(G):
    ...     print(line)
    0 1 2 3
    1 2 3
    2 3
    3 4
    4 5
    5 6
    6

    See Also
    --------
    write_adjlist, read_adjlist

    """
    directed=G.is_directed()
    seen=set()
    for s,nbrs in G.adjacency_iter():
        line = make_str(s)+delimiter
        for t,data in nbrs.items():
            if not directed and t in seen:
                continue
            if G.is_multigraph():
                for d in data.values():
                    line += make_str(t) + delimiter
            else:
                line += make_str(t) + delimiter
        if not directed:
            seen.add(s)
        yield line[:-len(delimiter)] 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:50,代码来源:adjlist.py

示例15: generate_adjlist

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import lollipop_graph [as 别名]
def generate_adjlist(G, delimiter=' '):
    """Generate a single line of the graph G in adjacency list format.

    Parameters
    ----------
    G : NetworkX graph

    delimiter : string, optional
       Separator for node labels

    Returns
    -------
    lines : string
        Lines of data in adjlist format.

    Examples
    --------
    >>> G = nx.lollipop_graph(4, 3)
    >>> for line in nx.generate_adjlist(G):
    ...     print(line)
    0 1 2 3
    1 2 3
    2 3
    3 4
    4 5
    5 6
    6

    See Also
    --------
    write_adjlist, read_adjlist

    """
    directed = G.is_directed()
    seen = set()
    for s, nbrs in G.adjacency():
        line = make_str(s) + delimiter
        for t, data in nbrs.items():
            if not directed and t in seen:
                continue
            if G.is_multigraph():
                for d in data.values():
                    line += make_str(t) + delimiter
            else:
                line += make_str(t) + delimiter
        if not directed:
            seen.add(s)
        yield line[:-len(delimiter)] 
开发者ID:holzschu,项目名称:Carnets,代码行数:50,代码来源:adjlist.py


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