Python networkx.NetworkXNoCycle() Examples
The following are 12
code examples of networkx.NetworkXNoCycle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: test_cycles.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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_)
Example #2
Source File: test_cycles.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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_)
Example #3
Source File: deployment_group_manager.py From shipyard with Apache License 2.0 | 6 votes |
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)) )
Example #4
Source File: test_cycles.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_graph_nocycle(self): G = nx.Graph(self.edges) assert_raises(nx.exception.NetworkXNoCycle, find_cycle, G, self.nodes)
Example #5
Source File: test_cycles.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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')
Example #6
Source File: test_cycles.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)])
Example #7
Source File: test_cycles.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #8
Source File: test_cycles.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_graph(self): G = nx.Graph(self.edges) assert_raises(nx.exception.NetworkXNoCycle, find_cycle, G, self.nodes)
Example #9
Source File: test_cycles.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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')
Example #10
Source File: test_cycles.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)])
Example #11
Source File: test_cycles.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #12
Source File: graph_utils.py From nucleus7 with Mozilla Public License 2.0 | 4 votes |
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