Ticket #12945: trac_12945-balaban-11-cage.2.patch

File trac_12945-balaban-11-cage.2.patch, 6.4 KB (added by kini, 7 years ago)

apply to $SAGE_ROOT/devel/sage

  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Keshav Kini <keshav.kini@gmail.com>
    # Date 1336988063 -28800
    # Node ID ab2253063e2cd8af58fb3f7f535fc60b617bca1c
    # Parent  267492bb09f3afab1a62479bb5a15874a5287eca
    Add some doctests, minor fixes
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    23332333    #   Named Graphs
    23342334    #######################################################################
    23352335
    2336     def Balaban10Cage(self, embedding = 1):
     2336    def Balaban10Cage(self, embedding=1):
    23372337        r"""
    23382338        Returns the Balaban 10-cage.
    23392339
     
    23442344        The default embedding gives a deeper understanding of the
    23452345        graph's automorphism group. It is divided into 4 layers (each
    23462346        layer being a set of points at equal distance from the drawing's
    2347         center). From outside to inside :
    2348 
    2349         - L1 : The outer layer (vertices which are the furthest from the
     2347        center). From outside to inside:
     2348
     2349        - L1: The outer layer (vertices which are the furthest from the
    23502350          origin) is actually the disjoint union of two cycles of length
    23512351          10.
    23522352
    2353         - L2 : The second layer is an independent set of 20 vertices.
    2354 
    2355         - L3 : The third layer is a matching on 10 vertices.
    2356 
    2357         - L4 : The inner layer (vertices which are the closest from the
     2353        - L2: The second layer is an independent set of 20 vertices.
     2354
     2355        - L3: The third layer is a matching on 10 vertices.
     2356
     2357        - L4: The inner layer (vertices which are the closest from the
    23582358          origin) is also the disjoint union of two cycles of length 10.
    23592359
    23602360        This graph is not vertex-transitive, and its vertices are
    2361         partitioned into 3 orbits : L2, L3, and the union of L1 of L4
     2361        partitioned into 3 orbits: L2, L3, and the union of L1 of L4
    23622362        whose elements are equivalent.
    23632363
    23642364        INPUT:
     
    23662366        - ``embedding`` -- two embeddings are available, and can be
    23672367          selected by setting ``embedding`` to be either 1 or 2.
    23682368
    2369         EXAMPLE::
    2370 
    2371            sage: g = graphs.Balaban10Cage()
    2372            sage: g.girth()
    2373            10
    2374            sage: g.chromatic_number()
    2375            2
    2376            sage: g.diameter()
    2377            6
    2378            sage: g.is_hamiltonian()
    2379            True
    2380            sage: g.show(figsize=[10,10])
     2369        EXAMPLES::
     2370
     2371            sage: g = graphs.Balaban10Cage()
     2372            sage: g.girth()
     2373            10
     2374            sage: g.chromatic_number()
     2375            2
     2376            sage: g.diameter()
     2377            6
     2378            sage: g.is_hamiltonian()
     2379            True
     2380            sage: g.show(figsize=[10,10])
     2381
     2382        TESTS::
     2383
     2384            sage: graphs.Balaban10Cage(embedding='foo')
     2385            Traceback (most recent call last):
     2386            ...
     2387            ValueError: The value of embedding must be 1 or 2.
    23812388        """
    23822389
    23832390        L = [-9, -25, -19, 29, 13, 35, -13, -29, 19, 25, 9, -29, 29, 17, 33,
     
    23922399        if embedding == 2:
    23932400            return g
    23942401        elif embedding != 1:
    2395             raise ValueError("The value of embedding must be either 1 or 2")
     2402            raise ValueError("The value of embedding must be 1 or 2.")
    23962403
    23972404        L3 = [5, 24, 35, 46, 29, 40, 51, 34, 45, 56]
    23982405        _circle_embedding(g, L3, center=(0,0), radius = 4.3)
     
    24282435          selected by setting ``embedding`` to be 1, 2, or 3.
    24292436
    24302437          - The first embedding is the one appearing on page 9 of the
    2431             Fifth Annual Graph Drawing Contest report [FAGDC]_.
     2438            Fifth Annual Graph Drawing Contest report [FAGDC]_. It
     2439            separates vertices based on their eccentricity (see
     2440            :meth:`eccentricity()
     2441            <sage.graphs.generic_graph.GenericGraph.eccentricity>`).
    24322442
    24332443          - The second embedding has been produced just for Sage and is
    24342444            meant to emphasize the automorphism group's 6 orbits.
     
    24592469
    24602470        Our many embeddings::
    24612471
    2462             sage: graphs.Balaban11Cage(embedding=1).show(figsize=[10,10])
    2463             sage: graphs.Balaban11Cage(embedding=2).show(figsize=[10,10])
    2464             sage: graphs.Balaban11Cage(embedding=3).show(figsize=[10,10])
     2472            sage: g1 = graphs.Balaban11Cage(embedding=1)
     2473            sage: g2 = graphs.Balaban11Cage(embedding=2)
     2474            sage: g3 = graphs.Balaban11Cage(embedding=3)
     2475            sage: g1.show(figsize=[10,10])
     2476            sage: g2.show(figsize=[10,10])
     2477            sage: g3.show(figsize=[10,10])
     2478
     2479        Proof that the embeddings are the same graph::
     2480
     2481            sage: g1.is_isomorphic(g2) # g2 and g3 are obviously isomorphic
     2482            True
     2483
     2484        TESTS::
     2485
     2486            sage: graphs.Balaban11Cage(embedding='xyzzy')
     2487            Traceback (most recent call last):
     2488            ...
     2489            ValueError: The value of embedding must be 1, 2, or 3.
    24652490
    24662491        REFERENCES:
    24672492
    24682493        .. [FAGDC] Fifth Annual Graph Drawing Contest
    2469           P. Eaded, J. Marks, P.Mutzel, S. North
    2470           http://www.merl.com/papers/docs/TR98-16.pdf
     2494           P. Eaded, J. Marks, P.Mutzel, S. North
     2495           http://www.merl.com/papers/docs/TR98-16.pdf
    24712496        """
    24722497        if embedding == 1:
    24732498            pos_dict = {}
     
    25652590            v2 = [88, 3, 19, 55, 67, 42, 101, 33, 77, 5, 17, 57, 69, 71, 73,
    25662591                  75, 11, 61, 28, 9, 37, 26, 46, 95, 13, 63, 81, 83, 108, 106,
    25672592                  48, 97]
    2568             l1 = [35, 93, 1, 24, 53, 7, 44, 59, 15, 65, 79, 21, 110, 90, 50, 99]
    2569             l2 = [87, 4, 18, 56, 68, 41, 102, 32, 12, 62, 29, 84, 38, 105, 47, 96]
     2593            l1 = [35, 93, 1, 24, 53, 7, 44, 59, 15, 65, 79, 21, 110, 90, 50,
     2594                  99]
     2595            l2 = [87, 4, 18, 56, 68, 41, 102, 32, 12, 62, 29, 84, 38, 105, 47,
     2596                  96]
    25702597
    25712598            d = g.get_pos()
    25722599            for i,v in enumerate(v1):
     
    25902617            return g
    25912618
    25922619        else:
    2593             raise ValueError("The value of embedding must be either 1 or 2")
     2620            raise ValueError("The value of embedding must be 1, 2, or 3.")
    25942621
    25952622    def BidiakisCube(self):
    25962623        r"""
     
    76497676# Helper functions #
    76507677####################
    76517678
    7652 def _circle_embedding(g, vertices, center = (0,0), radius = 1, shift = 0):
     7679def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
    76537680    r"""
    76547681    Set some vertices on a circle in the embedding of a graph G.
    76557682