# HG changeset patch
# User Sebastien Labbe <slabqc@gmail.com>
# Date 1255949995 7200
# Node ID 52730b87e0fe17eb5282dec340fe8957a150f832
# Parent f9c29678efec723cd110e2f85c97e1ab9e494655
#7246: Reviewer's patch.
diff r f9c29678efec r 52730b87e0fe sage/graphs/graph_generators.py
a

b


3751  3751  
3752  3752  EXAMPLES:: 
3753  3753  
3754   sage: db=digraphs.DeBruijn(2,2) 
 3754  sage: db=digraphs.DeBruijn(2,2); db 
 3755  De Bruijn digraph (n=2, k=2): Looped digraph on 4 vertices 
3755  3756  sage: db.order() 
3756  3757  4 
3757  3758  sage: db.size() 
3758  3759  8 
3759   """ 
3760   
 3760  
 3761  TESTS:: 
 3762  
 3763  sage: digraphs.DeBruijn(5,0) 
 3764  De Bruijn digraph (n=5, k=0): Looped multidigraph on 1 vertex 
 3765  sage: digraphs.DeBruijn(0,0) 
 3766  De Bruijn digraph (n=0, k=0): Looped multidigraph on 0 vertices 
 3767  
 3768  """ 
3761  3769  from sage.combinat.words.words import Words 
3762   from sage.combinat.words.word import Word 
3763   
3764   words=Words(n,k) 
3765   alphabet=[Word([l]) for l in words.alphabet()] 
3766   g=graph.DiGraph(loops=True) 
3767   for w in words: 
3768   ww=w[1:] 
3769   for l in alphabet: 
3770   g.add_edge(w,ww.concatenate(l),l) 
3771   g.name("De Bruijn digraph (n="+str(n)+",k="+str(k)+")") 
3772   
 3770  
 3771  W = Words(n, k) 
 3772  A = Words(n, 1) 
 3773  g = graph.DiGraph(loops=True) 
 3774  
 3775  if k == 0 : 
 3776  g.allow_multiple_edges(True) 
 3777  v = W[0] 
 3778  for a in A: 
 3779  g.add_edge(v, v, a) 
 3780  else: 
 3781  for w in W: 
 3782  ww = w[1:] 
 3783  for a in A: 
 3784  g.add_edge(w, ww*a, a) 
 3785  
 3786  g.name( "De Bruijn digraph (n=%s, k=%s)"%(n,k) ) 
3773  3787  return g 
3774  3788  
3775  3789  