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


Python networkx.compose方法代码示例

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


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

示例1: compose

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def compose(self, other: "NetworkxTree") -> None:
        """
        Compose the graph of another :class:`BaseNetworkxTree` with the graph of \
        the current instance.

        Composition is the simple union of the node sets and edge sets.
        The node sets of ``self.data`` and ``other.data`` do not need to be \
        disjoint.

        The data in ``other`` takes precedence over the data in the current instance.

        Args:
            other: Instance of :class:`BaseNetworkxTree` that will be composed \
                  with the current instance.

        Returns:
            None

        """
        self.data = nx.compose(self.data, other.data) 
开发者ID:FragileTech,项目名称:fragile,代码行数:22,代码来源:tree.py

示例2: join_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def join_graph(G1, G2, n_pert_edges):
    """ Join two graphs along matching nodes, then perturb the resulting graph.
    Args:
        G1, G2: Networkx graphs to be joined.
        n_pert_edges: number of perturbed edges.
    Returns:
        A new graph, result of merging and perturbing G1 and G2.
    """
    assert n_pert_edges > 0
    F = nx.compose(G1, G2)
    edge_cnt = 0
    while edge_cnt < n_pert_edges:
        node_1 = np.random.choice(G1.nodes())
        node_2 = np.random.choice(G2.nodes())
        F.add_edge(node_1, node_2)
        edge_cnt += 1
    return F 
开发者ID:RexYing,项目名称:gnn-model-explainer,代码行数:19,代码来源:gengraph.py

