Ticket #14122: trac_14122.patch

File trac_14122.patch, 4.7 KB (added by ncohen, 7 years ago)
  • sage/graphs/digraph_generators.py

    # 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  
    33
    44Generators for common digraphs.
    55
     6.. csv-table::
     7    :class: contentstable
     8    :widths: 30, 70
     9    :delim: |
     10
     11    :meth:`~DiGraphGenerators.ButterflyGraph`      | Returns a n-dimensional 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
    625AUTHORS:
    726
    827- Robert L. Miller (2006)
    928- Emily A. Kirkman (2006)
    1029- Michael C. Yurko (2009)
    1130- David Coudert    (2012)
     31
     32Functions and methods
     33---------------------
     34
    1235"""
    1336
    1437################################################################################
     
    5073                    - DeBruijn
    5174                    - GeneralizedDeBruijn
    5275                    - Kautz
     76                    - Path
    5377                    - ImaseItoh
     78                    - Tournament
    5479
    5580           
    5681   
     
    260285            raise NotImplementedError, "vertices must be 'strings' or 'vectors'."
    261286        return DiGraph(butterfly)
    262287
     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(n-1):
     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
    263354    def Circuit(self,n):
    264355        r"""
    265356        Returns the circuit on `n` vertices
     
    289380        else:
    290381            g.add_edges([(i,i+1) for i in xrange(n-1)])
    291382            g.add_edge(n-1,0)
    292             return g       
     383            return g
    293384
    294385    def DeBruijn(self, k, n, vertices = 'strings'):
    295386        r"""
    296         Returns the De Bruijn diraph with parameters `k,n`.
     387        Returns the De Bruijn digraph with parameters `k,n`.
    297388
    298389        The De Bruijn digraph with parameters `k,n` is built upon a set of
    299390        vertices equal to the set of words of length `n` from a dictionary of