# Ticket #13578: trac_13578-rev.patch

File trac_13578-rev.patch, 6.8 KB (added by ncohen, 9 years ago)
• ## sage/graphs/generators/families.py

# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1349628950 -7200
# Node ID e7b3b1cc4441ca2deff7d62b524d7bd26294b7a0
# Parent  477fc9acc814949a648436ac568f9e337f32658d
graphs.RingedTree -- reviewer's patch

diff --git a/sage/graphs/generators/families.py b/sage/graphs/generators/families.py
 a This file gathers generators for some families of graphs. - :meth:RingedTree  AUTHORS: - David Coudert (2012) Ringed Trees #                         http://www.gnu.org/licenses/ ################################################################################ # import from Python standard library from math import sin, cos, pi # import from Sage library from sage.graphs.graph import Graph def RingedTree(self, k): def RingedTree(self, k, vertex_labels = True): r""" Return the ringed tree on k-levels. A ringed tree of level k is a fully binary tree with k levels (counting A ringed tree of level k is a binary tree with k levels (counting the root as a level), in which all vertices at the same level are connected by a ring. More precisely, we can use a binary string to represent each vertex in the tree, such that the root (at level 0) is represented by an empty string, and the left child and the right child of a vertex with string \sigma are represented as \sigma0 and \sigma1, respectively. Then, at each level i = 1, 2, \cdots , k-1, we connect two vertices u and v represented by binary strings \sigma_u and \sigma_v if (\sigma_u + 1) \pmod{2^i}\equiv \sigma_v, where the addition treats the binary strings as the integers they represent. by a ring. More precisely, in each layer of the binary tree (i.e. a layer is the set of vertices [2^i...2^{i+1}-1]) two vertices u,v are adjacent if u=v+1 or if u=2^i and v=2^{i+1}-1. Ringed trees are defined in [CFHM12]_. INPUT: - k -- the number of levels of the ringed tree. EXAMPLE: - vertex_labels (boolean) -- whether to label vertices as binary words (default) or as integers. EXAMPLE:: sage: G = graphs.RingedTree(5) sage: P = G.plot(vertex_labels=False, vertex_size=10) sage: P.show() # long time sage: G.vertices() ['', '0', '00', '000', '0000', '0001', '001', '0010', '0011', '01', '010', '0100', '0101', '011', '0110', '0111', '1', '10', '100', '1000', '1001', '101', '1010', '1011', '11', '110', '1100', '1101', '111', '1110', '1111'] TEST: TEST:: sage: G = graphs.RingedTree(-1) Traceback (most recent call last): ... ValueError: The number of levels must be >= 1. sage: G = graphs.RingedTree(5, vertex_labels = False) sage: G.vertices() [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] REFERENCES: .. [CFHM12] On the Hyperbolicity of Small-World and Tree-Like Random Graphs Wei Chen, Wenjie Fang, Guangda Hu, Michael W. Mahoney http://arxiv.org/abs/1201.1717 """ if k<1: raise ValueError('The number of levels must be >= 1.') E = [] W = {} # We first add the tree edges W[0] = [''] for l in xrange(k-1): W[l+1] = [] for r in W[l]: E.append( (r,r+'0') ) E.append( (r,r+'1') ) W[l+1].append(r+'0') W[l+1].append(r+'1') from sage.graphs.graph_generators import _circle_embedding from sage.graphs.graph_generators import GraphGenerators # We then add the ring edges and fix positions of vertices for nice drawing pos_dict = {'':(0,0.2)} for l in xrange(1,k): twol = 1<1: # to avoid adding twice edge ('0','1') E.append( (W[l][0],W[l][twol-1]) ) for i in xrange(twol-1): theta = (2*i+1)*theta0 pos_dict[ W[l][i] ] = ( r*sin(theta), r*cos(theta) ) E.append( (W[l][i],W[l][i+1]) ) # Creating the Balanced tree, which contains most edges already g = GraphGenerators().BalancedTree(2,k-1) g.name('Ringed Tree on '+str(k)+' levels') return Graph(E, pos=pos_dict, name='Ringed Tree on '+str(k)+' levels' ) # We consider edges layer by layer for i in range(1,k): vertices = range(2**(i)-1,2**(i+1)-1) # Add the missing edges g.add_cycle(vertices) # And set the vertices' positions radius = i if i <= 1 else 1.5**i shift = -2**(i-2)+.5 if i > 1 else 0 _circle_embedding(g, vertices, radius = radius, shift = shift) # Specific position for the central vertex g.get_pos()[0] = (0,0.2) # Relabel vertices as binary words if not vertex_labels: return g vertices = [''] for i in range(k-1): for j in range(2**(i)-1,2**(i+1)-1): v = vertices[j] vertices.append(v+'0') vertices.append(v+'1') g.relabel(vertices) return g
• ## sage/graphs/graph_generators.py

diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
 a - :meth:FuzzyBallGraph  - :meth:GeneralizedPetersenGraph  - :meth:HanoiTowerGraph  - :meth:HyperStarGraph  - :meth:KneserGraph  - :meth:LCFGraph  - :meth:NStarGraph  - :meth:OddGraph  - :meth:PaleyGraph  - :meth:RingedTree  - :meth:line_graph_forbidden_subgraphs  - :meth:PermutationGraph  - :meth:trees  Chessboard graphs : - :meth:BishopGraph  - :meth:KingGraph  - :meth:KnightGraph  - :meth:QueenGraph  - :meth:RookGraph  - :meth:RingedTree  Pseudofractal graphs -------------------- - :meth:DorogovtsevGoltsevMendesGraph  Random graphs -------------