Ticket #14251: trac_14251.patch

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

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1362934587 -3600
    # Node ID 1699dbc4723b75833fc7f26a620c60201de501bc
    # Parent  e96fafb64ae2d32fc7adbf5ee537d9fb0b4766a8
    Circulant digraphs
    
    diff --git a/sage/graphs/digraph_generators.py b/sage/graphs/digraph_generators.py
    a b  
    1010
    1111    :meth:`~DiGraphGenerators.ButterflyGraph`      | Returns a n-dimensional butterfly graph.
    1212    :meth:`~DiGraphGenerators.Circuit`             | Returns the circuit on `n` vertices.
     13    :meth:`~DiGraphGenerators.Circulant`           | Returns a circulant digraph on `n` vertices from a set of integers.
    1314    :meth:`~DiGraphGenerators.DeBruijn`            | Returns the De Bruijn digraph with parameters `k,n`.
    1415    :meth:`~DiGraphGenerators.GeneralizedDeBruijn` | Returns the generalized de Bruijn digraph of order `n` and degree `d`.
    1516    :meth:`~DiGraphGenerators.ImaseItoh`           | Returns the digraph of Imase and Itoh of order `n` and degree `d`.
     
    382383            g.add_edge(n-1,0)
    383384            return g
    384385
     386    def Circulant(self,n,integers):
     387        r"""
     388        Returns a circulant digraph on `n` vertices from a set of integers.
     389
     390        INPUT:
     391
     392        - ``n`` (integer) -- number of vertices.
     393
     394        - ``integers`` -- the list of integers such that there is an edge from
     395          `i` to `j` if and only if ``(j-i) in integers``.
     396
     397        EXAMPLE::
     398
     399            sage: digraphs.Circulant(13,[3,5,7])
     400            Circulant graph ([3, 5, 7]): Digraph on 13 vertices
     401        """
     402        from sage.graphs.graph_plot import _circle_embedding
     403
     404        G=DiGraph(n, name="Circulant graph ("+str(integers)+")")
     405        _circle_embedding(G, range(n))
     406
     407        for v in range(n):
     408            G.add_edges([(v,(v+j)%n) for j in integers])
     409
     410        return G
     411
    385412    def DeBruijn(self, k, n, vertices = 'strings'):
    386413        r"""
    387414        Returns the De Bruijn digraph with parameters `k,n`.
  • sage/graphs/generators/families.py

    diff --git a/sage/graphs/generators/families.py b/sage/graphs/generators/families.py
    a b  
    573573    r"""
    574574    Returns a circulant graph with n nodes.
    575575
    576     A circulant graph has the property that the vertex i is connected
    577     with the vertices i+j and i-j for each j in adj.
     576    A circulant graph has the property that the vertex `i` is connected
     577    with the vertices `i+j` and `i-j` for each j in adj.
    578578
    579579    INPUT:
    580580
     
    661661        (4, 5),
    662662        (5, 6)]
    663663    """
     664    from sage.graphs.graph_plot import _circle_embedding
     665
    664666    if not isinstance(adjacency,list):
    665667        adjacency=[adjacency]
    666     pos_dict = {}
    667     for i in range(n):
    668         x = float(cos((pi/2) + ((2*pi)/n)*i))
    669         y = float(sin((pi/2) + ((2*pi)/n)*i))
    670         pos_dict[i] = (x,y)
     668
    671669    G=graph.Graph(n, name="Circulant graph ("+str(adjacency)+")")
    672     G._pos=pos_dict
     670    _circle_embedding(G, range(n))
     671
    673672    for v in G:
    674673        G.add_edges([(v,(v+j)%n) for j in adjacency])
    675         G.add_edges([(v,(v-j)%n) for j in adjacency])
     674
    676675    return G
    677676
    678677def CubeGraph(n):