Ticket #7246: trac_7246.patch

File trac_7246.patch, 2.9 KB (added by ncohen, 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  
    8282        - CompleteGraph
    8383        - CompleteBipartiteGraph
    8484        - CubeGraph
     85        - DeBruijn
    8586        - HyperStarGraph
    8687        - NKStarGraph
    8788        - NStarGraph
     
    135136
    136137- Michael Yurko (2009-9-01): added hyperstar, (n,k)-star, n-star, and
    137138  bubblesort graphs
     139
     140- Nathann Cohen (2009-10-19): added DeBruijn Graph
    138141"""
    139142
    140143################################################################################
     
    35093512                    - RandomDirectedGN
    35103513                    - RandomDirectedGNC
    35113514                    - RandomDirectedGNR
     3515
     3516                Families of Graphs:
     3517                    - DeBruijn
     3518
    35123519           
    35133520   
    35143521    ORDERLY GENERATION: digraphs(vertices, property=lambda x: True,
     
    37173724        else:
    37183725            raise NotImplementedError, "vertices must be 'strings' or 'vectors'."
    37193726        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
    37203775       
    37213776    def RandomDirectedGN(self, n, kernel=lambda x:x, seed=None):
    37223777        """