Ticket #12980: trac_12980.reviewer.patch

File trac_12980.reviewer.patch, 10.3 KB (added by kini, 9 years ago)

apply to $SAGE_ROOT/devel/sage

  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Keshav Kini <keshav.kini@gmail.com>
    # Date 1337816788 25200
    # Node ID 7c353bb3530853893488c9a3cd618d24bdbc20bb
    # Parent  3de830eff3624fd7a79e913742b59f2fc184b5da
    Naming, formatting, faster casting, unreferenced var
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    115115- :meth:`GrotzschGraph <GraphGenerators.GrotzschGraph>`
    116116- :meth:`HararyGraph <GraphGenerators.HararyGraph>`
    117117- :meth:`HarriesGraph <GraphGenerators.HarriesGraph>`
    118 - :meth:`HarriesWong <GraphGenerators.HarriesWong>`
     118- :meth:`HarriesWongGraph <GraphGenerators.HarriesWongGraph>`
    119119- :meth:`HeawoodGraph <GraphGenerators.HeawoodGraph>`
    120120- :meth:`HerschelGraph <GraphGenerators.HerschelGraph>`
    121121- :meth:`HigmanSimsGraph <GraphGenerators.HigmanSimsGraph>`
     
    16751675        else:
    16761676            raise ValueError("The value of embedding must be 1 or 2.")
    16771677
    1678     def HarriesWong(self, embedding=1):
     1678    def HarriesWongGraph(self, embedding=1):
    16791679        r"""
    16801680        Returns the Harries-Wong Graph.
    16811681
     
    16841684
    16851685        *About the default embedding:*
    16861686
    1687             The default embedding is an attempt to emphasize the graph's 8 (!!!)
    1688             different orbits. In order to understand this better, one can
    1689             picture the graph as built in the following way :
    1690 
    1691                 #. One first create a 3-dimensional cube (8 vertices, 12 edges),
    1692                    whose vertices define the first orbit of the final graph.
    1693 
    1694                 #. The edges of this graph are subdivided once, to create 12 new
    1695                    vertices which define a second orbit.
    1696 
    1697                 #. The edges of the graph are subdivided once more, to create 24
    1698                    new vertices giving a third orbit.
    1699 
    1700                 #. 4 vertices are created and made adjacent to the vertices of
    1701                    the second orbit so that they have degree 3. These 4 vertices
    1702                    also define a new orbit.
    1703 
    1704                 #. In order to make the vertices from the third orbit 3-regular
    1705                    (they all miss one edge), one creates a binary tree on 1 + 3
    1706                    + 6 + 12 vertices. The leaves of this new tree are made
    1707                    adjacent to the 12 vertices of the third orbit, and the graph
    1708                    is now 3-regular. This binary tree contributes 4 new orbits
    1709                    to the Harries-Wong graph.
     1687        The default embedding is an attempt to emphasize the graph's
     1688        8 (!!!) different orbits. In order to understand this better,
     1689        one can picture the graph as being built in the following way:
     1690
     1691            #. One first creates a 3-dimensional cube (8 vertices, 12
     1692               edges), whose vertices define the first orbit of the
     1693               final graph.
     1694
     1695            #. The edges of this graph are subdivided once, to create 12
     1696               new vertices which define a second orbit.
     1697
     1698            #. The edges of the graph are subdivided once more, to
     1699               create 24 new vertices giving a third orbit.
     1700
     1701            #. 4 vertices are created and made adjacent to the vertices
     1702               of the second orbit so that they have degree
     1703               3. These 4 vertices also define a new orbit.
     1704
     1705            #. In order to make the vertices from the third orbit
     1706               3-regular (they all miss one edge), one creates a binary
     1707               tree on 1 + 3 + 6 + 12 vertices. The leaves of this new
     1708               tree are made adjacent to the 12 vertices of the third
     1709               orbit, and the graph is now 3-regular. This binary tree
     1710               contributes 4 new orbits to the Harries-Wong graph.
    17101711
    17111712        INPUT:
    17121713
    1713         - ``embedding`` -- two embeddings are available, and can be selected by
    1714           setting ``embedding`` to 1 or 2.
     1714        - ``embedding`` -- two embeddings are available, and can be
     1715          selected by setting ``embedding`` to 1 or 2.
    17151716
    17161717        EXAMPLES::
    17171718
    1718             sage: g = graphs.HarriesWong()
     1719            sage: g = graphs.HarriesWongGraph()
    17191720            sage: g.order()
    17201721            70
    17211722            sage: g.size()
     
    17241725            10
    17251726            sage: g.diameter()
    17261727            6
    1727             sage: orbits = g.automorphism_group(orbits = True)[-1]
    1728             sage: g.show(figsize=[15, 15], partition = orbits)
     1728            sage: orbits = g.automorphism_group(orbits=True)[-1]
     1729            sage: g.show(figsize=[15, 15], partition=orbits)
    17291730
    17301731        Alternative embedding::
    17311732
    1732             sage: graphs.HarriesWong(embedding=2).show()
     1733            sage: graphs.HarriesWongGraph(embedding=2).show()
    17331734
    17341735        TESTS::
    17351736
    1736             sage: graphs.HarriesWong(embedding=3)
     1737            sage: graphs.HarriesWongGraph(embedding=3)
    17371738            Traceback (most recent call last):
    17381739            ...
    17391740            ValueError: The value of embedding must be 1 or 2.
     
    17521753            d = g.get_pos()
    17531754
    17541755            # Binary tree (left side)
    1755             d[66] = (-9.5,0)
    1756             _line_embedding(g, [37, 65,67], first=(-8,2.25), last=(-8,-2.25))
    1757             _line_embedding(g, [36, 38, 64, 24, 68, 30], first=(-7,3), last=(-7,-3))
    1758             _line_embedding(g, [35, 39, 63, 25, 59, 29, 11, 5, 55, 23, 69, 31], first=(-6,3.5), last = (-6,-3.5))
    1759 
    1760             # Cube, corners : [9, 15, 21, 27, 45, 51, 57, 61]
    1761             _circle_embedding(g, [61, 9], center = (0,-1.5), shift = .2, radius = 4)
    1762             _circle_embedding(g, [27, 15], center = (0,-1.5), shift = .7, radius = 4*.707)
    1763             _circle_embedding(g, [51, 21], center = (0,2.5), shift = .2, radius = 4)
    1764             _circle_embedding(g, [45, 57], center = (0,2.5), shift = .7, radius = 4*.707)
     1756            d[66] = (-9.5, 0)
     1757            _line_embedding(g, [37, 65, 67], first=(-8, 2.25),
     1758                    last=(-8, -2.25))
     1759            _line_embedding(g, [36, 38, 64, 24, 68, 30], first=(-7, 3),
     1760                    last=(-7, -3))
     1761            _line_embedding(g, [35, 39, 63, 25, 59, 29, 11, 5, 55, 23, 69, 31],
     1762                    first=(-6, 3.5), last=(-6, -3.5))
     1763
     1764            # Cube, corners: [9, 15, 21, 27, 45, 51, 57, 61]
     1765            _circle_embedding(g, [61, 9], center=(0, -1.5), shift=.2,
     1766                    radius=4)
     1767            _circle_embedding(g, [27, 15], center=(0, -1.5), shift=.7,
     1768                    radius=4*.707)
     1769            _circle_embedding(g, [51, 21], center=(0, 2.5), shift=.2,
     1770                    radius=4)
     1771            _circle_embedding(g, [45, 57], center=(0, 2.5), shift=.7,
     1772                    radius=4*.707)
    17651773
    17661774            # Cube, subdivision
    1767             _line_embedding(g, [21, 22, 43, 44, 45], first=d[21], last = d[45])
    1768             _line_embedding(g, [21, 4, 3, 56, 57], first=d[21], last = d[57])
    1769             _line_embedding(g, [57, 12, 13, 14, 15], first=d[57], last = d[15])
    1770             _line_embedding(g, [15, 6, 7, 8, 9], first=d[15], last = d[9])
    1771             _line_embedding(g, [9, 10, 19, 20, 21], first=d[9], last = d[21])
    1772             _line_embedding(g, [45, 54, 53, 52, 51], first=d[45], last = d[51])
    1773             _line_embedding(g, [51, 50, 49, 58, 57], first=d[51], last = d[57])
    1774             _line_embedding(g, [51, 32, 33, 34, 61], first=d[51], last = d[61])
    1775             _line_embedding(g, [61, 62, 41, 40, 27], first=d[61], last = d[27])
    1776             _line_embedding(g, [9, 0, 1, 26, 27], first=d[9], last = d[27])
    1777             _line_embedding(g, [27, 28, 47, 46, 45], first=d[27], last = d[45])
    1778             _line_embedding(g, [15, 16, 17, 60, 61], first=d[15], last = d[61])
     1775            _line_embedding(g, [21, 22, 43, 44, 45], first=d[21], last=d[45])
     1776            _line_embedding(g, [21, 4, 3, 56, 57], first=d[21], last=d[57])
     1777            _line_embedding(g, [57, 12, 13, 14, 15], first=d[57], last=d[15])
     1778            _line_embedding(g, [15, 6, 7, 8, 9], first=d[15], last=d[9])
     1779            _line_embedding(g, [9, 10, 19, 20, 21], first=d[9], last=d[21])
     1780            _line_embedding(g, [45, 54, 53, 52, 51], first=d[45], last=d[51])
     1781            _line_embedding(g, [51, 50, 49, 58, 57], first=d[51], last=d[57])
     1782            _line_embedding(g, [51, 32, 33, 34, 61], first=d[51], last=d[61])
     1783            _line_embedding(g, [61, 62, 41, 40, 27], first=d[61], last=d[27])
     1784            _line_embedding(g, [9, 0, 1, 26, 27], first=d[9], last=d[27])
     1785            _line_embedding(g, [27, 28, 47, 46, 45], first=d[27], last=d[45])
     1786            _line_embedding(g, [15, 16, 17, 60, 61], first=d[15], last=d[61])
    17791787
    17801788            # Top vertices
    1781             _line_embedding(g, [2, 18, 42, 48], first=(-1,7), last=(3,7))
     1789            _line_embedding(g, [2, 18, 42, 48], first=(-1, 7), last=(3, 7))
    17821790
    17831791            return g
    17841792
     
    81538161
    81548162        sage: from sage.graphs.graph_generators import _circle_embedding
    81558163        sage: g = graphs.CycleGraph(5)
    8156         sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius = 2, shift = .5)
     8164        sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
    81578165        sage: g.show()
    81588166    """
    81598167    c_x, c_y = center
     
    81688176
    81698177    g.set_pos(d)
    81708178
    8171 def _line_embedding(g, vertices, first=(0,0), last = (0,1)):
     8179def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
    81728180    r"""
    81738181    Sets some vertices on a line in the embedding of a graph G.
    81748182
    81758183    This method modifies the graph's embedding so that the vertices of
    8176     ``vertices`` appear on a line, where the position of ``vertices[0]`` is the
    8177     pair ``first`` and the position of ``vertices[-1]`` is ``last``. The
    8178     vertices are evenly spaced.
     8184    ``vertices`` appear on a line, where the position of ``vertices[0]``
     8185    is the pair ``first`` and the position of ``vertices[-1]`` is
     8186    ``last``. The vertices are evenly spaced.
    81798187
    81808188    EXAMPLE::
    81818189
    81828190        sage: from sage.graphs.graph_generators import _line_embedding
    81838191        sage: g = graphs.PathGraph(5)
    8184         sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1,-1), last=(1,1))
     8192        sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
    81858193        sage: g.show()
    81868194    """
    8187     n = len(vertices)-1+0.
     8195    n = len(vertices) - 1.
    81888196
    81898197    fx, fy = first
    81908198    dx = (last[0] - first[0])/n
    81918199    dy = (last[1] - first[1])/n
    81928200
    81938201    d = g.get_pos()
    8194     for i, v in enumerate(vertices):
    8195         d[v] = (fx,fy)
     8202    for v in vertices:
     8203        d[v] = (fx, fy)
    81968204        fx += dx
    81978205        fy += dy