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

File trac_12945-balaban-11-cage.rebased.patch, 11.0 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 1336942234 -28800
    # Node ID 340df701e0954f1cc121ece3534a42937104b07e
    # Parent  b04704c9d1b2c3db7806b7e6f91593b57180025f
    trac #9136: Balaban 11-cage
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    9595Named Graphs
    9696------------
    9797
     98- :meth:`Balaban10Cage <GraphGenerators.Balaban10Cage>`
     99- :meth:`Balaban11Cage <GraphGenerators.Balaban11Cage>`
    98100- :meth:`BidiakisCube <GraphGenerators.BidiakisCube>`
    99101- :meth:`BrinkmannGraph <GraphGenerators.BrinkmannGraph>`
    100 - :meth:`Balaban10Cage <GraphGenerators.Balaban10Cage>`
    101102- :meth:`ChvatalGraph <GraphGenerators.ChvatalGraph>`
    102103- :meth:`DesarguesGraph <GraphGenerators.DesarguesGraph>`
    103104- :meth:`DurerGraph <GraphGenerators.DurerGraph>`
     
    23322333    #   Named Graphs
    23332334    #######################################################################
    23342335
     2336    def Balaban10Cage(self, embedding = 1):
     2337        r"""
     2338        Returns the Balaban 10-cage.
     2339
     2340        The Balaban 10-cage is a 3-regular graph with 70 vertices and
     2341        105 edges. See its :wikipedia:`Wikipedia page
     2342        <Balaban_10-cage>`.
     2343
     2344        The default embedding gives a deeper understanding of the
     2345        graph's automorphism group. It is divided into 4 layers (each
     2346        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
     2350          origin) is actually the disjoint union of two cycles of length
     2351          10.
     2352
     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
     2358          origin) is also the disjoint union of two cycles of length 10.
     2359
     2360        This graph is not vertex-transitive, and its vertices are
     2361        partitioned into 3 orbits : L2, L3, and the union of L1 of L4
     2362        whose elements are equivalent.
     2363
     2364        INPUT:
     2365
     2366        - ``embedding`` -- two embeddings are available, and can be
     2367          selected by setting ``embedding`` to be either 1 or 2.
     2368
     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])
     2381        """
     2382
     2383        L = [-9, -25, -19, 29, 13, 35, -13, -29, 19, 25, 9, -29, 29, 17, 33,
     2384              21, 9,-13, -31, -9, 25, 17, 9, -31, 27, -9, 17, -19, -29, 27,
     2385              -17, -9, -29, 33, -25,25, -21, 17, -17, 29, 35, -29, 17, -17,
     2386              21, -25, 25, -33, 29, 9, 17, -27, 29, 19, -17, 9, -27, 31, -9,
     2387              -17, -25, 9, 31, 13, -9, -21, -33, -17, -29, 29]
     2388
     2389        g = graphs.LCFGraph(70, L, 1)
     2390        g.name("Balaban 10-cage")
     2391
     2392        if embedding == 2:
     2393            return g
     2394        elif embedding != 1:
     2395            raise ValueError("The value of embedding must be either 1 or 2")
     2396
     2397        L3 = [5, 24, 35, 46, 29, 40, 51, 34, 45, 56]
     2398        _circle_embedding(g, L3, center=(0,0), radius = 4.3)
     2399
     2400        L2  = [6, 4, 23, 25, 60, 36, 1, 47, 28, 30, 39, 41, 50, 52, 33, 9, 44,
     2401                20, 55, 57]
     2402        _circle_embedding(g, L2, center=(0,0), radius = 5, shift=-.5)
     2403
     2404
     2405        L1a = [69, 68, 67, 66, 65, 64, 63, 62, 61, 0]
     2406        L1b = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10]
     2407        _circle_embedding(g, L1a, center=(0,0), radius = 6, shift = 3.25)
     2408        _circle_embedding(g, L1b, center=(0,0), radius = 6, shift = -1.25)
     2409
     2410        L4a = [37, 2, 31, 38, 53, 32, 21, 54, 3, 22]
     2411        _circle_embedding(g, L4a, center=(0,0), radius = 3, shift = 1.9)
     2412
     2413        L4b = [26, 59, 48, 27, 42, 49, 8, 43, 58, 7]
     2414        _circle_embedding(g, L4b, center=(0,0), radius = 3, shift = 1.1)
     2415
     2416        return g
     2417
     2418    def Balaban11Cage(self):
     2419        r"""
     2420        Returns the Balaban 11-cage.
     2421
     2422        For more information, see this `Wikipedia article on the Balaban
     2423        11-cage <http://en.wikipedia.org/wiki/Balaban_11-cage>`_.
     2424        """
     2425        pos_dict = {}
     2426        for j in range(8):
     2427            for i in range(8):
     2428                pos_dict[str(j) + str(i)]= [
     2429                        0.8 * float(cos(2*((8*j + i)*pi/64 + pi/128))),
     2430                        0.8 * float(sin(2*((8*j + i)*pi/64 + pi/128)))
     2431                ]
     2432            for i in range(4):
     2433                pos_dict['1' + str(j) + str(i)] = [
     2434                        1.1 * float(cos(2*((4*j + i)*pi/32 + pi/64))),
     2435                        1.1 * float(sin(2*((4*j + i)*pi/32 + pi/64)))
     2436                ]
     2437            for i in range(2):
     2438                pos_dict['1' + str(j) + str(i + 4)] = [
     2439                        1.4 * float(cos(2*((2*j + i)*pi/16 + pi/32))),
     2440                        1.4 * float(sin(2*((2*j + i)*pi/16 + pi/32)))
     2441                ]
     2442
     2443        edge_dict = {
     2444            "00": ["11"], "01": ["10"],   "02": ["53"], "03": ["52"],
     2445            "11": ["20"], "10": ["21"],   "53": ["22"], "52": ["23"],
     2446            "20": ["31"], "21": ["30"],   "22": ["33"], "23": ["32"],
     2447            "31": ["40"], "30": ["41"],   "33": ["43"], "32": ["42"],
     2448            "40": ["50"], "41": ["51"],   "43": ["12"], "42": ["13"],
     2449            "50": ["61"], "51": ["60"],   "12": ["63"], "13": ["62"],
     2450            "61": ["70"], "60": ["71"],   "63": ["72"], "62": ["73"],
     2451            "70": ["01"], "71": ["00"],   "72": ["03"], "73": ["02"],
     2452
     2453            "04": ["35"], "05": ["34"],   "06": ["37"], "07": ["36"],
     2454            "35": ["64"], "34": ["65"],   "37": ["66"], "36": ["67"],
     2455            "64": ["55"], "65": ["54"],   "66": ["17"], "67": ["16"],
     2456            "55": ["45"], "54": ["44"],   "17": ["46"], "16": ["47"],
     2457            "45": ["74"], "44": ["75"],   "46": ["76"], "47": ["77"],
     2458            "74": ["25"], "75": ["24"],   "76": ["27"], "77": ["26"],
     2459            "25": ["14"], "24": ["15"],   "27": ["56"], "26": ["57"],
     2460            "14": ["05"], "15": ["04"],   "56": ["07"], "57": ["06"],
     2461
     2462
     2463
     2464            "100": ["03", "04"],   "110": ["10", "12"],
     2465            "101": ["01", "06"],   "111": ["11", "13"],
     2466            "102": ["00", "07"],   "112": ["14", "16"],
     2467            "103": ["02", "05"],   "113": ["15", "17"],
     2468
     2469            "120": ["22", "24"],   "130": ["33", "36"],
     2470            "121": ["20", "26"],   "131": ["32", "37"],
     2471            "122": ["21", "27"],   "132": ["31", "34"],
     2472            "123": ["23", "25"],   "133": ["30", "35"],
     2473
     2474            "140": ["43", "45"],   "150": ["50", "52"],
     2475            "141": ["40", "46"],   "151": ["51", "53"],
     2476            "142": ["41", "47"],   "152": ["54", "56"],
     2477            "143": ["42", "44"],   "153": ["55", "57"],
     2478
     2479            "160": ["60", "66"],   "170": ["73", "76"],
     2480            "161": ["63", "65"],   "171": ["72", "77"],
     2481            "162": ["62", "64"],   "172": ["71", "74"],
     2482            "163": ["61", "67"],   "173": ["70", "75"],
     2483
     2484
     2485
     2486            "104": ["100", "102", "105"],   "114": ["110", "111", "115"],
     2487            "105": ["101", "103", "104"],   "115": ["112", "113", "114"],
     2488
     2489            "124": ["120", "121", "125"],   "134": ["130", "131", "135"],
     2490            "125": ["122", "123", "124"],   "135": ["132", "133", "134"],
     2491
     2492            "144": ["140", "141", "145"],   "154": ["150", "151", "155"],
     2493            "145": ["142", "143", "144"],   "155": ["152", "153", "154"],
     2494
     2495            "164": ["160", "161", "165"],   "174": ["170", "171", "175"],
     2496            "165": ["162", "163", "164"],   "175": ["172", "173", "174"]
     2497        }
     2498
     2499        return graph.Graph(edge_dict, pos=pos_dict, name="Balaban 11-cage")
     2500
    23352501    def BidiakisCube(self):
    23362502        r"""
    23372503        Returns the Bidiakis cube.
     
    25242690
    25252691        return graph.Graph(networkx.chvatal_graph(), pos=pos_dict, name="Chvatal graph")
    25262692
    2527     def Balaban10Cage(self, embedding = 1):
    2528         r"""
    2529         Returns the Balaban 10-cage.
    2530 
    2531         The Balaban 10-cage is a 3-regular graph with 70 vertices and
    2532         105 edges. See its :wikipedia:`Wikipedia page
    2533         <Balaban_10-cage>`.
    2534 
    2535         The default embedding gives a deeper understanding of the
    2536         graph's automorphism group. It is divided into 4 layers (each
    2537         layer being a set of points at equal distance from the drawing's
    2538         center). From outside to inside :
    2539 
    2540         - L1 : The outer layer (vertices which are the furthest from the
    2541           origin) is actually the disjoint union of two cycles of length
    2542           10.
    2543 
    2544         - L2 : The second layer is an independent set of 20 vertices.
    2545 
    2546         - L3 : The third layer is a matching on 10 vertices.
    2547 
    2548         - L4 : The inner layer (vertices which are the closest from the
    2549           origin) is also the disjoint union of two cycles of length 10.
    2550 
    2551         This graph is not vertex-transitive, and its vertices are
    2552         partitioned into 3 orbits : L2, L3, and the union of L1 of L4
    2553         whose elements are equivalent.
    2554 
    2555         INPUT:
    2556 
    2557         - ``embedding`` -- two embeddings are available, and can be
    2558           selected by setting ``embedding`` to be either 1 or 2.
    2559 
    2560         EXAMPLE::
    2561 
    2562            sage: g = graphs.Balaban10Cage()
    2563            sage: g.girth()
    2564            10
    2565            sage: g.chromatic_number()
    2566            2
    2567            sage: g.diameter()
    2568            6
    2569            sage: g.is_hamiltonian()
    2570            True
    2571            sage: g.show(figsize=[10,10])
    2572         """
    2573 
    2574         L = [-9, -25, -19, 29, 13, 35, -13, -29, 19, 25, 9, -29, 29, 17, 33,
    2575               21, 9,-13, -31, -9, 25, 17, 9, -31, 27, -9, 17, -19, -29, 27,
    2576               -17, -9, -29, 33, -25,25, -21, 17, -17, 29, 35, -29, 17, -17,
    2577               21, -25, 25, -33, 29, 9, 17, -27, 29, 19, -17, 9, -27, 31, -9,
    2578               -17, -25, 9, 31, 13, -9, -21, -33, -17, -29, 29]
    2579 
    2580         g = graphs.LCFGraph(70, L, 1)
    2581         g.name("Balaban 10-cage")
    2582 
    2583         if embedding == 2:
    2584             return g
    2585         elif embedding != 1:
    2586             raise ValueError("The value of embedding must be either 1 or 2")
    2587 
    2588         L3 = [5, 24, 35, 46, 29, 40, 51, 34, 45, 56]
    2589         _circle_embedding(g, L3, center=(0,0), radius = 4.3)
    2590 
    2591         L2  = [6, 4, 23, 25, 60, 36, 1, 47, 28, 30, 39, 41, 50, 52, 33, 9, 44,
    2592                 20, 55, 57]
    2593         _circle_embedding(g, L2, center=(0,0), radius = 5, shift=-.5)
    2594 
    2595 
    2596         L1a = [69, 68, 67, 66, 65, 64, 63, 62, 61, 0]
    2597         L1b = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10]
    2598         _circle_embedding(g, L1a, center=(0,0), radius = 6, shift = 3.25)
    2599         _circle_embedding(g, L1b, center=(0,0), radius = 6, shift = -1.25)
    2600 
    2601         L4a = [37, 2, 31, 38, 53, 32, 21, 54, 3, 22]
    2602         _circle_embedding(g, L4a, center=(0,0), radius = 3, shift = 1.9)
    2603 
    2604         L4b = [26, 59, 48, 27, 42, 49, 8, 43, 58, 7]
    2605         _circle_embedding(g, L4b, center=(0,0), radius = 3, shift = 1.1)
    2606 
    2607         return g
    2608 
    2609 
    26102693    def DesarguesGraph(self):
    26112694        """
    26122695        Returns the Desargues graph.