Ticket #7157: trac_7157.patch

File trac_7157.patch, 10.3 KB (added by ncohen, 11 years ago)
  • sage/combinat/posets/hasse_diagram.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1255087231 -7200
    # Node ID d23fb3343d5e81e0c510f086f289b41fcd2076e8
    # Parent  6ef7c82641faf0dc7ef13942367b4da92eb0d99c
    Graph.successor and Graph.predecessor changed to Graph.neighbors_out and Graph.neighbors_in. The old functions stay and are deprecated
    
    diff -r 6ef7c82641fa -r d23fb3343d5e sage/combinat/posets/hasse_diagram.py
    a b  
    669669            sage: list(H.upper_covers_iterator(7))
    670670            []
    671671        """
    672         for x in self.successor_iterator(element):
     672        for x in self.neighbor_out_iterator(element):
    673673            yield x
    674674
    675675    def lower_covers_iterator(self,element):
     
    684684            sage: list(H.lower_covers_iterator(4))
    685685            [1, 2]
    686686        """
    687         for x in self.predecessor_iterator(element):
     687        for x in self.neighbor_in_iterator(element):
    688688            yield x
    689689
    690690    def size(self):
  • sage/combinat/yang_baxter_graph.py

    diff -r 6ef7c82641fa -r d23fb3343d5e sage/combinat/yang_baxter_graph.py
    a b  
    323323        seen[self._root] = True
    324324        while queue:
    325325            u = queue.pop()
    326             for w in digraph.successors(u):
     326            for w in digraph.neighbor_out_iterator(u):
    327327                if w not in seen:
    328328                    seen[w] = True
    329329                    queue.append(w)
  • sage/graphs/graph.py

    diff -r 6ef7c82641fa -r d23fb3343d5e sage/graphs/graph.py
    a b  
    391391from sage.plot.misc import options
    392392import sage.groups.perm_gps.partn_ref.refinement_graphs
    393393from sage.groups.perm_gps.partn_ref.refinement_graphs import isomorphic, search_tree
     394from sage.misc.misc import deprecated_function_alias
    394395
    395396
    396397class GenericGraph(SageObject):
     
    15881589        if self.allows_multiple_edges() or to_undirected:
    15891590            if self._directed and not to_undirected:
    15901591                for v in self:
    1591                     for u in self.predecessor_iterator(v):
     1592                    for u in self.neighbor_in_iterator(v):
    15921593                        edges = self.edge_boundary([u], [v])
    15931594                        if len(edges) > 1:
    15941595                            return True
     
    17631764        multi_edges = []
    17641765        if self._directed and not to_undirected:
    17651766            for v in self:
    1766                 for u in self.predecessor_iterator(v):
     1767                for u in self.neighbor_in_iterator(v):
    17671768                    edges = self.edge_boundary([u], [v], labels)
    17681769                    if len(edges) > 1:
    17691770                        multi_edges += edges
     
    32313232        output = set()
    32323233        if self._directed:
    32333234            for v in vertices1:
    3234                 output.update(self.successor_iterator(v))
     3235                output.update(self.neighbor_out_iterator(v))
    32353236        else:
    32363237            for v in vertices1:
    32373238                output.update(self.neighbor_iterator(v))                   
     
    34483449            [1, 2, 3]
    34493450        """
    34503451        if self._directed:
    3451             return iter(set(self.successor_iterator(vertex)) \
    3452                     | set(self.predecessor_iterator(vertex)))
     3452            return iter(set(self.neighbor_out_iterator(vertex)) \
     3453                    | set(self.neighbor_in_iterator(vertex)))
    34533454        else:
    34543455            return iter(set(self._backend.iterator_nbrs(vertex)))
    34553456
     
    41874188        if self.allows_multiple_edges():
    41884189            if self._directed:
    41894190                for v in self:
    4190                     for u in self.predecessor_iterator(v):
     4191                    for u in self.neighbor_in_iterator(v):
    41914192                        edges = self.edge_boundary([u], [v])
    41924193                        if len(edges) > 1:
    41934194                            self.delete_edges(edges[1:])
     
    57325733            [[0, 1, 3], [0, 2, 3], [0, 3]]
    57335734        """
    57345735        if self.is_directed():
    5735             iterator=self.successor_iterator
     5736            iterator=self.neighbor_out_iterator
    57365737        else:
    57375738            iterator=self.neighbor_iterator
    57385739        all_paths = []      # list of
     
    61336134        ``neighbors`` to be the :meth:`.predecessor` function of the graph::
    61346135           
    61356136            sage: D = DiGraph( { 0: [1,2,3], 1: [4,5], 2: [5], 3: [6], 5: [7], 6: [7], 7: [0]})
    6136             sage: list(D.breadth_first_search(5,neighbors=D.predecessors, distance=2))
     6137            sage: list(D.breadth_first_search(5,neighbors=D.neighbors_in, distance=2))
    61376138            [5, 1, 2, 0]
    6138             sage: list(D.breadth_first_search(5,neighbors=D.successors, distance=2)) 
     6139            sage: list(D.breadth_first_search(5,neighbors=D.neighbors_out, distance=2)) 
    61396140            [5, 7, 0]
    61406141            sage: list(D.breadth_first_search(5,neighbors=D.neighbors, distance=2))
    61416142            [5, 1, 2, 7, 0, 4, 6]
     
    61546155            if not self._directed or ignore_direction:
    61556156                neighbors=self.neighbor_iterator           
    61566157            else:
    6157                 neighbors=self.successor_iterator
     6158                neighbors=self.neighbor_out_iterator
    61586159        seen=set([])
    61596160        if isinstance(start, list):
    61606161            queue=[(v,0) for v in start]
     
    62446245        ``neighbors`` to be the :meth:`.predecessor` function of the graph::
    62456246       
    62466247            sage: D = DiGraph( { 0: [1,2,3], 1: [4,5], 2: [5], 3: [6], 5: [7], 6: [7], 7: [0]})
    6247             sage: list(D.depth_first_search(5,neighbors=D.predecessors, distance=2))
     6248            sage: list(D.depth_first_search(5,neighbors=D.neighbors_in, distance=2))
    62486249            [5, 2, 0, 1]
    6249             sage: list(D.depth_first_search(5,neighbors=D.successors, distance=2)) 
     6250            sage: list(D.depth_first_search(5,neighbors=D.neighbors_out, distance=2)) 
    62506251            [5, 7, 0]
    62516252            sage: list(D.depth_first_search(5,neighbors=D.neighbors, distance=2))
    62526253            [5, 7, 6, 0, 2, 1, 4]
     
    62646265            if not self._directed or ignore_direction:
    62656266                neighbors=self.neighbor_iterator           
    62666267            else:
    6267                 neighbors=self.successor_iterator
     6268                neighbors=self.neighbor_out_iterator
    62686269        seen=set([])
    62696270        if isinstance(start, list):
    62706271            # Reverse the list so that the initial vertices come out in the same order
     
    1170211703        """
    1170311704        return list(self.outgoing_edge_iterator(vertices, labels=labels))
    1170411705
    11705     def predecessor_iterator(self, vertex):
    11706         """
    11707         Returns an iterator over predecessor vertices of vertex.
    11708        
    11709         EXAMPLES::
    11710        
    11711             sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
    11712             sage: for a in D.predecessor_iterator(0):
     11706    def neighbor_in_iterator(self, vertex):
     11707        """
     11708        Returns an iterator over the in-neighbors of vertex.
     11709
     11710        An vertex `u` is an in-neighbor of a vertex `v` if `uv` in an edge.
     11711       
     11712        EXAMPLES::
     11713       
     11714            sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
     11715            sage: for a in D.neighbor_in_iterator(0):
    1171311716            ...    print a
    1171411717            1
    1171511718            4
    1171611719        """
    1171711720        return iter(set(self._backend.iterator_in_nbrs(vertex)))
    1171811721
    11719     def predecessors(self, vertex):
    11720         """
    11721         Returns a list of predecessor vertices of vertex.
    11722        
    11723         EXAMPLES::
    11724        
    11725             sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
    11726             sage: D.predecessors(0)
     11722    predecessor_iterator = deprecated_function_alias(neighbor_in_iterator, 'Sage Version 4.2, Release Date: 2009-10-24')
     11723
     11724    def neighbors_in(self, vertex):
     11725        """
     11726        Returns the list of the in-neighbors of a given vertex.
     11727
     11728        An vertex `u` is an in-neighbor of a vertex `v` if `uv` in an edge.
     11729       
     11730        EXAMPLES::
     11731       
     11732            sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
     11733            sage: D.neighbors_in(0)
    1172711734            [1, 4]
    1172811735        """
    11729         return list(self.predecessor_iterator(vertex))
    11730 
    11731     def successor_iterator(self, vertex):
    11732         """
    11733         Returns an iterator over successor vertices of vertex.
    11734        
    11735         EXAMPLES::
    11736        
    11737             sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
    11738             sage: for a in D.successor_iterator(0):
     11736        return list(self.neighbor_in_iterator(vertex))
     11737
     11738    predecessors = deprecated_function_alias(neighbors_in, 'Sage Version 4.2, Release Date: 2009-10-24')
     11739
     11740    def neighbor_out_iterator(self, vertex):
     11741        """
     11742        Returns an iterator over the out-neighbors of a given vertex.
     11743
     11744        An vertex `u` is an out-neighbor of a vertex `v` if `vu` in an edge.
     11745       
     11746        EXAMPLES::
     11747       
     11748            sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
     11749            sage: for a in D.neighbor_out_iterator(0):
    1173911750            ...    print a
    1174011751            1
    1174111752            2
     
    1174311754        """
    1174411755        return iter(set(self._backend.iterator_out_nbrs(vertex)))
    1174511756
    11746     def successors(self, vertex):
    11747         """
    11748         Returns a list of successor vertices of vertex.
    11749        
    11750         EXAMPLES::
    11751        
    11752             sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
    11753             sage: D.successors(0)
     11757    successor_iterator = deprecated_function_alias(neighbor_out_iterator, 'Sage Version 4.2, Release Date: 2009-10-24')
     11758
     11759    def neighbors_out(self, vertex):
     11760        """
     11761        Returns the list of the out-neighbors of a given vertex.
     11762
     11763        An vertex `u` is an out-neighbor of a vertex `v` if `vu` in an edge.
     11764       
     11765        EXAMPLES::
     11766       
     11767            sage: D = DiGraph( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )
     11768            sage: D.neighbors_out(0)
    1175411769            [1, 2, 3]
    1175511770        """
    11756         return list(self.successor_iterator(vertex))
     11771        return list(self.neighbor_out_iterator(vertex))
     11772
     11773    successors = deprecated_function_alias(neighbors_out, 'Sage Version 4.2, Release Date: 2009-10-24')
    1175711774
    1175811775    ### Degree functions
    1175911776