Ticket #12980: trac_12980.patch

File trac_12980.patch, 6.7 KB (added by ncohen, 9 years ago)
  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1337506071 -7200
    # Node ID e8ba27e3597d3da360f3a8826ef5f166b61fa819
    # Parent  03b654e807816c6a1ceb005eb90147ec00f0cdaa
    Harries-Wong graph generator and embedding
    
    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>`
    118119- :meth:`HeawoodGraph <GraphGenerators.HeawoodGraph>`
    119120- :meth:`HerschelGraph <GraphGenerators.HerschelGraph>`
    120121- :meth:`HigmanSimsGraph <GraphGenerators.HigmanSimsGraph>`
     
    16741675        else:
    16751676            raise ValueError("The value of embedding must be 1 or 2.")
    16761677
     1678    def HarriesWong(self, embedding=1):
     1679        r"""
     1680        Returns the Harries-Wong Graph.
     1681
     1682        See the :wikipedia:`Wikipedia page on the Harries-Wong graph
     1683        <Harries-Wong_graph>`.
     1684
     1685        *About the default embedding:*
     1686
     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.
     1710
     1711        INPUT:
     1712
     1713        - ``embedding`` -- two embeddings are available, and can be selected by
     1714          setting ``embedding`` to 1 or 2.
     1715
     1716        EXAMPLES::
     1717
     1718            sage: g = graphs.HarriesWong()
     1719            sage: g.order()
     1720            70
     1721            sage: g.size()
     1722            105
     1723            sage: g.girth()
     1724            10
     1725            sage: g.diameter()
     1726            6
     1727            sage: orbits = g.automorphism_group(orbits = True)[-1]
     1728            sage: g.show(figsize=[15, 15], partition = orbits)
     1729
     1730        Alternative embedding::
     1731
     1732            sage: graphs.HarriesWong(embedding=2).show()
     1733
     1734        TESTS::
     1735
     1736            sage: graphs.HarriesWong(embedding=3)
     1737            Traceback (most recent call last):
     1738            ...
     1739            ValueError: The value of embedding must be 1 or 2.
     1740        """
     1741
     1742        L = [9, 25, 31, -17, 17, 33, 9, -29, -15, -9, 9, 25, -25, 29, 17, -9,
     1743             9, -27, 35, -9, 9, -17, 21, 27, -29, -9, -25, 13, 19, -9, -33,
     1744             -17, 19, -31, 27, 11, -25, 29, -33, 13, -13, 21, -29, -21, 25,
     1745             9, -11, -19, 29, 9, -27, -19, -13, -35, -9, 9, 17, 25, -9, 9, 27,
     1746             -27, -21, 15, -9, 29, -29, 33, -9, -25]
     1747
     1748        g = graphs.LCFGraph(70, L, 1)
     1749        g.name("Harries-Wong graph")
     1750
     1751        if embedding == 1:
     1752            d = g.get_pos()
     1753
     1754            # 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)
     1765
     1766            # 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])
     1779
     1780            # Top vertices
     1781            _line_embedding(g, [2, 18, 42, 48], first=(-1,7), last=(3,7))
     1782
     1783            return g
     1784
     1785        elif embedding == 2:
     1786            return g
     1787        else:
     1788            raise ValueError("The value of embedding must be 1 or 2.")
     1789
    16771790    def HouseGraph(self):
    16781791        """
    16791792        Returns a house graph with 5 nodes.
     
    80488161        d[v] = (v_x, v_y)
    80498162
    80508163    g.set_pos(d)
     8164
     8165def _line_embedding(g, vertices, first=(0,0), last = (0,1)):
     8166    r"""
     8167    Sets some vertices on a line in the embedding of a graph G.
     8168
     8169    This method modifies the graph's embedding so that the vertices of
     8170    ``vertices`` appear on a line, where the position of ``vertices[0]`` is the
     8171    pair ``first`` and the position of ``vertices[-1]`` is ``last``. The
     8172    vertices are evenly spaced.
     8173
     8174    EXAMPLE::
     8175
     8176        sage: from sage.graphs.graph_generators import _line_embedding
     8177        sage: g = graphs.PathGraph(5)
     8178        sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1,-1), last=(1,1))
     8179        sage: g.show()
     8180    """
     8181    n = len(vertices)-1+0.
     8182
     8183    fx, fy = first
     8184    dx = (last[0] - first[0])/n
     8185    dy = (last[1] - first[1])/n
     8186
     8187    d = g.get_pos()
     8188    for i, v in enumerate(vertices):
     8189        d[v] = (fx,fy)
     8190        fx += dx
     8191        fy += dy