Ticket #12810: trac_12810.patch

File trac_12810.patch, 44.9 KB (added by ncohen, 9 years ago)
  • doc/en/reference/graphs.rst

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1332446450 -3600
    # Node ID e8d2705baa180079501e1f3a05084a5a516a68a7
    # Parent  299ed30e5ae505953666114972f573dd98ae3199
    Broken links in the documentation of graph/ files
    
    diff --git a/doc/en/reference/graphs.rst b/doc/en/reference/graphs.rst
    a b  
    1010
    1111   sage/graphs/generic_graph
    1212   sage/graphs/graph
    13    sage/graphs/graph_plot
    1413   sage/graphs/digraph
    1514   sage/graphs/bipartite_graph
    1615
     
    5049   sage/graphs/cliquer
    5150   sage/graphs/spanning_tree
    5251   sage/graphs/pq_trees
     52   sage/graphs/trees
    5353   sage/graphs/matchpoly
     54   sage/graphs/linearextensions
     55   sage/graphs/schnyder
     56   sage/graphs/graph_plot
    5457   sage/graphs/graph_decompositions/vertex_separation
    5558   sage/graphs/graph_decompositions/rankwidth
    5659   sage/graphs/modular_decomposition/modular_decomposition
  • sage/graphs/all.py

    diff --git a/sage/graphs/all.py b/sage/graphs/all.py
    a b  
    2121import sage.graphs.isgci
    2222from sage.graphs.isgci import graph_classes
    2323import sage.graphs.distances_all_pairs
     24import sage.graphs.trees
     25import sage.graphs.graph_latex
  • sage/graphs/base/c_graph.pyx

    diff --git a/sage/graphs/base/c_graph.pyx b/sage/graphs/base/c_graph.pyx
    a b  
    226226
    227227        .. SEEALSO::
    228228
    229             - :meth:`add_vertex_unsafe`
    230               -- add a vertex to a graph. This method is potentially unsafe.
    231               You should instead use :meth:`add_vertex`.
    232 
    233             - :meth:`add_vertices`
    234               -- add a bunch of vertices to a graph.
     229            - ``add_vertex_unsafe`` -- add a vertex to a graph. This
     230              method is potentially unsafe.  You should instead use
     231              :meth:`add_vertex`.
     232
     233            - ``add_vertices`` -- add a bunch of vertices to a graph.
    235234
    236235        EXAMPLES:
    237236
     
    439438
    440439        .. SEEALSO::
    441440
    442             - :meth:`del_vertex_unsafe`
    443               -- delete a vertex from a graph. This method is potentially
    444               unsafe. Use :meth:`del_vertex` instead.
     441            - ``del_vertex_unsafe`` -- delete a vertex from a graph. This method
     442              is potentially unsafe. Use :meth:`del_vertex` instead.
    445443
    446444        EXAMPLES:
    447445
     
    853851        raise NotImplementedError()
    854852
    855853    cdef int * adjacency_sequence_in(self, int n, int *vertices, int v):
    856         r""" 
     854        r"""
    857855        Returns the adjacency sequence corresponding to a list of vertices
    858         and a vertex. 
     856        and a vertex.
    859857
    860858        See the OUTPUT section for a formal definition.
    861859
    862860        See the function ``_test_adjacency_sequence()`` of
    863861        ``dense_graph.pyx`` and ``sparse_graph.pyx`` for unit tests.
    864        
    865         INPUT: 
     862
     863        INPUT:
    866864
    867865        - ``n`` -- nonnegative integer; the maximum index in
    868866          ``vertices`` up to which we want to consider. If ``n = 0``,
  • sage/graphs/base/static_sparse_graph.pyx

    diff --git a/sage/graphs/base/static_sparse_graph.pyx b/sage/graphs/base/static_sparse_graph.pyx
    a b  
    401401    bitset_intersection(scc, scc, scc_reversed)
    402402
    403403cdef void free_short_digraph(short_digraph g):
    404            
     404
    405405    if g.edges != NULL:
    406406        sage_free(g.edges)
    407407
     
    419419    .. NOTE::
    420420
    421421        This method has been written as an attempt to solve the slowness
    422         reported in #12235. It is not the one used by
    423         :meth:`sage.graphs.digraph.strongly_connected_components` as saving some
    424         time on the computation of the strongly connected components is not
    425         worth copying the whole graph, but it is a nice way to test this
     422        reported in :trac:`12235`. It is not the one used by
     423        :meth:`sage.graphs.digraph.DiGraph.strongly_connected_components` as
     424        saving some time on the computation of the strongly connected components
     425        is not worth copying the whole graph, but it is a nice way to test this
    426426        module's functions. It is also tested in the doctest or
    427         :meth:`sage.graphs.digraph.strongly_connected_components`.
     427        :meth:`sage.graphs.digraph.DiGraph.strongly_connected_components`.
    428428
    429429    EXAMPLE::
    430430
    431431        sage: from sage.graphs.base.static_sparse_graph import strongly_connected_components
    432432        sage: g = digraphs.ButterflyGraph(2)
    433433        sage: strongly_connected_components(g)
    434         [[('00', 0)], [('00', 1)], [('00', 2)], [('01', 0)], [('01', 1)], [('01', 2)], 
     434        [[('00', 0)], [('00', 1)], [('00', 2)], [('01', 0)], [('01', 1)], [('01', 2)],
    435435        [('10', 0)], [('10', 1)], [('10', 2)], [('11', 0)], [('11', 1)], [('11', 2)]]
    436436    """
    437437
     
    467467        strongly_connected_component_containing_vertex(g, gr, v, scc)
    468468        answer.append([vertices[i] for i in bitset_list(scc)])
    469469        bitset_union(seen, seen, scc)
    470        
     470
    471471    bitset_free(seen)
    472472    bitset_free(scc)
    473473    free_short_digraph(g)
  • sage/graphs/digraph.py

    diff --git a/sage/graphs/digraph.py b/sage/graphs/digraph.py
    a b  
    25952595        level set decomposition of the graph (see :meth:`.level_sets`).
    25962596
    25972597        This is achieved by calling ``graphviz`` and ``dot2tex`` if
    2598         available (see :meth:`.layout_acyclic_graphviz`), and using a
     2598        available (see :meth:`.layout_graphviz`), and using a
    25992599        random horizontal placement of the vertices otherwise (see
    26002600        :meth:`.layout_acyclic_dummy`).
    26012601
  • sage/graphs/generic_graph.py

    diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
    a b  
    1210512105        Multiple starting vertices can be specified in a list::
    1210612106
    1210712107            sage: D = DiGraph( { 0: [1,2,3], 1: [4,5], 2: [5], 3: [6], 5: [7], 6: [7], 7: [0]})
    12108             sage: list(D.breadth_first_search([0]))                                   
     12108            sage: list(D.breadth_first_search([0]))
    1210912109            [0, 1, 2, 3, 4, 5, 6, 7]
    1211012110            sage: list(D.breadth_first_search([0,6]))
    1211112111            [0, 6, 1, 2, 3, 7, 4, 5]
     
    1211512115            [0, 6, 1, 2, 3, 7]
    1211612116            sage: list(D.breadth_first_search(6,ignore_direction=True,distance=2))
    1211712117            [6, 3, 7, 0, 5]
    12118        
     12118
    1211912119        More generally, you can specify a ``neighbors`` function.  For
    1212012120        example, you can traverse the graph backwards by setting
    12121         ``neighbors`` to be the :meth:`.predecessor` function of the graph::
    12122            
     12121        ``neighbors`` to be the :meth:`.neighbors_in` function of the graph::
     12122
    1212312123            sage: D = DiGraph( { 0: [1,2,3], 1: [4,5], 2: [5], 3: [6], 5: [7], 6: [7], 7: [0]})
    1212412124            sage: list(D.breadth_first_search(5,neighbors=D.neighbors_in, distance=2))
    1212512125            [5, 1, 2, 0]
    12126             sage: list(D.breadth_first_search(5,neighbors=D.neighbors_out, distance=2)) 
     12126            sage: list(D.breadth_first_search(5,neighbors=D.neighbors_out, distance=2))
    1212712127            [5, 7, 0]
    12128             sage: list(D.breadth_first_search(5,neighbors=D.neighbors, distance=2)) 
     12128            sage: list(D.breadth_first_search(5,neighbors=D.neighbors, distance=2))
    1212912129            [5, 1, 2, 7, 0, 4, 6]
    1213012130
    1213112131
     
    1213812138            [0, 1, 2]
    1213912139
    1214012140        """
    12141         # Preferably use the Cython implementation 
    12142         if neighbors is None and not isinstance(start,list) and distance is None and hasattr(self._backend,"breadth_first_search"): 
    12143             for v in self._backend.breadth_first_search(start, ignore_direction = ignore_direction): 
    12144                 yield v 
    12145         else: 
     12141        # Preferably use the Cython implementation
     12142        if neighbors is None and not isinstance(start,list) and distance is None and hasattr(self._backend,"breadth_first_search"):
     12143            for v in self._backend.breadth_first_search(start, ignore_direction = ignore_direction):
     12144                yield v
     12145        else:
    1214612146            if neighbors is None:
    1214712147                if not self._directed or ignore_direction:
    12148                     neighbors=self.neighbor_iterator           
     12148                    neighbors=self.neighbor_iterator
    1214912149                else:
    1215012150                    neighbors=self.neighbor_out_iterator
    1215112151            seen=set([])
     
    1224412244       
    1224512245        More generally, you can specify a ``neighbors`` function.  For
    1224612246        example, you can traverse the graph backwards by setting
    12247         ``neighbors`` to be the :meth:`.predecessor` function of the graph::
     12247        ``neighbors`` to be the :meth:`.neighbors_in` function of the graph::
    1224812248       
    1224912249            sage: D = DiGraph( { 0: [1,2,3], 1: [4,5], 2: [5], 3: [6], 5: [7], 6: [7], 7: [0]})
    1225012250            sage: list(D.depth_first_search(5,neighbors=D.neighbors_in, distance=2))
     
    1341013410        :meth:`.layout_graphviz` for installation instructions.
    1341113411
    1341213412        A subclass may implement another layout algorithm `blah`, by
    13413         implementing a method :meth:`.layout_blah`. It may override
     13413        implementing a method ``.layout_blah``. It may override
    1341413414        the default layout by overriding :meth:`.layout_default`, and
    1341513415        similarly override the predefined layouts.
    1341613416
     
    1483014830        INPUT:
    1483114831
    1483214832        -  ``laplacian`` - if ``True``, use the Laplacian matrix
    14833            (see :meth:`~sage.graphs.graph.GenericGraph.kirchhoff_matrix()`)
     14833           (see :meth:`kirchhoff_matrix`)
    1483414834
    1483514835        OUTPUT:
    1483614836
     
    1493814938        INPUT:
    1493914939
    1494014940        -  ``laplacian`` - if True, use the Laplacian matrix
    14941            (see :meth:`~sage.graphs.graph.GenericGraph.kirchhoff_matrix()`)
     14941           (see :meth:`kirchhoff_matrix`)
    1494214942
    1494314943        OUTPUT:
    1494414944
     
    1502915029        INPUT:
    1503015030
    1503115031        -  ``laplacian`` - if True, use the Laplacian matrix
    15032            (see :meth:`~sage.graphs.graph.GenericGraph.kirchhoff_matrix()`)
     15032           (see :meth:`kirchhoff_matrix`)
    1503315033
    1503415034        OUTPUT:
    1503515035
  • sage/graphs/graph.py

    diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
    a b  
    28812881        for h in H:
    28822882            for u,v in self.edges(labels=None):
    28832883                p.add_constraint(r_edges[h][(u,v)] + r_edges[h][(v,u)] - edges[h][S((u,v))], min = 0)
    2884                                                                    
     2884
    28852885            for v in self:
    28862886                p.add_constraint(Sum([r_edges[h][(u,v)] for u in self.neighbors(v)]), max = 1-epsilon)
    28872887
     
    29252925        Returns an rank-decomposition of ``self`` achieving optiml rank-width.
    29262926
    29272927        See the documentation of the ``rankwidth`` module
    2928         :class:`<rankwidth sage.graphs.graph_decompositions.rankwidth>`.
     2928        :mod:`rankwidth <sage.graphs.graph_decompositions.rankwidth>`.
    29292929
    29302930        INPUT:
    29312931
     
    29402940
    29412941        See the documentation of the ``rankwidth`` module for more information
    29422942        on the tree
    2943         :class:`rankwidth <sage.graphs.graph_decompositions.rankwidth.`.
     2943        :mod:`rankwidth <sage.graphs.graph_decompositions.rankwidth>`.
    29442944
    29452945        .. WARNING::
    29462946
     
    32863286        obtained from `H` through arbitrary subdivision of its edges)
    32873287        as a subgraph.
    32883288
    3289         For more information, see the `Wikipedia article on graph
    3290         minor
    3291         <http://en.wikipedia.org/wiki/Minor_%28graph_theory%29>`_.
     3289        For more information, see the `Wikipedia article on graph minor
     3290        :wikipedia:`Minor_(graph_theory)`.
    32923291
    32933292        INPUT:
    32943293
     
    33103309        The topological `H`-minor found is returned as a subgraph `M`
    33113310        of ``self``, such that the vertex `v` of `M` that represents a
    33123311        vertex `h\in H` has ``h`` as a label (see
    3313         :meth:`get_vertex <sage.graphs.generic_graph.get_vertex>`
     3312        :meth:`get_vertex <sage.graphs.generic_graph.GenericGraph.get_vertex>`
    33143313        and
    3315         :meth:`set_vertex <sage.graphs.generic_graph.set_vertex>`),
     3314        :meth:`set_vertex <sage.graphs.generic_graph.GenericGraph.set_vertex>`),
    33163315        and such that every edge of `M` has as a label the edge of `H`
    33173316        it (partially) represents.
    33183317
     
    33303329        are highly exponential in `H`, though.
    33313330
    33323331        .. NOTE::
    3333        
     3332
    33343333            * This function can be expected to be *very* slow, especially
    33353334              where the topological minor does not exist.
    33363335
     
    33643363        from sage.numerical.mip import MixedIntegerLinearProgram, Sum, MIPSolverException
    33653364        p = MixedIntegerLinearProgram()
    33663365
    3367         # This is an existence problem 
     3366        # This is an existence problem
    33683367        p.set_objective(None)
    33693368
    33703369        #######################
  • sage/graphs/graph_decompositions/rankwidth.pyx

    diff --git a/sage/graphs/graph_decompositions/rankwidth.pyx b/sage/graphs/graph_decompositions/rankwidth.pyx
    a b  
    131131    r"""
    132132    Computes an optiml rank-decomposition of the given graph.
    133133
    134     This function is available as a method of the
    135     :class:`Graph <sage.graphs.graph>` class. See
    136     :meth:`rank_decomposition <sage.graphs.graph.rank_decomposition>`.
     134    This function is available as a method of the :class:`Graph
     135    <sage.graphs.graph>` class. See :meth:`rank_decomposition
     136    <sage.graphs.graph.Graph.rank_decomposition>`.
    137137
    138138    INPUT:
    139139
     
    162162        Exception: The rank decomposition cannot be computed on graphs of >= 32 vertices.
    163163
    164164    The empty graph::
    165    
     165
    166166        sage: g = Graph()
    167167        sage: rank_decomposition(g)
    168168        (0, Graph on 0 vertices)
  • sage/graphs/graph_generators.py

    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    66726672                    0: [1, 2, 3, 4],
    66736673                    1: [2, 3, 4],
    66746674                    3: [4],
    6675                     5: [2, 0, 1]                   
     6675                    5: [2, 0, 1]
    66766676                    }))
    66776677
    66786678        graphs.append(Graph({
  • sage/graphs/graph_latex.py

    diff --git a/sage/graphs/graph_latex.py b/sage/graphs/graph_latex.py
    a b  
    392392    should call this once as having random output to exhaust the
    393393    warnings before testing output.
    394394
    395     See also :meth:`sage.misc.latex.check_file`
     395    See also :meth:`sage.misc.latex.Latex.check_file`
    396396
    397397    TESTS::
    398398
     
    418418
    419419    The result is cached.
    420420
    421     See also :meth:`sage.misc.latex.has_file`
     421    See also :meth:`sage.misc.latex.Latex.has_file`
    422422
    423423    TESTS::
    424424
     
    437437    graphs(``tikz``, ``tkz-graph``, ``tkz-berge``), if available
    438438    in the ``LaTeX`` installation.
    439439
    440     See also :meth:`sage.misc.latex.add_package_to_preamble_if_available`.
    441    
     440    See also :meth:`sage.misc.latex.Latex.add_package_to_preamble_if_available`.
     441
    442442    EXAMPLES::
    443443
    444444        sage: sage.graphs.graph_latex.setup_latex_preamble()
     
    597597        Sets, modifies, clears a LaTeX
    598598        option for controlling the rendering of a graph.
    599599
    600         The possible options are documented here, because ultimately
    601         it is this routine that sets the values.  However, the
    602         :meth:`sage.graphs.generic_graph.Graph.set_latex_options` method
    603         is the easiest way to set options, and allows several to
    604         be set at once.
     600        The possible options are documented here, because ultimately it is this
     601        routine that sets the values.  However, the
     602        :meth:`sage.graphs.generic_graph.GenericGraph.set_latex_options` method
     603        is the easiest way to set options, and allows several to be set at once.
    605604
    606605        INPUTS:
    607606
    608         - ``option_name`` - a string for a latex option contained in
    609           the list :data:`__graphlatex_options`. A ``ValueError`` is
    610           raised if the option is not allowed.
     607        - ``option_name`` - a string for a latex option contained in the list
     608          ``sage.graphs.graph_latex.GraphLatex.__graphlatex_options``. A
     609          ``ValueError`` is raised if the option is not allowed.
    611610
    612611        - ``option_value`` - a value for the option.  If omitted, or
    613612          set to ``None``, the option will use the default value.
     
    888887            ...
    889888            ValueError: bad_name is not a LaTeX option for a graph.
    890889
    891         See :meth:`Graph.layout_graphviz` for installation
    892         instructions for ``graphviz`` and ``dot2tex``. Further more,
    893         pgf >= 2.00 should be available inside LaTeX's tree for LaTeX
    894         compilation (e.g. when using ``view``). In case your LaTeX
    895         distribution does not provide it, here are short instructions:
     890        See :meth:`sage.graphs.generic_graph.GenericGraph.layout_graphviz` for
     891        installation instructions for ``graphviz`` and ``dot2tex``. Further
     892        more, pgf >= 2.00 should be available inside LaTeX's tree for LaTeX
     893        compilation (e.g. when using ``view``). In case your LaTeX distribution
     894        does not provide it, here are short instructions:
    896895
    897896           - download pgf from http://sourceforge.net/projects/pgf/
    898897           - unpack it in ``/usr/share/texmf/tex/generic`` (depends on your system)
     
    12361235        OUTPUT:
    12371236
    12381237        If the name is not present in
    1239         :data:`sage.graphs.graph_latex.__graphlatex_options` it is an
     1238        ``__graphlatex_options`` it is an
    12401239        error to ask for it.  If an option has not been set then the
    12411240        default value is returned. Otherwise, the value of the
    12421241        option is returned.
     
    12691268        Returns a string in LaTeX representing a graph.
    12701269
    12711270        This is the command that is invoked by
    1272         :meth:`~sage.graphs.graph.GenericGraph._latex_` for
    1273         a graph, so it returns a string of
    1274         LaTeX commands that can be incorporated
    1275         into a LaTeX document unmodified.  The exact contents
    1276         of this string are influenced by the options set via the methods
    1277         :meth:`sage.graphs.graph.GenericGraph.set_latex_options`,
     1271        ``sage.graphs.generic_graph.GenericGraph._latex_`` for a graph, so
     1272        it returns a string of LaTeX commands that can be incorporated into a
     1273        LaTeX document unmodified.  The exact contents of this string are
     1274        influenced by the options set via the methods
     1275        :meth:`sage.graphs.generic_graph.GenericGraph.set_latex_options`,
    12781276        :meth:`set_option`, and :meth:`set_options`.
    12791277
    1280         By setting the ``format`` option different packages can be used
    1281         to create the latex version of a graph.  Supported packages are
     1278        By setting the ``format`` option different packages can be used to
     1279        create the latex version of a graph.  Supported packages are
    12821280        ``tkz-graph`` and ``dot2tex``.
    12831281
    12841282        EXAMPLES::
  • sage/graphs/graph_plot.py

    diff --git a/sage/graphs/graph_plot.py b/sage/graphs/graph_plot.py
    a b  
    151151
    152152        Make sure that vertex locations are floats.  Not being floats
    153153        isn't a bug in itself but makes it too easy to accidentally
    154         introduce a bug elsewhere, such as in set_edges (trac #10124),
     154        introduce a bug elsewhere, such as in set_edges (:trac:`10124`),
    155155        via silent truncating division of integers::
    156156
    157157            sage: g = graphs.FruchtGraph()
     
    313313            sage: G.show(edge_colors={'red':[(3,6),(2,5)]})
    314314
    315315        Verify that default edge labels are pretty close to being between the vertices
    316         in some cases where they weren't due to truncating division (trac #10124)::
     316        in some cases where they weren't due to truncating division (:trac:`10124`)::
    317317
    318318            sage: test_graphs = graphs.FruchtGraph(), graphs.BullGraph()
    319319            sage: tol = 0.001
     
    514514
    515515        TESTS:
    516516       
    517         Make sure that Python ints are acceptable arguments (trac #10124)::
     517        Make sure that Python ints are acceptable arguments (:trac:`10124`)::
    518518
    519519            sage: GP = DiGraph().graphplot()
    520520            sage: GP._polar_hack_for_multidigraph((0, 1), (2, 2), .1)
  • sage/graphs/linearextensions.py

    diff --git a/sage/graphs/linearextensions.py b/sage/graphs/linearextensions.py
    a b  
    33
    44A linear extension of a directed acyclic graph is a total (linear) ordering on
    55the vertices that is compatible with the graph in the following sense:
    6 if there is a path from x to y in the graph, the x appears before y in the 
     6if there is a path from x to y in the graph, the x appears before y in the
    77linear extension.
    88
    99The algorithm implemented in this module is from "Generating Linear Extensions
    10 Fast" by Preusse and Ruskey, which can be found at 
     10Fast" by Preusse and Ruskey, which can be found at
    1111http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.52.3057 .  The algorithm
    1212generates the extensions in constant amortized time (CAT) -- a constant amount
    13 of time per extension generated, or linear in the number of extensions 
     13of time per extension generated, or linear in the number of extensions
    1414generated.
    1515
    1616EXAMPLES:
     17
    1718Here we generate the 5 linear extensions of the following directed
    18 acyclic graph.
     19acyclic graph::
     20
    1921    sage: from sage.graphs.linearextensions import LinearExtensions
    2022    sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    2123    sage: D.is_directed_acyclic()
     
    3133induced from the graph.
    3234
    3335We can also get at the linear extensions directly from the graph.  From
    34 the graph, the linear extensions are known as topological sorts.
     36the graph, the linear extensions are known as topological sorts ::
     37
    3538    sage: D.topological_sort_generator()
    3639    [[0, 1, 2, 3, 4],
    3740     [0, 1, 2, 4, 3],
     
    6265
    6366        This is an in-place algorithm and the list self.le keeps track
    6467        of the current linear extensions.  The boolean variable self.is_plus
    65         keeps track of the "sign". 
     68        keeps track of the "sign".
    6669
    67         EXAMPLES:
     70        EXAMPLES::
     71
    6872            sage: from sage.graphs.linearextensions import LinearExtensions
    6973            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    7074            sage: l = LinearExtensions(D)
    7175            sage: l == loads(dumps(l))
    7276            True
    73        
     77
    7478        """
    7579        ################
    7680        #Precomputation#
     
    113117        self.is_plus = True
    114118        self.linear_extensions = None
    115119        self._name = "Linear extensions of %s"%dag
    116    
     120
    117121
    118122    def switch(self, i):
    119123        """
    120124        This implements the Switch procedure described on page 7
    121125        of "Generating Linear Extensions Fast" by Pruesse and Ruskey.
    122126
    123         If i == -1, then the sign is changed.  If i > 0, then self.a[i] 
     127        If i == -1, then the sign is changed.  If i > 0, then self.a[i]
    124128        and self.b[i] are transposed.
    125129
    126130        Note that this meant to be called by the generate_linear_extensions
    127131        method and is not meant to be used directly.
    128        
    129         EXAMPLES:
     132
     133        EXAMPLES::
     134
    130135            sage: from sage.graphs.linearextensions import LinearExtensions
    131136            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    132137            sage: l = LinearExtensions(D)
     
    171176        of "Generating Linear Extensions Fast" by Pruesse and Ruskey.
    172177
    173178        If direction is "left", then this transposes element with the
    174         element on its left.  If the direction is "right", then this 
     179        element on its left.  If the direction is "right", then this
    175180        transposes element with the element on its right.
    176              
     181
    177182        Note that this is meant to be called by the generate_linear_extensions
    178183        method and is not meant to be used directly.
    179184
    180         EXAMPLES:
     185        EXAMPLES::
     186
    181187            sage: from sage.graphs.linearextensions import LinearExtensions
    182188            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    183189            sage: l = LinearExtensions(D)
     
    209215        """
    210216        If letter =="b", then this returns True if and only if
    211217        self.b[i] is incomparable with the elements to its right
    212         in self.le.  If letter == "a", then it returns True if 
     218        in self.le.  If letter == "a", then it returns True if
    213219        and only if self.a[i] is incomparable with the element to its
    214220        right in self.le and the element to the right is not
    215221        self.b[i]
    216        
    217         This is the Right function described on page 8 of 
     222
     223        This is the Right function described on page 8 of
    218224        "Generating Linear Extensions Fast" by Pruesse and Ruskey.
    219225
    220226        Note that this is meant to be called by the generate_linear_extensions
    221227        method and is not meant to be used directly.
    222228
    223         EXAMPLES:
     229        EXAMPLES::
     230
    224231            sage: from sage.graphs.linearextensions import LinearExtensions
    225232            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    226233            sage: l = LinearExtensions(D)
     
    270277        Note that this is meant to be called by the list
    271278        method and is not meant to be used directly.
    272279
    273         EXAMPLES:
     280        EXAMPLES::
     281
    274282            sage: from sage.graphs.linearextensions import LinearExtensions
    275283            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    276284            sage: l = LinearExtensions(D)
     
    322330        """
    323331        Returns a list of the linear extensions of the directed acyclic graph.
    324332
    325         Note that once they are computed, the linear extensions are 
     333        Note that once they are computed, the linear extensions are
    326334        cached in this object.
    327335
    328         EXAMPLES:
     336        EXAMPLES::
     337
    329338            sage: from sage.graphs.linearextensions import LinearExtensions
    330339            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    331340            sage: LinearExtensions(D).list()
     
    337346        """
    338347        if self.linear_extensions is not None:
    339348            return self.linear_extensions[:]
    340        
     349
    341350        self.linear_extensions = []
    342351        self.linear_extensions.append(self.le[:])
    343352        self.generate_linear_extensions(self.max_pair)
     
    346355        self.linear_extensions.sort()
    347356        return self.linear_extensions[:]
    348357
    349    
     358
    350359    def incomparable(self, x, y):
    351360        """
    352361        Returns True if vertices x and y are incomparable in the directed
    353362        acyclic graph when thought of as a poset.
    354363
    355         EXAMPLES:
     364        EXAMPLES::
     365
    356366            sage: from sage.graphs.linearextensions import LinearExtensions
    357367            sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] })
    358368            sage: l = LinearExtensions(D)
  • sage/graphs/matchpoly.pyx

    diff --git a/sage/graphs/matchpoly.pyx b/sage/graphs/matchpoly.pyx
    a b  
    22Matching Polynomial Routine
    33
    44AUTHORS:
    5     -- Robert Miller, Tom Boothby - original implementation
     5- Robert Miller, Tom Boothby -- original implementation
    66
    77REFERENCE:
    8     Chris Godsil, Algebraic Combinatorics.
     8 Chris Godsil, Algebraic Combinatorics.
    99
    1010"""
    1111
  • sage/graphs/schnyder.py

    diff --git a/sage/graphs/schnyder.py b/sage/graphs/schnyder.py
    a b  
     1"""
     2Schnyder's Algorithm for straight-line planar embeddings.
    13
    2 """
    34A module for computing the (x,y) coordinates for a straight-line planar
    4 embedding of any connected planar graph with at least three vertices.  Uses 
     5embedding of any connected planar graph with at least three vertices.  Uses
    56Walter Schnyder's Algorithm.
    67
    78AUTHORS:
     
    2627    """
    2728    Helper function to schnyder method for computing coordinates in the plane to
    2829    plot a planar graph with no edge crossings.
    29    
     30
    3031    Given a connected graph g with at least 3 vertices and a planar combinatorial
    3132    embedding comb_emb of g, modify g in place to form a graph whose faces are
    3233    all triangles, and return the set of newly created edges.
    33    
     34
    3435    The simple way to triangulate a face is to just pick a vertex and draw
    3536    an edge from that vertex to every other vertex in the face. Think that this
    3637    might ultimately result in graphs that don't look very nice when we draw them
     
    3940    a repeat, we keep the first edge of the face and retry the process at the next
    4041    edge in the face list.  (By removing the special cases we guarantee that this
    4142    method will work on one of these attempts.)
    42    
     43
    4344    INPUT:
    4445        g -- the graph to triangulate
    4546        comb_emb -- a planar combinatorial embedding of g
    46        
     47
    4748    RETURNS:
    4849        A list of edges that are added to the graph (in place)
    49    
    50     EXAMPLES:
     50
     51    EXAMPLES::
     52
    5153        sage: from sage.graphs.schnyder import _triangulate
    5254        sage: g = Graph(graphs.CycleGraph(4))
    5355        sage: g.is_planar(set_embedding=True)
     
    6870        raise NotImplementedError("_triangulate() only knows how to handle connected graphs.")
    6971
    7072    if g.order() == 3 and len(g.edges()) == 2:             # if g is o--o--o
    71         vertex_list = g.vertices()                         
     73        vertex_list = g.vertices()
    7274        if len(g.neighbors(vertex_list[0])) == 2:          # figure out which of the vertices already has two neighbors
    7375            new_edge = (vertex_list[1], vertex_list[2])    # and connect the other two together.
    7476        elif len(g.neighbors(vertex_list[1])) == 2:
    7577            new_edge = (vertex_list[0], vertex_list[2])
    7678        else:
    7779            new_edge = (vertex_list[0], vertex_list[1])
    78            
     80
    7981        g.add_edge(new_edge)
    8082        return [new_edge]
    8183
     
    8385    # that it is not the graph o--o--o. This is where the real work starts.
    8486
    8587    faces = g.trace_faces(comb_emb)        # We start by finding all of the faces of this embedding.
    86    
     88
    8789    edges_added = []                        # The list of edges that we add to the graph.
    8890                                            # This will be returned at the end.
    89                                            
    90    
     91
     92
    9193    for face in faces:
    9294        new_face = []
    9395        if len(face) < 3:
     
    100102                new_face = (face[2][1], face[1][0])
    101103            g.add_edge(new_face)
    102104            edges_added.append(new_face)
    103         else:       
     105        else:
    104106            N = len(face)
    105107            i = 0
    106108            while i < N-1:
     
    126128    """
    127129    Helper function to schnyder method for computing coordinates in the plane to
    128130    plot a planar graph with no edge crossings.
    129    
     131
    130132    Constructs a normal labelling of a triangular graph g, given the planar
    131133    combinatorial embedding of g and a designated external face.  Returns labels
    132     dictionary.  The normal label is constructed by first contracting the graph 
     134    dictionary.  The normal label is constructed by first contracting the graph
    133135    down to its external face, then expanding the graph back to the original while
    134136    simultaneously adding angle labels.
    135    
     137
    136138    INPUT:
    137139        g -- the graph to find the normal labeling of (g must be triangulated)
    138140        comb_emb -- a planar combinatorial embedding of g
    139141        external_face -- the list of three edges in the external face of g
    140    
     142
    141143    RETURNS:
    142144        x -- tuple with entries
    143145            x[0] = dict of dicts of normal labeling for each vertex of g and each
    144                     adjacent neighbors u,v (u < v) of vertex: 
     146                    adjacent neighbors u,v (u < v) of vertex:
    145147                    { vertex : { (u,v): angel_label } }
    146148            x[1] = (v1,v2,v3) tuple of the three vertices of the external face.
    147            
    148     EXAMPLES:
     149
     150    EXAMPLES::
     151
    149152        sage: from sage.graphs.schnyder import _triangulate, _normal_label, _realizer
    150153        sage: g = Graph(graphs.CycleGraph(7))
    151154        sage: g.is_planar(set_embedding=True)
     
    157160        sage: _realizer(g, tn)
    158161        ({0: [<sage.graphs.schnyder.TreeNode instance at ...>]},
    159162         (0, 1, 2))
    160        
     163
    161164    """
    162165    contracted = []
    163166    contractible = []
    164167
    165168    labels = {}
    166    
     169
    167170    external_vertices = [external_face[0][0], external_face[1][0], external_face[2][0]]
    168171    external_vertices.sort()
    169172    v1,v2,v3 = external_vertices
     
    174177        neighbor_count[v] = 0
    175178    for v in g.neighbors(v1):
    176179        neighbor_count[v] = len(v1_neighbors.intersection( Set(g.neighbors(v))))
    177    
     180
    178181
    179182    for v in v1_neighbors:
    180183        if v in [v1,v2,v3]:
    181184            continue
    182185        if neighbor_count[v] == 2:
    183186            contractible.append(v)
    184    
     187
    185188    # contraction phase:
    186189
    187190    while g.order() > 3:
     
    206209        for w in g.neighbors(v1):
    207210            if(len(v1_neighbors.intersection( Set(g.neighbors(w))))) == 2 and w not in [v1, v2, v3]:
    208211                contractible.append(w)
    209            
    210    
     212
     213
    211214    # expansion phase:
    212215
    213216    v1, v2, v3 = g.vertices() #always in sorted order
     
    227230        if len(neighbors_to_delete) == 0:
    228231            # we are adding v into the face new_neighbors
    229232            w1, w2, w3 = sorted(new_neighbors)
    230            
     233
    231234            labels[v] = {(w1, w2): labels[w3].pop((w1,w2)), (w2,w3) : labels[w1].pop((w2,w3)), (w1,w3) : labels[w2].pop((w1,w3))}
    232235            labels[w1][tuple(sorted((w2,v)))] = labels[v][(w2,w3)]
    233236            labels[w1][tuple(sorted((w3,v)))] = labels[v][(w2,w3)]
     
    267270                else:
    268271                    vertices_in_order.append(angle[0])
    269272                angles_out_of_v1.remove(angle)
    270            
     273
    271274            w = vertices_in_order
    272275
    273276            # is w[0] a 2 or a 3?
     
    282285                labels[w[i]][ tuple(sorted( (w[i+1], v) )) ] = top_label
    283286                labels[w[i+1]][ tuple(sorted( (w[i], v) )) ] = bottom_label
    284287                i = i + 1
    285            
     288
    286289            labels[v][tuple(sorted( (v1, w[0])))] = bottom_label
    287290            labels[v][tuple(sorted( (v1, w[-1])))] = top_label
    288291
     
    291294            labels[w[-1]][tuple(sorted((v1,v)))] = bottom_label
    292295            labels[v1][tuple(sorted( (w[0],v) ))] = 1
    293296            labels[v1][tuple(sorted( (w[-1],v) ))] = 1
    294            
     297
    295298            #delete all the extra labels
    296299
    297300            for angle in angle_set:
     
    299302
    300303            labels[w[0]].pop( tuple (sorted( (v1, w[1]) ) ))
    301304            labels[w[-1]].pop( tuple (sorted( (v1, w[-2]) ) ))
    302            
     305
    303306            i = 1
    304307            while i < len(w) - 1:
    305                 labels[w[i]].pop(tuple(sorted( (v1, w[i+1])))) 
    306                 labels[w[i]].pop(tuple(sorted( (v1, w[i-1])))) 
     308                labels[w[i]].pop(tuple(sorted( (v1, w[i+1]))))
     309                labels[w[i]].pop(tuple(sorted( (v1, w[i-1]))))
    307310                i = i + 1
    308311
    309312        for w in new_neighbors:
     
    317320    realizer and returns a dictionary of three trees determined by the
    318321    realizer, each spanning all interior vertices and rooted at one of
    319322    the three external vertices.
    320    
     323
    321324    A realizer is a directed graph with edge labels that span all interior
    322325    vertices from each external vertex.  It is determined by giving direction
    323326    to the edges that have the same angle label on both sides at a vertex.
    324327    (Thus the direction actually points to the parent in the tree.)  The
    325328    edge label is set as whatever the matching angle label is.  Then from
    326     any interior vertex, following the directed edges by label will 
     329    any interior vertex, following the directed edges by label will
    327330    give a path to each of the three external vertices.
    328    
     331
    329332    INPUT:
    330333        g -- the graph to compute the realizer of
    331334        x -- tuple with entries
    332              x[0] = dict of dicts representing a normal labeling of g.  For 
    333                     each vertex of g and each adjacent neighbors u,v (u < v) of 
     335             x[0] = dict of dicts representing a normal labeling of g.  For
     336                    each vertex of g and each adjacent neighbors u,v (u < v) of
    334337                    vertex:  { vertex : { (u,v): angle_label } }
    335338             x[1] = (v1, v2, v3) tuple of the three external vertices (also
    336339                    the roots of each tree)
    337                    
     340
    338341    RETURNS:
    339342        x -- tuple with entries
    340343            x[0] = dict of lists of TreeNodes:
    341344                    { root_vertex : [ list of all TreeNodes under root_vertex ] }
    342345            x[0] = (v1,v2,v3) tuple of the three external vertices (also the
    343346                    roots of each tree)
    344                    
    345     EXAMPLES:
     347
     348    EXAMPLES::
     349
    346350        sage: from sage.graphs.schnyder import _triangulate, _normal_label, _realizer
    347351        sage: g = Graph(graphs.CycleGraph(7))
    348352        sage: g.is_planar(set_embedding=True)
     
    354358        sage: _realizer(g, tn)
    355359        ({0: [<sage.graphs.schnyder.TreeNode instance at ...>]},
    356360         (0, 1, 2))
    357                
     361
    358362    """
    359363    normal_labeling, (v1, v2, v3) = x
    360364    realizer = DiGraph()
     
    362366    tree_nodes = {}
    363367    for v in g:
    364368        tree_nodes[v] = [TreeNode(label = v, children = []), TreeNode(label = v, children = []), TreeNode(label = v, children = [])]
    365    
     369
    366370
    367371    for v in g:
    368372        ones = []
     
    375379        ones.sort()
    376380        twos.sort()
    377381        threes.sort()
    378        
     382
    379383        i = 0
    380384        while i < len(ones) - 1:
    381385            if ones[i] == ones[i+1]:
     
    399403            i = i + 1
    400404
    401405    _compute_coordinates(realizer, (tree_nodes, (v1, v2, v3)))
    402    
     406
    403407    if example:
    404408        realizer.show(talk=True, edge_labels=True)
    405409
     
    408412def _compute_coordinates(g, x):
    409413    """
    410414    Given a triangulated graph g with a dict of trees given by the
    411     realizer and tuple of the external vertices, we compute the 
     415    realizer and tuple of the external vertices, we compute the
    412416    coordinates of a planar geometric embedding in the grid.
    413    
     417
    414418    The coordinates will be set to the _pos attribute of g.
    415    
     419
    416420    INPUT:
    417421        g -- the graph to compute the coordinates of
    418422        x -- tuple with entries
    419              x[0] = dict of tree nodes for the three trees with each external 
     423             x[0] = dict of tree nodes for the three trees with each external
    420424                    vertex as root
    421425                    { root_vertex : [ list of all TreeNodes under root_vertex ] }
    422                    
     426
    423427             x[1] = (v1, v2, v3) tuple of the three external vertices (also
    424428                    the roots of each tree)
    425     EXAMPLES:
     429    EXAMPLES::
     430
    426431        sage: from sage.graphs.schnyder import _triangulate, _normal_label, _realizer, _compute_coordinates
    427432        sage: g = Graph(graphs.CycleGraph(7))
    428433        sage: g.is_planar(set_embedding=True)
     
    436441        sage: g.get_pos()
    437442        {0: [5, 1], 1: [0, 5], 2: [1, 0], 3: [1, 4], 4: [2, 1], 5: [2, 3], 6: [3, 2]}
    438443    """
    439    
     444
    440445    tree_nodes, (v1, v2, v3) = x
    441446    # find the roots of each tree:
    442447    t1, t2, t3 = tree_nodes[v1][0], tree_nodes[v2][1], tree_nodes[v3][2]
     
    462467        if v not in [t1.label,t2.label,t3.label]:
    463468            # Computing coordinates for v
    464469            r = list((0,0,0))
    465            
     470
    466471            for i in [0,1,2]:
    467472                # Computing size of region i:
    468                
     473
    469474                # Tracing up tree (i + 1) % 3
    470475                p = tree_nodes[v][(i + 1) % 3]
    471476                while p is not None:
     
    475480                    r[i] += q
    476481                    p = p.parent
    477482
    478                 # Tracing up tree (i - 1) % 3                   
     483                # Tracing up tree (i - 1) % 3
    479484                p = tree_nodes[v][(i - 1) % 3]
    480485                while p is not None:
    481486                    q = tree_nodes[p.label][i].number_of_descendants
     
    483488                    # labels on path up tree (i - 1) % 3
    484489                    r[i] += q
    485490                    p = p.parent
    486                
     491
    487492                q = tree_nodes[v][i].number_of_descendants
    488                 # Subtracting 
     493                # Subtracting
    489494                r[i] -= q
    490                
    491                 # Subtracting 
     495
     496                # Subtracting
    492497                q = tree_nodes[v][(i-1)%3].depth
    493498                r[i] -= q
    494499
     
    504509    A class to represent each node in the trees used by _realizer() and
    505510    _compute_coordinates() when finding a planar geometric embedding in
    506511    the grid.
    507    
     512
    508513    Each tree node is doubly linked to its parent and children.
    509    
     514
    510515    INPUT:
    511516        parent -- the parent TreeNode of self
    512517        children -- a list of TreeNode children of self
    513518        label -- the associated realizer vertex label
    514        
    515     EXAMPLES:
     519
     520    EXAMPLES::
     521
    516522        sage: from sage.graphs.schnyder import TreeNode
    517523        sage: tn = TreeNode(label=5)
    518524        sage: tn2 = TreeNode(label=2,parent=tn)
     
    535541            parent -- the parent TreeNode of self
    536542            children -- a list of TreeNode children of self
    537543            label -- the associated realizer vertex label
    538            
    539         EXAMPLE:
     544
     545        EXAMPLE::
     546
    540547            sage: from sage.graphs.schnyder import TreeNode
    541548            sage: tn = TreeNode(label=5)
    542549            sage: tn2 = TreeNode(label=2,parent=tn)
     
    563570
    564571    def compute_number_of_descendants(self):
    565572        """
    566         Computes the number of descendants of self and all descendants. 
     573        Computes the number of descendants of self and all descendants.
    567574        For each TreeNode, sets result as attribute self.number_of_descendants
    568        
    569         EXAMPLES:
     575
     576        EXAMPLES::
     577
    570578            sage: from sage.graphs.schnyder import TreeNode
    571579            sage: tn = TreeNode(label=5)
    572580            sage: tn2 = TreeNode(label=2,parent=tn)
     
    588596            n += child.compute_number_of_descendants()
    589597        self.number_of_descendants = n
    590598        return n
    591    
     599
    592600    def compute_depth_of_self_and_children(self):
    593601        """
    594602        Computes the depth of self and all descendants.
    595603        For each TreeNode, sets result as attribute self.depth
    596        
    597         EXAMPLES:
     604
     605        EXAMPLES::
     606
    598607            sage: from sage.graphs.schnyder import TreeNode
    599608            sage: tn = TreeNode(label=5)
    600609            sage: tn2 = TreeNode(label=2,parent=tn)
     
    617626            self.depth = self.parent.depth + 1
    618627        for child in self.children:
    619628            child.compute_depth_of_self_and_children()
    620            
     629
    621630    def append_child(self, child):
    622631        """
    623632        Add a child to list of children.
    624        
    625         EXAMPLES:
     633
     634        EXAMPLES::
     635
    626636            sage: from sage.graphs.schnyder import TreeNode
    627637            sage: tn = TreeNode(label=5)
    628638            sage: tn2 = TreeNode(label=2,parent=tn)
  • sage/graphs/trees.pyx

    diff --git a/sage/graphs/trees.pyx b/sage/graphs/trees.pyx
    a b  
    11r"""
    2 This is an implementation of the algorithm for generating trees with n vertices
     2Generation of trees
     3
     4This is an implementation of the algorithm for generating trees with `n` vertices
    35(up to isomorphism) in constant time per tree described in [WRIGHT-ETAL]_.
    46
    57AUTHORS:
     
    2729    r"""
    2830    This class iterates over all trees with n vertices (up to isomorphism).
    2931
    30     EXAMPLES:
     32    EXAMPLES::
    3133
    3234        sage: from sage.graphs.trees import TreeIterator
    3335        sage: def check_trees(n):
     
    4749        sage: print check_trees(10)
    4850        True
    4951
     52    ::
     53
    5054        sage: from sage.graphs.trees import TreeIterator
    5155        sage: count = 0
    5256        sage: for t in TreeIterator(15):
     
    5761
    5862    def __init__(self, int vertices):
    5963        r"""
    60         Initializes an iterator over all trees with n vertices.
     64        Initializes an iterator over all trees with `n` vertices.
    6165
    6266        EXAMPLES::
    6367
     
    7377
    7478    def __dealloc__(self):
    7579        r"""
    76         EXAMPLES:
     80        EXAMPLES::
     81
    7782            sage: from sage.graphs.trees import TreeIterator
    7883            sage: t = TreeIterator(100)
    7984            sage: t = None # indirect doctest
     
    8590
    8691    def __str__(self):
    8792        r"""
    88         EXAMPLES:
     93        EXAMPLES::
     94
    8995            sage: from sage.graphs.trees import TreeIterator
    9096            sage: t = TreeIterator(100)
    9197            sage: print t # indirect doctest
     
    95101
    96102    def __iter__(self):
    97103        r"""
    98         Returns an iterator over all the trees with n vertices.
     104        Returns an iterator over all the trees with `n` vertices.
    99105
    100         EXAMPLES:
     106        EXAMPLES::
     107
    101108            sage: from sage.graphs.trees import TreeIterator
    102109            sage: t = TreeIterator(4)
    103110            sage: list(iter(t))
     
    107114
    108115    def __next__(self):
    109116        r"""
    110         Returns the next tree with n vertices
     117        Returns the next tree with `n` vertices
    111118
    112         EXAMPLES:
     119        EXAMPLES::
     120
    113121            sage: from sage.graphs.trees import TreeIterator
    114122            sage: T = TreeIterator(5)
    115123            sage: [t for t in T] # indirect doctest
     
    164172
    165173    cdef int generate_first_level_sequence(self):
    166174        r"""
    167         Generates the level sequence representing the first tree with n vertices
     175        Generates the level sequence representing the first tree with `n` vertices
    168176        """
    169177        cdef int i
    170178        cdef int k
     
    200208
    201209    cdef int generate_next_level_sequence(self):
    202210        r"""
    203         Generates the level sequence representing the next tree with n vertices
     211        Generates the level sequence representing the next tree with `n` vertices
    204212        """
    205213        cdef int i
    206214        cdef int fixit = 0
     
    311319        self.l = l
    312320        self.current_level_sequence = w
    313321
    314         return 0
    315  No newline at end of file
     322        return 0