# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1360871889 3600
# Node ID 93919526b840ec57e69b4a04c6eb6b0caadbe88c
# Parent ca877a1fdc06f49f74e422f648ed5c05fea1a570
Tournament and directed path constructors
diff git a/sage/graphs/digraph_generators.py b/sage/graphs/digraph_generators.py
a

b


3  3  
4  4  Generators for common digraphs. 
5  5  
 6  .. csvtable:: 
 7  :class: contentstable 
 8  :widths: 30, 70 
 9  :delim:  
 10  
 11  :meth:`~DiGraphGenerators.ButterflyGraph`  Returns a ndimensional butterfly graph. 
 12  :meth:`~DiGraphGenerators.Circuit`  Returns the circuit on `n` vertices. 
 13  :meth:`~DiGraphGenerators.DeBruijn`  Returns the De Bruijn digraph with parameters `k,n`. 
 14  :meth:`~DiGraphGenerators.GeneralizedDeBruijn`  Returns the generalized de Bruijn digraph of order `n` and degree `d`. 
 15  :meth:`~DiGraphGenerators.ImaseItoh`  Returns the digraph of Imase and Itoh of order `n` and degree `d`. 
 16  :meth:`~DiGraphGenerators.Kautz`  Returns the Kautz digraph of degree `d` and diameter `D`. 
 17  :meth:`~DiGraphGenerators.Path`  Returns a directed path on `n` vertices. 
 18  :meth:`~DiGraphGenerators.RandomDirectedGNC`  Returns a random GNC (growing network with copying) digraph with `n` vertices. 
 19  :meth:`~DiGraphGenerators.RandomDirectedGNM`  Returns a random labelled digraph on `n` nodes and `m` arcs. 
 20  :meth:`~DiGraphGenerators.RandomDirectedGNP`  Returns a random digraph on `n` nodes. 
 21  :meth:`~DiGraphGenerators.RandomDirectedGN`  Returns a random GN (growing network) digraph with `n` vertices. 
 22  :meth:`~DiGraphGenerators.RandomDirectedGNR`  Returns a random GNR (growing network with redirection) digraph. 
 23  :meth:`~DiGraphGenerators.Tournament`  Returns a tournament on `n` vertices. 
 24  
6  25  AUTHORS: 
7  26  
8  27   Robert L. Miller (2006) 
9  28   Emily A. Kirkman (2006) 
10  29   Michael C. Yurko (2009) 
11  30   David Coudert (2012) 
 31  
 32  Functions and methods 
 33   
 34  
12  35  """ 
13  36  
14  37  ################################################################################ 
… 
… 

50  73   DeBruijn 
51  74   GeneralizedDeBruijn 
52  75   Kautz 
 76   Path 
53  77   ImaseItoh 
 78   Tournament 
54  79  
55  80  
56  81  
… 
… 

260  285  raise NotImplementedError, "vertices must be 'strings' or 'vectors'." 
261  286  return DiGraph(butterfly) 
262  287  
 288  def Path(self,n): 
 289  r""" 
 290  Returns a directed path on `n` vertices. 
 291  
 292  INPUT: 
 293  
 294   ``n`` (integer)  number of vertices in the path. 
 295  
 296  EXAMPLES:: 
 297  
 298  sage: g = digraphs.Path(5) 
 299  sage: g.vertices() 
 300  [0, 1, 2, 3, 4] 
 301  sage: g.size() 
 302  4 
 303  sage: g.automorphism_group().cardinality() 
 304  1 
 305  """ 
 306  if n<0: 
 307  raise ValueError("The number of vertices must be a positive integer.") 
 308  
 309  g = DiGraph() 
 310  g.name("Path on "+str(n)+" vertices") 
 311  
 312  if n: 
 313  g.add_path(range(n)) 
 314  
 315  g.set_pos({i:(i,0) for i in range(n)}) 
 316  return g 
 317  
 318  def Tournament(self,n): 
 319  r""" 
 320  Returns a tournament on `n` vertices. 
 321  
 322  In this tournament there is an edge from `i` to `j` if `i<j`. 
 323  
 324  INPUT: 
 325  
 326   ``n`` (integer)  number of vertices in the tournament. 
 327  
 328  EXAMPLES:: 
 329  
 330  sage: g = digraphs.Tournament(5) 
 331  sage: g.vertices() 
 332  [0, 1, 2, 3, 4] 
 333  sage: g.size() 
 334  10 
 335  sage: g.automorphism_group().cardinality() 
 336  1 
 337  """ 
 338  if n<0: 
 339  raise ValueError("The number of vertices must be a positive integer.") 
 340  
 341  g = DiGraph() 
 342  g.name("Tournament on "+str(n)+" vertices") 
 343  
 344  for i in range(n1): 
 345  for j in range(i+1, n): 
 346  g.add_edge(i,j) 
 347  
 348  if n: 
 349  from sage.graphs.graph_plot import _circle_embedding 
 350  _circle_embedding(g, range(n)) 
 351  
 352  return g 
 353  
263  354  def Circuit(self,n): 
264  355  r""" 
265  356  Returns the circuit on `n` vertices 
… 
… 

289  380  else: 
290  381  g.add_edges([(i,i+1) for i in xrange(n1)]) 
291  382  g.add_edge(n1,0) 
292   return g 
 383  return g 
293  384  
294  385  def DeBruijn(self, k, n, vertices = 'strings'): 
295  386  r""" 
296   Returns the De Bruijn diraph with parameters `k,n`. 
 387  Returns the De Bruijn digraph with parameters `k,n`. 
297  388  
298  389  The De Bruijn digraph with parameters `k,n` is built upon a set of 
299  390  vertices equal to the set of words of length `n` from a dictionary of 