Ticket #12942: trac_12942.patch
File trac_12942.patch, 5.7 KB (added by , 8 years ago) 


sage/graphs/graph_generators.py
# HG changeset patch # User Nathann Cohen <nathann.cohen@gmail.com> # Date 1336937702 7200 # Node ID 5522e24da86604b28e35631a85bbb37a258a695f # Parent 2e9d0d8a6025045e3feacc75b979d2276ab7072f Adds Balaban's 10cage to Sage's graph generators diff git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
a b 97 97 98 98  :meth:`BidiakisCube <GraphGenerators.BidiakisCube>` 99 99  :meth:`BrinkmannGraph <GraphGenerators.BrinkmannGraph>` 100  :meth:`Balaban10Cage <GraphGenerators.Balaban10Cage>` 100 101  :meth:`ChvatalGraph <GraphGenerators.ChvatalGraph>` 101 102  :meth:`DesarguesGraph <GraphGenerators.DesarguesGraph>` 102 103  :meth:`DurerGraph <GraphGenerators.DurerGraph>` … … 106 107  :meth:`FranklinGraph <GraphGenerators.FranklinGraph>` 107 108  :meth:`FruchtGraph <GraphGenerators.FruchtGraph>` 108 109  :meth:`GoldnerHararyGraph <GraphGenerators.GoldnerHararyGraph>` 109  :meth:`GrotzschGraph <GraphGenerators.GrotzschGraph>` 110  :meth:`GrotzschGraph <GraphGenerators.GrotzschGraph>` 110 111  :meth:`HararyGraph <GraphGenerators.HararyGraph>` 111 112  :meth:`HeawoodGraph <GraphGenerators.HeawoodGraph>` 112 113  :meth:`HerschelGraph <GraphGenerators.HerschelGraph>` … … 2523 2524 2524 2525 return graph.Graph(networkx.chvatal_graph(), pos=pos_dict, name="Chvatal graph") 2525 2526 2527 def Balaban10Cage(self, embedding = 1): 2528 r""" 2529 Returns Balaban's 10 cage. 2530 2531 Balaban's 10cage is a 3regular graph with 70 vertices and 105 2532 edges. See its :wikipedia:`Wikipedia page <Balaban_10cage>`. 2533 2534 The default embedding gives a deeper understanding of the graph's 2535 automorphism group. It is divided into 4 layers (each layer being a set 2536 of points at equal distance from the drawing's center). From outside to 2537 inside : 2538 2539  L1 : The outer layer (vertices which are the furthest from the origin) 2540 is actually the disjoint union of two cycles of length 10. 2541 2542  L2 : The second layer is an independent set of 20 vertices. 2543 2544  L3 : The third layer is a matching on 10 vertices. 2545 2546  L4 : The inner layer (vertices which are the closest from the origin) 2547 is also the disjoint union of two cycles of length 10. 2548 2549 This graph is not vertextransitive, and its vertices are partitionned 2550 into 3 orbits : L2, L3, and the union of L1 of L4 whose elements are 2551 equivalent. 2552 2553 INPUT: 2554 2555  ``embedding``  two embeddings are available, and can be selected by 2556 setting ``embedding`` to be either 1 or 2. 2557 2558 EXAMPLE:: 2559 2560 sage: g = graphs.Balaban10Cage() 2561 sage: g.girth() 2562 10 2563 sage: g.chromatic_number() 2564 2 2565 sage: g.diameter() 2566 6 2567 sage: g.is_hamiltonian() 2568 True 2569 sage: g.show(figsize=[10,10]) 2570 """ 2571 2572 L = [9, 25, 19, 29, 13, 35, 13, 29, 19, 25, 9, 29, 29, 17, 33, 2573 21, 9,13, 31, 9, 25, 17, 9, 31, 27, 9, 17, 19, 29, 27, 2574 17, 9, 29, 33, 25,25, 21, 17, 17, 29, 35, 29, 17, 17, 2575 21, 25, 25, 33, 29, 9, 17, 27, 29, 19, 17, 9, 27, 31, 9, 2576 17, 25, 9, 31, 13, 9, 21, 33, 17, 29, 29] 2577 2578 g = graphs.LCFGraph(70, L, 1) 2579 g.name("Balaban's 10cage") 2580 2581 if embedding == 2: 2582 return g 2583 elif embedding != 1: 2584 raise ValueError("The value of embedding must be equal to either 1 or 2") 2585 2586 L3 = [5, 24, 35, 46, 29, 40, 51, 34, 45, 56] 2587 _circle_embedding(g, L3, center=(0,0), radius = 4.3) 2588 2589 L2 = [6, 4, 23, 25, 60, 36, 1, 47, 28, 30, 39, 41, 50, 52, 33, 9, 44, 20, 55, 57] 2590 _circle_embedding(g, L2, center=(0,0), radius = 5, shift=.5) 2591 2592 2593 L1a = [69, 68, 67, 66, 65, 64, 63, 62, 61, 0] 2594 L1b = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10] 2595 _circle_embedding(g, L1a, center=(0,0), radius = 6, shift = 3.25) 2596 _circle_embedding(g, L1b, center=(0,0), radius = 6, shift = 1.25) 2597 2598 L4a = [37, 2, 31, 38, 53, 32, 21, 54, 3, 22] 2599 _circle_embedding(g, L4a, center=(0,0), radius = 3, shift = 1.9) 2600 2601 L4b = [26, 59, 48, 27, 42, 49, 8, 43, 58, 7] 2602 _circle_embedding(g, L4b, center=(0,0), radius = 3, shift = 1.1) 2603 2604 return g 2605 2606 2526 2607 def DesarguesGraph(self): 2527 2608 """ 2528 2609 Returns the Desargues graph. … … 7384 7465 graphs = GraphGenerators() 7385 7466 7386 7467 7387 7388 7468 #################### 7469 # Helper functions # 7470 #################### 7471 7472 def _circle_embedding(g, vertices, center = (0,0), radius = 1, shift = 0): 7473 r""" 7474 Set some vertices on a circle in the embedding of a graph G. 7475 7476 This method modifies the graph's embedding so that the vertices listed in 7477 ``vertices`` appear in this ordering on a circle of given radius and 7478 center. The ``shift`` parameter is actually a rotation of the circle. A 7479 value of ``shift=1`` will replace in the drawing the `i` th element of the 7480 list by the `i1` th. Noninteger values are admissible, and a value of 7481 `\alpha` corresponds to a rotation of the circle by an angle of `\alpha 7482 2\Pi/n` (where `n` is the number of vertices set on the circle). 7483 7484 EXAMPLE:: 7485 7486 sage: from sage.graphs.graph_generators import _circle_embedding 7487 sage: g = graphs.CycleGraph(5) 7488 sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius = 2, shift = .5) 7489 sage: g.show() 7490 """ 7491 c_x, c_y = center 7492 n = len(vertices) 7493 d = g.get_pos() 7494 7495 for i,v in enumerate(vertices): 7496 i += shift 7497 v_x = c_x + radius * cos( 2*i*pi / n) 7498 v_y = c_y + radius * sin( 2*i*pi / n) 7499 d[v] = (v_x, v_y) 7500 7501 g.set_pos(d)