# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1362934587 3600
# Node ID 1699dbc4723b75833fc7f26a620c60201de501bc
# Parent e96fafb64ae2d32fc7adbf5ee537d9fb0b4766a8
Circulant digraphs
diff git a/sage/graphs/digraph_generators.py b/sage/graphs/digraph_generators.py
a

b


10  10  
11  11  :meth:`~DiGraphGenerators.ButterflyGraph`  Returns a ndimensional butterfly graph. 
12  12  :meth:`~DiGraphGenerators.Circuit`  Returns the circuit on `n` vertices. 
 13  :meth:`~DiGraphGenerators.Circulant`  Returns a circulant digraph on `n` vertices from a set of integers. 
13  14  :meth:`~DiGraphGenerators.DeBruijn`  Returns the De Bruijn digraph with parameters `k,n`. 
14  15  :meth:`~DiGraphGenerators.GeneralizedDeBruijn`  Returns the generalized de Bruijn digraph of order `n` and degree `d`. 
15  16  :meth:`~DiGraphGenerators.ImaseItoh`  Returns the digraph of Imase and Itoh of order `n` and degree `d`. 
… 
… 

382  383  g.add_edge(n1,0) 
383  384  return g 
384  385  
 386  def Circulant(self,n,integers): 
 387  r""" 
 388  Returns a circulant digraph on `n` vertices from a set of integers. 
 389  
 390  INPUT: 
 391  
 392   ``n`` (integer)  number of vertices. 
 393  
 394   ``integers``  the list of integers such that there is an edge from 
 395  `i` to `j` if and only if ``(ji) in integers``. 
 396  
 397  EXAMPLE:: 
 398  
 399  sage: digraphs.Circulant(13,[3,5,7]) 
 400  Circulant graph ([3, 5, 7]): Digraph on 13 vertices 
 401  """ 
 402  from sage.graphs.graph_plot import _circle_embedding 
 403  
 404  G=DiGraph(n, name="Circulant graph ("+str(integers)+")") 
 405  _circle_embedding(G, range(n)) 
 406  
 407  for v in range(n): 
 408  G.add_edges([(v,(v+j)%n) for j in integers]) 
 409  
 410  return G 
 411  
385  412  def DeBruijn(self, k, n, vertices = 'strings'): 
386  413  r""" 
387  414  Returns the De Bruijn digraph with parameters `k,n`. 
diff git a/sage/graphs/generators/families.py b/sage/graphs/generators/families.py
a

b


573  573  r""" 
574  574  Returns a circulant graph with n nodes. 
575  575  
576   A circulant graph has the property that the vertex i is connected 
577   with the vertices i+j and ij for each j in adj. 
 576  A circulant graph has the property that the vertex `i` is connected 
 577  with the vertices `i+j` and `ij` for each j in adj. 
578  578  
579  579  INPUT: 
580  580  
… 
… 

661  661  (4, 5), 
662  662  (5, 6)] 
663  663  """ 
 664  from sage.graphs.graph_plot import _circle_embedding 
 665  
664  666  if not isinstance(adjacency,list): 
665  667  adjacency=[adjacency] 
666   pos_dict = {} 
667   for i in range(n): 
668   x = float(cos((pi/2) + ((2*pi)/n)*i)) 
669   y = float(sin((pi/2) + ((2*pi)/n)*i)) 
670   pos_dict[i] = (x,y) 
 668  
671  669  G=graph.Graph(n, name="Circulant graph ("+str(adjacency)+")") 
672   G._pos=pos_dict 
 670  _circle_embedding(G, range(n)) 
 671  
673  672  for v in G: 
674  673  G.add_edges([(v,(v+j)%n) for j in adjacency]) 
675   G.add_edges([(v,(vj)%n) for j in adjacency]) 
 674  
676  675  return G 
677  676  
678  677  def CubeGraph(n): 