Ticket #12981: trac_12981.patch

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

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1337509974 -7200
    # Node ID 5a296c09be760accbf4743e9e62a682737b368c3
    # Parent  36200f727b53c6a2b3b5a66c474ca2730cc41478
    Ljubljana graph generator
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    120120- :meth:`HerschelGraph <GraphGenerators.HerschelGraph>`
    121121- :meth:`HigmanSimsGraph <GraphGenerators.HigmanSimsGraph>`
    122122- :meth:`HoffmanSingletonGraph <GraphGenerators.HoffmanSingletonGraph>`
     123- :meth:`LjubljanaGraph <GraphGenerators.LjubljanaGraph>`
    123124- :meth:`MoebiusKantorGraph <GraphGenerators.MoebiusKantorGraph>`
    124125- :meth:`MoserSpindle <GraphGenerators.MoserSpindle>`
    125126- :meth:`PappusGraph <GraphGenerators.PappusGraph>`
     
    41884189        H.set_pos(pos_dict)
    41894190        return H
    41904191
     4192    def LjubljanaGraph(self, embedding = 1):
     4193        r"""
     4194        Returns the Ljubljana Graph.
     4195
     4196        The Ljubljana graph is a bipartite 3-regular graph on 112 vertices and
     4197        168 edges. It is not vertex-transitive as it has two orbits which are
     4198        also independent sets og size 56. See the :wikipedia:`Wikipedia page on
     4199        the Ljubljana Graph <Ljubljana_graph>`.
     4200
     4201        The default embedding is obtained from the Heawood graph.
     4202
     4203        INPUT:
     4204
     4205        - ``embedding`` -- two embeddings are available, and can be
     4206          selected by setting ``embedding`` to 1 or 2.
     4207
     4208        EXAMPLES::
     4209
     4210            sage: g = graphs.LjubljanaGraph()
     4211            sage: g.order()
     4212            112
     4213            sage: g.size()
     4214            168
     4215            sage: g.girth()
     4216            10
     4217            sage: g.diameter()
     4218            8
     4219            sage: g.show(figsize=[10, 10])
     4220            sage: graphs.LjubljanaGraph(embedding=2).show(figsize=[10, 10])
     4221
     4222        TESTS::
     4223
     4224            sage: graphs.LjubljanaGraph(embedding=3)
     4225            Traceback (most recent call last):
     4226            ...
     4227            ValueError: The value of embedding must be 1 or 2.
     4228        """
     4229
     4230        L = [47, -23, -31, 39, 25, -21, -31, -41, 25, 15, 29, -41, -19, 15,
     4231             -49, 33, 39, -35, -21, 17, -33, 49, 41, 31, -15, -29, 41, 31,
     4232             -15, -25, 21, 31, -51, -25, 23, 9, -17, 51, 35, -29, 21, -51,
     4233             -39, 33, -9, -51, 51, -47, -33, 19, 51, -21, 29, 21, -31, -39]
     4234
     4235        g = graphs.LCFGraph(112, L, 2)
     4236        g.name("Ljubljana graph")
     4237
     4238        if embedding == 1:
     4239            return g
     4240
     4241        elif embedding == 2:
     4242            dh = graphs.HeawoodGraph().get_pos()
     4243
     4244            # Correspondance between the vertices of the Heawood Graph and
     4245            # 8-sets of the Ljubljana Graph.
     4246
     4247            d = {
     4248                0: [1, 21, 39, 57, 51, 77, 95, 107],
     4249                1: [2, 22, 38, 58, 50, 78, 94, 106],
     4250                2: [3, 23, 37, 59, 49, 79, 93, 105],
     4251                3: [4, 24, 36, 60, 48, 80, 92, 104],
     4252                4: [5, 25, 35, 61, 15, 81, 91, 71],
     4253                9: [6, 26, 44, 62, 16, 82, 100, 72],
     4254                10: [7, 27, 45, 63, 17, 83, 101, 73],
     4255                11: [8, 28, 46, 64, 18, 84, 102, 74],
     4256                12: [9, 29, 47, 65, 19, 85, 103, 75],
     4257                13: [10, 30, 0, 66, 20, 86, 56, 76],
     4258                8: [11, 31, 111, 67, 99, 87, 55, 43],
     4259                7: [12, 32, 110, 68, 98, 88, 54, 42],
     4260                6: [13, 33, 109, 69, 97, 89, 53, 41],
     4261                5: [14, 34, 108, 70, 96, 90, 52, 40]
     4262                }
     4263
     4264            # The vertices of each 8-set is plotted on a circle, and the circles
     4265            # is slowly shifted to obtain a symmetric drawing.
     4266
     4267            for i, (u, vertices) in enumerate(d.iteritems()):
     4268                i = i+0.
     4269                _circle_embedding(g, vertices, center=dh[u], radius=.1, shift=8*i/14)
     4270
     4271            return g
     4272        else:
     4273            raise ValueError("The value of embedding must be 1 or 2.")
     4274
     4275        return g
     4276
    41914277    def KneserGraph(self,n,k):
    41924278        r"""
    41934279        Returns the Kneser Graph with parameters `n, k`.