Ticket #7246: trac_7246.patch
File trac_7246.patch, 2.9 KB (added by , 11 years ago) |
---|
-
sage/graphs/graph_generators.py
# HG changeset patch # User Nathann Cohen <nathann.cohen@gmail.com> # Date 1255935569 -7200 # Node ID 6ce68b51a8a03faec12b6206bf5c081f5c420128 # Parent e334f15125a3faecdecfefc6079a7ba4536955e8 digraphs.DeBruijn added to graph_generators diff -r e334f15125a3 -r 6ce68b51a8a0 sage/graphs/graph_generators.py
a b 82 82 - CompleteGraph 83 83 - CompleteBipartiteGraph 84 84 - CubeGraph 85 - DeBruijn 85 86 - HyperStarGraph 86 87 - NKStarGraph 87 88 - NStarGraph … … 135 136 136 137 - Michael Yurko (2009-9-01): added hyperstar, (n,k)-star, n-star, and 137 138 bubblesort graphs 139 140 - Nathann Cohen (2009-10-19): added DeBruijn Graph 138 141 """ 139 142 140 143 ################################################################################ … … 3509 3512 - RandomDirectedGN 3510 3513 - RandomDirectedGNC 3511 3514 - RandomDirectedGNR 3515 3516 Families of Graphs: 3517 - DeBruijn 3518 3512 3519 3513 3520 3514 3521 ORDERLY GENERATION: digraphs(vertices, property=lambda x: True, … … 3717 3724 else: 3718 3725 raise NotImplementedError, "vertices must be 'strings' or 'vectors'." 3719 3726 return graph.DiGraph(butterfly) 3727 3728 def DeBruijn(self,n,k): 3729 r""" 3730 Returns the De Bruijn diraph with parameters `n,k`. 3731 3732 The De Bruijn diraph with parameters `n,k` is built 3733 upon a set of vertices equal to the set of words of 3734 length `k` from a dictionary of `n` letters. 3735 3736 In this digraph, there is an arc `w_1w_2` if `w_2` 3737 can be obtained from `w_1` by removing the leftmost 3738 letter and adding a new letter at its right end. 3739 ( more information on this page : 3740 http://en.wikipedia.org/wiki/De_Bruijn_graph ) 3741 3742 INPUT: 3743 3744 - ``n`` -- Two possibilities for this parameter : 3745 - an integer equal to the cardinality of the 3746 alphabet to use. 3747 - An iterable object to be used as the set 3748 of letters 3749 - ``k`` -- An integer equal to the length of words in 3750 the De Bruijn digraph. 3751 3752 EXAMPLES:: 3753 3754 sage: db=digraphs.DeBruijn(2,2) 3755 sage: db.order() 3756 4 3757 sage: db.size() 3758 8 3759 """ 3760 3761 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 3773 return g 3774 3720 3775 3721 3776 def RandomDirectedGN(self, n, kernel=lambda x:x, seed=None): 3722 3777 """