示例3: test_compose_multigraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def test_compose_multigraph():
    G=nx.MultiGraph()
    G.add_edge(1,2,key=0)
    G.add_edge(1,2,key=1)
    H=nx.MultiGraph()
    H.add_edge(3,4,key=0)
    H.add_edge(3,4,key=1)
    GH=nx.compose(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)))
    H.add_edge(1,2,key=2)
    GH=nx.compose(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,代码行数:18,代码来源:test_binary.py

示例4: test_compose_multigraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def test_compose_multigraph():
    G = nx.MultiGraph()
    G.add_edge(1, 2, key=0)
    G.add_edge(1, 2, key=1)
    H = nx.MultiGraph()
    H.add_edge(3, 4, key=0)
    H.add_edge(3, 4, key=1)
    GH = nx.compose(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)))
    H.add_edge(1, 2, key=2)
    GH = nx.compose(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,代码行数:18,代码来源:test_binary.py

示例5: create_from_pd

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def create_from_pd(self, pd_graph, nx_graph=None, directional=False):

        nodes_df = pd_graph.get_nodes()
        edges_df = pd_graph.get_edges()

        # Create graph from edgelist dataframes
        if nx_graph is None:
            if directional:
                nx_graph = nx.DiGraph()
            else:
                nx_graph = nx.Graph()

        for key in edges_df:
            new_graph = nx.from_pandas_edgelist(
                edges_df[key], source="Source", target="Target", edge_attr=True)

            nx_graph = nx.compose(nx_graph, new_graph)

        # Add node attributes
        for key in nodes_df:
            df = nodes_df[key]

            for index, row in df.iterrows():
                _id = row["Id"]
                node = nx_graph.node[_id]

                for attr in row.keys():
                    node[attr] = row[attr]

        return nx_graph 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:32,代码来源:exportnx.py

示例6: random_powerlaw

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def random_powerlaw():
    g = networkx.DiGraph()
    t = networkx.random_powerlaw_tree(500, gamma=3, tries=1000, seed=160290)
    return networkx.compose(g, t) 
开发者ID:FragileTech,项目名称:fragile,代码行数:6,代码来源:test_tree.py

示例7: test_compose_not_crashes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def test_compose_not_crashes(self, tree):
        other = NetworkxTree()
        other.data = small_tree()
        tree.compose(other) 
开发者ID:FragileTech,项目名称:fragile,代码行数:6,代码来源:test_tree.py

示例8: collect_tasks

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def collect_tasks(path, folders, matrix_base_dir, channels=None, steps=0, test=False,
                  max_downstream=5, variant_config_files=None, platform_filters=None,
                  clobber_sections_file=None, append_sections_file=None, pass_throughs=None,
                  skip_existing=True):
    # runs = ['test']
    # not testing means build and test
    # if not test:
    #     runs.insert(0, 'build')
    runs = ['build']

    task_graph = nx.DiGraph()
    parsed_cli_args = _parse_python_numpy_from_pass_throughs(pass_throughs)
    config = conda_build.api.Config(clobber_sections_file=clobber_sections_file,
                                    append_sections_file=append_sections_file,
                                    skip_existing=skip_existing, **parsed_cli_args)
    platform_filters = ensure_list(platform_filters) if platform_filters else ['*']
    for run in runs:
        platforms = parse_platforms(matrix_base_dir, run, platform_filters)
        # loop over platforms here because each platform may have different dependencies
        # each platform will be submitted with a different label

        for platform in platforms:
            index_key = '-'.join([platform['platform'], str(platform['arch'])])
            config.variants = get_package_variants(path, config, platform.get('variants'))
            config.channel_urls = channels or []
            config.variant_config_files = variant_config_files or []
            conda_resolve = Resolve(get_build_index(subdir=index_key,
                                                    bldpkgs_dir=config.bldpkgs_dir, channel_urls=channels)[0])
            # this graph is potentially different for platform and for build or test mode ("run")
            g = construct_graph(path, worker=platform, folders=folders, run=run,
                                matrix_base_dir=matrix_base_dir, conda_resolve=conda_resolve,
                                config=config)
            # Apply the build label to any nodes that need (re)building or testing
            expand_run(g, config=config.copy(), conda_resolve=conda_resolve, worker=platform,
                       run=run, steps=steps, max_downstream=max_downstream, recipes_dir=path,
                       matrix_base_dir=matrix_base_dir)
            # merge this graph with the main one
            task_graph = nx.compose(task_graph, g)
    collapse_noarch_python_nodes(task_graph)
    return task_graph 
开发者ID:conda,项目名称:conda-concourse-ci,代码行数:42,代码来源:execute.py

示例9: combine_2_graphs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def combine_2_graphs(graph1, graph2):
    """
    Combine two graphs into one. Do this by recognising common nodes between the two.

    Args:
        graph1: Graph to compare
        graph2: Graph to compare

    Returns:
        Combined graph
    """

    for node, data in graph1.nodes(data=True):
        if graph2.has_node(node):
            data2 = graph2.nodes[node]
            if data2 != data:
                raise ValueError((f'Found non-matching node properties for node {node} '
                                  f'between graphs {graph1} and {graph2}:\n'
                                  f'In graph {graph1}: {data}\n'
                                  f'In graph {graph2}: {data2}'))

    for sender, receiver, keys, data in graph1.edges(data=True, keys=True):
        if graph2.has_edge(sender, receiver, keys):
            data2 = graph2.edges[sender, receiver, keys]
            if data2 != data:
                raise ValueError((f'Found non-matching edge properties for edge {sender, receiver, keys} '
                                  f'between graphs {graph1} and {graph2}:\n'
                                  f'In graph {graph1}: {data}\n'
                                  f'In graph {graph2}: {data2}'))

    return nx.compose(graph1, graph2) 
开发者ID:graknlabs,项目名称:kglib,代码行数:33,代码来源:queries_to_graph.py

示例10: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def setUp(self):

        self.T1 = self.graph()

        self.T2 = self.graph()
        self.T2.add_node(1)

        self.T3 = self.graph()
        self.T3.add_nodes_from(range(5))
        edges = [(i,i+1) for i in range(4)]
        self.T3.add_edges_from(edges)

        self.T5 = self.multigraph()
        self.T5.add_nodes_from(range(5))
        edges = [(i,i+1) for i in range(4)]
        self.T5.add_edges_from(edges)

        self.T6 = self.graph()
        self.T6.add_nodes_from([6,7])
        self.T6.add_edge(6,7)

        self.F1 = nx.compose(self.T6, self.T3)

        self.N4 = self.graph()
        self.N4.add_node(1)
        self.N4.add_edge(1,1)

        self.N5 = self.graph()
        self.N5.add_nodes_from(range(5))

        self.N6 = self.graph()
        self.N6.add_nodes_from(range(3))
        self.N6.add_edges_from([(0,1),(1,2),(2,0)])

        self.NF1 = nx.compose(self.T6,self.N6) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:37,代码来源:test_recognition.py

示例11: compose_all

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def compose_all(graphs, name=None):
    """Return the composition of all graphs.

    Composition is the simple union of the node sets and edge sets.
    The node sets of the supplied graphs need not be disjoint.

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

    name : string
       Specify name for new graph

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

    Notes
    -----
    It is recommended that the supplied 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)
    C = next(graphs)
    for H in graphs:
        C = nx.compose(C, H, name=name)
    return C 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:34,代码来源:all.py

示例12: test_mixed_type_compose

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

示例13: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import compose [as 别名]
def setUp(self):

        self.T1 = self.graph()

        self.T2 = self.graph()
        self.T2.add_node(1)

        self.T3 = self.graph()
        self.T3.add_nodes_from(range(5))
        edges = [(i, i + 1) for i in range(4)]
        self.T3.add_edges_from(edges)

        self.T5 = self.multigraph()
        self.T5.add_nodes_from(range(5))
        edges = [(i, i + 1) for i in range(4)]
        self.T5.add_edges_from(edges)

        self.T6 = self.graph()
        self.T6.add_nodes_from([6, 7])
        self.T6.add_edge(6, 7)

        self.F1 = nx.compose(self.T6, self.T3)

        self.N4 = self.graph()
        self.N4.add_node(1)
        self.N4.add_edge(1, 1)

        self.N5 = self.graph()
        self.N5.add_nodes_from(range(5))

        self.N6 = self.graph()
        self.N6.add_nodes_from(range(3))
        self.N6.add_edges_from([(0, 1), (1, 2), (2, 0)])

        self.NF1 = nx.compose(self.T6, self.N6) 
开发者ID:holzschu,项目名称:Carnets,代码行数:37,代码来源:test_recognition.py

示例14: compose_all

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

    Composition is the simple union of the node sets and edge sets.
    The node sets of the supplied graphs need not be disjoint.

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

    Returns
    -------
    C : 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 supplied 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 compose_all to an empty list')
    graphs = iter(graphs)
    C = next(graphs)
    for H in graphs:
        C = nx.compose(C, H)
    return C 
开发者ID:holzschu,项目名称:Carnets,代码行数:38,代码来源:all.py

示例15: test_mixed_type_compose

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


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