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


Python cycles.find_cycle函数代码示例

本文整理汇总了Python中pygraph.algorithms.cycles.find_cycle函数的典型用法代码示例。如果您正苦于以下问题:Python find_cycle函数的具体用法?Python find_cycle怎么用?Python find_cycle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _validate

 def _validate(self):
     # TODO: test A -> B, A -> C, B -> C
     if len(self.starters) == 0:
         return False
     if find_cycle(self._digraph):
         return False
     return True
开发者ID:flavioamieiro,项目名称:pypelinin,代码行数:7,代码来源:pipeline.py

示例2: main

def main():
    global dg2
    while find_cycle(dg2):
        dg2 = generate(8,10,directed=True)
    sweep()
    print dg2
    print toporder
开发者ID:darkzyy,项目名称:graph_algrithm,代码行数:7,代码来源:topsort.py

示例3: _check_cycles

 def _check_cycles(self):
     """
     Raise a CyclesDetectedError if a cycle is detected.
     """
     cycles = find_cycle(self.dag)
     if cycles:
         raise CyclesDetectedError(cycles, self.dag)
开发者ID:AdrienDebrie,项目名称:sequencer,代码行数:7,代码来源:model.py

示例4: testNoCycleDigraph2

 def testNoCycleDigraph2(self):
     G = pygraph.digraph()
     G.add_nodes([1,2,3])
     G.add_edge(1,2)
     G.add_edge(1,3)
     G.add_edge(2,3)
     assert find_cycle(G) == []
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-cycles.py

示例5: condorcet_completion_method

    def condorcet_completion_method(self):

        # Initialize the candidate graph
        self.rounds = []
        graph = digraph()
        graph.add_nodes(self.candidates)

        # Loop until we've considered all possible pairs
        remaining_strong_pairs = deepcopy(self.strong_pairs)
        while len(remaining_strong_pairs) > 0:
            r = {}

            # Find the strongest pair
            largest_strength = max(remaining_strong_pairs.values())
            strongest_pairs = matching_keys(remaining_strong_pairs, largest_strength)
            if len(strongest_pairs) > 1:
                r["tied_pairs"] = strongest_pairs
                strongest_pair = self.break_ties(strongest_pairs)
            else:
                strongest_pair = list(strongest_pairs)[0]
            r["pair"] = strongest_pair

            # If the pair would add a cycle, skip it
            graph.add_edge(strongest_pair)
            if len(find_cycle(graph)) > 0:
                r["action"] = "skipped"
                graph.del_edge(strongest_pair)
            else:
                r["action"] = "added"
            del remaining_strong_pairs[strongest_pair]
            self.rounds.append(r)

        self.old_graph = self.graph
        self.graph = graph
        self.graph_winner()
开发者ID:Crowdocracy,项目名称:thedap,代码行数:35,代码来源:ranked_pairs.py

示例6: sort_out_covering_exons

def sort_out_covering_exons (cursor, exons):

    # havana is manually curated and gets priority
    is_ensembl = {}
    is_havana  = {}
    for exon in exons:
        logic_name = get_logic_name(cursor, exon.analysis_id)
        is_ensembl[exon] = ('ensembl' in logic_name)
        is_havana [exon] = ('havana'  in logic_name)

    dg = digraph()
    dg.add_nodes(exons)
    for exon1, exon2 in combinations(dg.nodes(),2):
        master, covered = find_master(cursor, exon1,exon2,is_ensembl,is_havana)
        if master is not None and covered is not None:
            dg.add_edge(master,covered)
    assert not find_cycle(dg)
    clusters = dict(((k,v) for k,v in accessibility(dg).iteritems()
                     if not dg.incidents(k)))
    for k in clusters:
        clusters[k].remove(k)

    for master_exon, covered_list in clusters.iteritems():
        master_exon.covering_exon       = -1 # nobody's covering this guy
        master_exon.covering_exon_known = -1 # formal
        for covered_exon in covered_list:
            covered_exon.covering_exon       = master_exon.exon_id
            covered_exon.covering_exon_known = master_exon.is_known
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:28,代码来源:06_exon_coordinates.py

示例7: main

def main(args):
    g = generate(args.nodes, args.edges, True)

    while not find_cycle(g):
        g = generate(args.nodes, args.edges, True)

    with open(args.output, 'w') as f:
        f.write(write(g))
开发者ID:sash-ko,项目名称:graph-cd,代码行数:8,代码来源:generate_random.py

示例8: testNoCycleDigraph

 def testNoCycleDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(3, 5)
     assert find_cycle(G) == []
开发者ID:svn2github,项目名称:python-graph2,代码行数:9,代码来源:unittests-cycles.py

示例9: test_find_small_cycle_on_digraph

 def test_find_small_cycle_on_digraph(self):
     gr = digraph()
     gr.add_nodes([1, 2, 3, 4, 5])
     gr.add_edge((1, 2))
     gr.add_edge((2, 3))
     gr.add_edge((2, 4))
     gr.add_edge((4, 5))
     gr.add_edge((2, 1))
     # Cycle: 1-2
     assert find_cycle(gr) == [1,2]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py

示例10: test_regression1

 def test_regression1(self):
     G = digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge((1, 2))
     G.add_edge((2, 3))
     G.add_edge((2, 4))
     G.add_edge((4, 5))
     G.add_edge((3, 5))
     G.add_edge((3, 1))
     assert find_cycle(G) == [1, 2, 3]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py

示例11: testSmallCycleDigraph

 def testSmallCycleDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(2, 1)
     # Cycle: 1-2
     assert find_cycle(G) == [1,2]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py

示例12: testMisleadingDigraph

 def testMisleadingDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(3, 5)
     G.add_edge(3, 1)
     assert find_cycle(G) == [1, 2, 3]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py

示例13: testGraph

 def testGraph(self):
     G = pygraph.graph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(1, 5)
     G.add_edge(3, 5)
     # Cycles: 1-2-4-5, 3-2-4-5 and 1-2-3-5
     assert find_cycle(G) == [2,3,5,4]
开发者ID:svn2github,项目名称:python-graph2,代码行数:11,代码来源:unittests-cycles.py

示例14: addDependency

 def addDependency(self,server,dependency):
     ''' Add a dependency to a server
     
     :param server: the name of the server
     :param dependency: the name of the server the former is dependent on  
     :raise DependencyException: Will raise an exception if there was a cycle in the server network
     '''
     self.graph.add_edge(((dependency,server))) #Note this is a turple casting
     cycleCheck = find_cycle(self.graph)
     if len(cycleCheck) != 0:
         raise Exceptions.DependencyException(cycleCheck,"There was a cycle in the server network")
     return
开发者ID:Keeper-of-the-Keys,项目名称:Ockle,代码行数:12,代码来源:ServerNetwork.py

示例15: _check_valid

def _check_valid(graph):
    """
    Check that the given graph is valid. This function does not return
    anything. It raise an exception however if the graph is considered
    invalid.
    """
    if graph is None:
        raise ValueError("The given graph is None!")

    if not graph.DIRECTED:
        raise ValueError("The given graph is not a directed graph!")

    cycle = find_cycle(graph)
    if len(cycle) != 0:
        _LOGGER.error("A cycle has been detected")
        raise CyclesDetectedError(cycle, graph)
开发者ID:pv-bull,项目名称:sequencer,代码行数:16,代码来源:algo.py


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