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


Python networkx.NetworkXNoCycle方法代码示例

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


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

示例1: test_prev_explored

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_prev_explored(self):
        # https://github.com/networkx/networkx/issues/2323

        G = nx.DiGraph()
        G.add_edges_from([(1, 0), (2, 0), (1, 2), (2, 1)])
        assert_raises(nx.NetworkXNoCycle, find_cycle, G, source=0)
        x = list(nx.find_cycle(G, 1))
        x_ = [(1, 2), (2, 1)]
        assert_equal(x, x_)

        x = list(nx.find_cycle(G, 2))
        x_ = [(2, 1), (1, 2)]
        assert_equal(x, x_)

        x = list(nx.find_cycle(G))
        x_ = [(1, 2), (2, 1)]
        assert_equal(x, x_) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_cycles.py

示例2: _detect_cycles

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def _detect_cycles(graph):
    """Detect if there are cycles between the groups

    Raise a DeploymentGroupCycleError if there are any circular
    dependencies
    """
    LOG.debug("Detecting cycles in graph")
    circ_deps = []
    try:
        circ_deps = list(nx.find_cycle(graph))
    except nx.NetworkXNoCycle:
        LOG.info('There are no cycles detected in the graph')
        pass

    if circ_deps:
        involved_nodes = set()
        # a value in this list is like: ('group1', 'group2')
        for dep in circ_deps:
            involved_nodes.update(dep)
        raise DeploymentGroupCycleError(
            "The following are involved in a circular dependency:"
            " {}".format(", ".join(involved_nodes))
        ) 
开发者ID:airshipit,项目名称:shipyard,代码行数:25,代码来源:deployment_group_manager.py

示例3: test_graph_nocycle

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_graph_nocycle(self):
        G = nx.Graph(self.edges)
        assert_raises(nx.exception.NetworkXNoCycle, find_cycle, G, self.nodes) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_cycles.py

示例4: test_multidigraph_original

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_multidigraph_original(self):
        # Node 2 doesn't need to be searched again from visited from 4.
        # The goal here is to cover the case when 2 to be researched from 4,
        # when 4 is visited from the first time (so we must make sure that 4
        # is not visited from 2, and hence, we respect the edge orientation).
        G = nx.MultiDiGraph([(0, 1), (1, 2), (2, 3), (4, 2)])
        assert_raises(nx.exception.NetworkXNoCycle,
                      find_cycle, G, [0, 1, 2, 3, 4], orientation='original') 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_cycles.py

示例5: test_dag

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_dag(self):
        G = nx.DiGraph([(0, 1), (0, 2), (1, 2)])
        assert_raises(nx.exception.NetworkXNoCycle,
                      find_cycle, G, orientation='original')
        x = list(find_cycle(G, orientation='ignore'))
        assert_equal(x, [(0, 1, FORWARD), (1, 2, FORWARD), (0, 2, REVERSE)]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_cycles.py

示例6: test_no_cycle

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_no_cycle(self):
        # https://github.com/networkx/networkx/issues/2439

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 0), (3, 1), (3, 2)])
        assert_raises(nx.NetworkXNoCycle, find_cycle, G, source=0)
        assert_raises(nx.NetworkXNoCycle, find_cycle, G) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_cycles.py

示例7: test_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_graph(self):
        G = nx.Graph(self.edges)
        assert_raises(nx.exception.NetworkXNoCycle, find_cycle, G, self.nodes) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:5,代码来源:test_cycles.py

示例8: test_multidigraph_ignore2

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def test_multidigraph_ignore2(self):
        # Node 2 doesn't need to be searched again from visited from 4.
        # The goal here is to cover the case when 2 to be researched from 4,
        # when 4 is visited from the first time (so we must make sure that 4
        # is not visited from 2, and hence, we respect the edge orientation).
        G = nx.MultiDiGraph([(0, 1), (1, 2), (2, 3), (4, 2)])
        assert_raises(nx.exception.NetworkXNoCycle,
                      find_cycle, G, [0, 1, 2, 3, 4], orientation='original') 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:10,代码来源:test_cycles.py

示例9: construct_graph_from_nucleotides

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoCycle [as 别名]
def construct_graph_from_nucleotides(
        nucleotides: List[Nucleotide],
        incoming_nucleotides: Optional[List[Nucleotide]] = None
) -> nx.DiGraph:
    """
    Construct graph from nucleotides

    Parameters
    ----------
    nucleotides
        nucleotides
    incoming_nucleotides
        incoming nucleotides, which will be added to nucleotides to construct
        the graph, but their connections to their inbound nodes will be
        ignored

    Returns
    -------
    graph
        graph with nucleotides as vertices

    Raises
    ------
    ValueError
        if graph contains loops
    """
    graph = nx.DiGraph()
    incoming_nucleotides = incoming_nucleotides or []
    all_nucleotides = nucleotides + incoming_nucleotides
    all_nucleotides_dict = {each_nucleotide.name: each_nucleotide
                            for each_nucleotide in all_nucleotides}
    for each_nucleotide in nucleotides:
        inbound_nodes = each_nucleotide.inbound_nodes
        if not inbound_nodes:
            graph.add_node(each_nucleotide)
        nucleotide_name = each_nucleotide.name
        for each_in_node_name in inbound_nodes:
            u_node = _get_incoming_node(all_nucleotides_dict, each_in_node_name)
            v_node = all_nucleotides_dict[nucleotide_name]
            graph.add_edge(u_node, v_node)

    try:
        cycles = nx.find_cycle(graph)
        raise ValueError("Cycles in the DNA helix graph were found! "
                         "({})".format(cycles))
    except nx.NetworkXNoCycle:
        pass

    return graph 
开发者ID:audi,项目名称:nucleus7,代码行数:51,代码来源:graph_utils.py


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