本文整理汇总了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_)
示例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))
)
示例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)
示例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')
示例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)])
示例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)
示例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)
示例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')
示例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