• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python cycles.find_cycle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: transitive_edges

def transitive_edges(graph):
    """
    Return a list of transitive edges.
    
    Example of transitivity within graphs: A -> B, B -> C, A ->  C
    in this case the transitive edge is: A -> C
    
    @attention: This function is only meaningful for directed acyclic graphs.
    
    @type graph: digraph
    @param graph: Digraph
    
    @rtype: List
    @return: List containing tuples with transitive edges (or an empty array if the digraph
        contains a cycle) 
    """
    #if the LoopGraph contains a cycle we return an empty array
    if not len(find_cycle(graph)) == 0:
        return []
    
    tranz_edges = [] # create an empty array that will contain all the tuples
    
    #run trough all the nodes in the LoopGraph
    for start in topological_sorting(graph):
        #find all the successors on the path for the current node
        successors = [] 
        for a in traversal(graph,start,'pre'):
            successors.append(a)
        del successors[0] #we need all the nodes in it's path except the start node itself
        
        for next in successors:
            #look for an intersection between all the neighbors of the 
            #given node and all the neighbors from the given successor
            intersect_array = _intersection(graph.neighbors(next), graph.neighbors(start) )
            for a in intersect_array:
                if graph.has_edge((start, a)):
                    ##check for the detected edge and append it to the returned array   
                    tranz_edges.append( (start,a) )      
    return tranz_edges # return the final array
开发者ID:aliahmet,项目名称:rogue,代码行数:39,代码来源:critical.py


示例17: build_graph

def build_graph(services, root=None):
    graph = digraph()

    for name, service in services.iteritems():
        dockerfile = "%s/Dockerfile" % service.dockerfile()

        if not os.path.isfile(dockerfile):
            sys.exit("%s does not exist" % dockerfile)

        baseimage = None
        with open(dockerfile, 'r') as file:
            for line in file:
                stripped = line.strip()
                if stripped.startswith('#'): continue

                if re.match("^\s*FROM\s+", stripped):
                    if baseimage: sys.exit("'%s' has more than 1 FROM instruction" % dockerfile)

                    tokens = stripped.split()
                    if len(tokens) < 2: sys.exit("'%s' has invalid FROM instruction" % dockerfile)

                    baseimage = tokens[1]

        _add_node_if_not_exists(graph, name)

        if baseimage.startswith(DOMAIN):
            parent = baseimage[len(DOMAIN):]
            _add_node_if_not_exists(graph, parent)
            graph.add_edge((parent, name))

    if root and not graph.has_node(root):
        sys.exit("Found no root in graph")

    cycles = find_cycle(graph)
    if cycles: sys.exit("Following services %s build a cycle. Please fix it!" % cycles)

    return _topological_sorting(graph, root)
开发者ID:berresch,项目名称:Docker-Sonderheft,代码行数:37,代码来源:dependencies.py


示例18: _find_cut

def _find_cut(candidate_cuts, cycle, tasks, files, releases):
    for (counter, cut) in enumerate(candidate_cuts):
        log.info("Cut: %s" % str(cut))

        tasks, task, task_name = _apply_cut(cut, tasks)
        # If no more cycles are found in the updated reduced graph
        # then return the good cut
        commits2 = create_commits_graph(files, tasks, releases)

        cycle2 = find_cycle(commits2)
        log.info("Cycle:  %s" % set(cycle))
        log.info("Cycle2: %s" % set(cycle2))

        _undo_cut(cut, task_name, task, tasks)

        if set(cycle) & set(cycle2) == set(cycle):
            log.info("The cycle was not removed")
        else:
            log.info("Cut found.")
            return cut
    else:
        # Error! This should not happen
        log.info("No cut found.")
        return None
开发者ID:pfeuffer,项目名称:PySynergy,代码行数:24,代码来源:convert_history.py


示例19: _find_one_pointless_cycle

def _find_one_pointless_cycle(node2arc_targets):
    # I guess find_cycle is cheaper than mutual_accessibility() if you
    # only care if there are cycles or not, but don't need the exact
    # strongly connected components """
    print(find_cycle(_graph2py_digraph(graph)))
开发者ID:KjellSchubert,项目名称:python-playground,代码行数:5,代码来源:graph_cycles.py


示例20: has_cycle

 def has_cycle(cls, nodes, edges):
     gr = digraph()
     gr.add_nodes(nodes)
     for edge in edges:
         gr.add_edge(edge)
     return find_cycle(gr)
开发者ID:4i60r,项目名称:ralph,代码行数:6,代码来源:models_ci.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python searching.breadth_first_search函数代码示例发布时间:2022-05-25
下一篇:
Python pygraph.digraph函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap