Ticket #13862: trac_13862-cleaning_and_moving.patch

File trac_13862-cleaning_and_moving.patch, 30.8 KB (added by ncohen, 7 years ago)
  • sage/graphs/generators/basic.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1356480205 -3600
    # Node ID bede57db4217aa72362b41bebde40684b320fe8b
    # Parent  633c65c6ada1769590041f4accf5d19e66092663
    Split graph_generators into several files -- cleaning, moving some more stuff
    
    diff --git a/sage/graphs/generators/basic.py b/sage/graphs/generators/basic.py
    a b  
    22Basic Graphs
    33==================
    44
    5 circle/line embeddings should not be here !
    6 
    7 :meth:`LCFGraph <GraphGenerators.LCFGraph>` was in the list of basic graphs.
    8 
    95"""
    106###########################################################################
    117#
     
    2117from sage.graphs.graph import Graph
    2218from sage.graphs import graph
    2319from math import sin, cos, pi
    24 
    25 ####################
    26 # Helper functions #
    27 ####################
    28 
    29 def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
    30     r"""
    31     Set some vertices on a circle in the embedding of a graph G.
    32 
    33     This method modifies the graph's embedding so that the vertices
    34     listed in ``vertices`` appear in this ordering on a circle of given
    35     radius and center. The ``shift`` parameter is actually a rotation of
    36     the circle. A value of ``shift=1`` will replace in the drawing the
    37     `i`-th element of the list by the `(i-1)`-th. Non-integer values are
    38     admissible, and a value of `\alpha` corresponds to a rotation of the
    39     circle by an angle of `\alpha 2\pi/n` (where `n` is the number of
    40     vertices set on the circle).
    41 
    42     EXAMPLE::
    43 
    44         sage: from sage.graphs.graph_generators import _circle_embedding
    45         sage: g = graphs.CycleGraph(5)
    46         sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
    47         sage: g.show()
    48     """
    49     c_x, c_y = center
    50     n = len(vertices)
    51     d = g.get_pos()
    52     if d is None:
    53         d = {}
    54 
    55     for i,v in enumerate(vertices):
    56         i += shift
    57         v_x = c_x + radius * cos(2*i*pi / n)
    58         v_y = c_y + radius * sin(2*i*pi / n)
    59         d[v] = (v_x, v_y)
    60 
    61     g.set_pos(d)
    62 
    63 def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
    64     r"""
    65     Sets some vertices on a line in the embedding of a graph G.
    66 
    67     This method modifies the graph's embedding so that the vertices of
    68     ``vertices`` appear on a line, where the position of ``vertices[0]``
    69     is the pair ``first`` and the position of ``vertices[-1]`` is
    70     ``last``. The vertices are evenly spaced.
    71 
    72     EXAMPLE::
    73 
    74         sage: from sage.graphs.graph_generators import _line_embedding
    75         sage: g = graphs.PathGraph(5)
    76         sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
    77         sage: g.show()
    78     """
    79     n = len(vertices) - 1.
    80 
    81     fx, fy = first
    82     dx = (last[0] - first[0])/n
    83     dy = (last[1] - first[1])/n
    84 
    85     d = g.get_pos()
    86     if d is None:
    87         d = {}
    88 
    89     for v in vertices:
    90         d[v] = (fx, fy)
    91         fx += dx
    92         fy += dy
    93 
     20from sage.graphs.graph_plot import _circle_embedding, _line_embedding
    9421
    9522#######################################################################
    9623#   Basic Structures
  • sage/graphs/generators/families.py

    diff --git a/sage/graphs/generators/families.py b/sage/graphs/generators/families.py
    a b  
    1111
    1212"""
    1313
    14 
    1514###########################################################################
    1615#
    1716#           Copyright (C) 2006 Robert L. Miller <rlmillster@gmail.com>
     
    2726from sage.graphs import graph
    2827from math import sin, cos, pi
    2928
     29def HararyGraph( self, k, n ):
     30    r"""
     31    Returns the Harary graph on `n` vertices and connectivity `k`, where
     32    `2 \leq k < n`.
     33
     34    A `k`-connected graph `G` on `n` vertices requires the minimum degree
     35    `\delta(G)\geq k`, so the minimum number of edges `G` should have is
     36    `\lceil kn/2\rceil`. Harary graphs achieve this lower bound, that is,
     37    Harary graphs are minimal `k`-connected graphs on `n` vertices.
     38
     39    The construction provided uses the method CirculantGraph.  For more
     40    details, see the book D. B. West, Introduction to Graph Theory, 2nd
     41    Edition, Prentice Hall, 2001, p. 150--151; or the `MathWorld article on
     42    Harary graphs <http://mathworld.wolfram.com/HararyGraph.html>`_.
     43
     44    EXAMPLES:
     45
     46    Harary graphs `H_{k,n}`::
     47
     48        sage: h = graphs.HararyGraph(5,9); h
     49        Harary graph 5, 9: Graph on 9 vertices
     50        sage: h.order()
     51        9
     52        sage: h.size()
     53        23
     54        sage: h.vertex_connectivity()
     55        5
     56
     57    TESTS:
     58
     59    Connectivity of some Harary graphs::
     60
     61        sage: n=10
     62        sage: for k in range(2,n):
     63        ...       g = graphs.HararyGraph(k,n)
     64        ...       if k != g.vertex_connectivity():
     65        ...          print "Connectivity of Harary graphs not satisfied."
     66    """
     67    if k < 2:
     68        raise ValueError("Connectivity parameter k should be at least 2.")
     69    if k >= n:
     70        raise ValueError("Number of vertices n should be greater than k.")
     71
     72    if k%2 == 0:
     73        G = self.CirculantGraph( n, range(1,k/2+1) )
     74    else:
     75        if n%2 == 0:
     76            G = self.CirculantGraph( n, range(1,(k-1)/2+1) )
     77            for i in range(n):
     78                G.add_edge( i, (i+n/2)%n )
     79        else:
     80            G = self.HararyGraph( k-1, n )
     81            for i in range((n-1)/2+1):
     82                G.add_edge( i, (i+(n-1)/2)%n )
     83    G.name('Harary graph {0}, {1}'.format(k,n))
     84    return G
     85
     86def DorogovtsevGoltsevMendesGraph(self, n):
     87    """
     88    Construct the n-th generation of the Dorogovtsev-Goltsev-Mendes
     89    graph.
     90
     91    EXAMPLE::
     92
     93        sage: G = graphs.DorogovtsevGoltsevMendesGraph(8)
     94        sage: G.size()
     95        6561
     96
     97    REFERENCE:
     98
     99    - [1] Dorogovtsev, S. N., Goltsev, A. V., and Mendes, J.
     100      F. F., Pseudofractal scale-free web, Phys. Rev. E 066122
     101      (2002).
     102    """
     103    import networkx
     104    return graph.Graph(networkx.dorogovtsev_goltsev_mendes_graph(n),\
     105           name="Dorogovtsev-Goltsev-Mendes Graph, %d-th generation"%n)
     106
     107def IntervalGraph(self,intervals):
     108    r"""
     109    Returns the graph corresponding to the given intervals.
     110
     111    An interval graph is built from a list `(a_i,b_i)_{1\leq i \leq n}`
     112    of intervals : to each interval of the list is associated one
     113    vertex, two vertices being adjacent if the two corresponding
     114    (closed) intervals intersect.
     115
     116    INPUT:
     117
     118    - ``intervals`` -- the list of pairs `(a_i,b_i)`
     119      defining the graph.
     120
     121    .. NOTE::
     122
     123        * The vertices are named 0, 1, 2, and so on. The
     124          intervals used to create the graph are saved with the
     125          graph and can be recovered using ``get_vertex()`` or
     126          ``get_vertices()``.
     127
     128        * The intervals `(a_i,b_i)` need not verify `a_i<b_i`.
     129
     130    EXAMPLE:
     131
     132    The following line creates the sequence of intervals
     133    `(i, i+2)` for i in `[0, ..., 8]`::
     134
     135        sage: intervals = [(i,i+2) for i in range(9)]
     136
     137    In the corresponding graph... ::
     138
     139        sage: g = graphs.IntervalGraph(intervals)
     140        sage: g.get_vertex(3)
     141        (3, 5)
     142        sage: neigh = g.neighbors(3)
     143        sage: for v in neigh: print g.get_vertex(v)
     144        (1, 3)
     145        (2, 4)
     146        (4, 6)
     147        (5, 7)
     148
     149    The is_interval() method verifies that this graph is an interval
     150    graph. ::
     151
     152        sage: g.is_interval()
     153        True
     154
     155    The intervals in the list need not be distinct. ::
     156
     157        sage: intervals = [ (1,2), (1,2), (1,2), (2,3), (3,4) ]
     158        sage: g = graphs.IntervalGraph(intervals)
     159        sage: g.clique_maximum()
     160        [0, 1, 2, 3]
     161        sage: g.get_vertices()
     162        {0: (1, 2), 1: (1, 2), 2: (1, 2), 3: (2, 3), 4: (3, 4)}
     163
     164    """
     165
     166    n = len(intervals)
     167    g = graph.Graph(n)
     168
     169    edges = []
     170
     171    for i in range(n-1):
     172        I = intervals[i]
     173        for j in range(i+1,n):
     174            J = intervals[j]
     175            if max(I) < min(J) or max(J) < min(I): continue
     176            edges.append((i,j))
     177
     178    g.add_edges(edges)
     179
     180    rep = dict( zip(range(n),intervals) )
     181    g.set_vertices(rep)
     182
     183    return g
     184
    30185def MycielskiGraph(self, k=1, relabel=True):
    31186    r"""
    32187    Returns the `k`-th Mycielski Graph.
     
    19362091    if k<1:
    19372092        raise ValueError('The number of levels must be >= 1.')
    19382093
    1939     from sage.graphs.graph_generators import _circle_embedding
    1940     from sage.graphs.graph_generators import GraphGenerators
     2094    from sage.graphs.graph_plot import _circle_embedding
     2095    from sage.graphs.graph_plot import GraphGenerators
    19412096
    19422097    # Creating the Balanced tree, which contains most edges already
    19432098    g = GraphGenerators().BalancedTree(2,k-1)
  • sage/graphs/generators/platonic_solids.py

    diff --git a/sage/graphs/generators/platonic_solids.py b/sage/graphs/generators/platonic_solids.py
    a b  
    22Platonic solids
    33==================
    44
    5 circle/line embeddings should not be here !
    6 
    75Platonic solids
    86---------------
    97
     
    2927from sage.graphs.graph import Graph
    3028from sage.graphs import graph
    3129from math import sin, cos, pi
    32 
    33 ####################
    34 # Helper functions #
    35 ####################
    36 
    37 def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
    38     r"""
    39     Set some vertices on a circle in the embedding of a graph G.
    40 
    41     This method modifies the graph's embedding so that the vertices
    42     listed in ``vertices`` appear in this ordering on a circle of given
    43     radius and center. The ``shift`` parameter is actually a rotation of
    44     the circle. A value of ``shift=1`` will replace in the drawing the
    45     `i`-th element of the list by the `(i-1)`-th. Non-integer values are
    46     admissible, and a value of `\alpha` corresponds to a rotation of the
    47     circle by an angle of `\alpha 2\pi/n` (where `n` is the number of
    48     vertices set on the circle).
    49 
    50     EXAMPLE::
    51 
    52         sage: from sage.graphs.graph_generators import _circle_embedding
    53         sage: g = graphs.CycleGraph(5)
    54         sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
    55         sage: g.show()
    56     """
    57     c_x, c_y = center
    58     n = len(vertices)
    59     d = g.get_pos()
    60     if d is None:
    61         d = {}
    62 
    63     for i,v in enumerate(vertices):
    64         i += shift
    65         v_x = c_x + radius * cos(2*i*pi / n)
    66         v_y = c_y + radius * sin(2*i*pi / n)
    67         d[v] = (v_x, v_y)
    68 
    69     g.set_pos(d)
    70 
    71 def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
    72     r"""
    73     Sets some vertices on a line in the embedding of a graph G.
    74 
    75     This method modifies the graph's embedding so that the vertices of
    76     ``vertices`` appear on a line, where the position of ``vertices[0]``
    77     is the pair ``first`` and the position of ``vertices[-1]`` is
    78     ``last``. The vertices are evenly spaced.
    79 
    80     EXAMPLE::
    81 
    82         sage: from sage.graphs.graph_generators import _line_embedding
    83         sage: g = graphs.PathGraph(5)
    84         sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
    85         sage: g.show()
    86     """
    87     n = len(vertices) - 1.
    88 
    89     fx, fy = first
    90     dx = (last[0] - first[0])/n
    91     dy = (last[1] - first[1])/n
    92 
    93     d = g.get_pos()
    94     if d is None:
    95         d = {}
    96 
    97     for v in vertices:
    98         d[v] = (fx, fy)
    99         fx += dx
    100         fy += dy
    101 
     30from sage.graphs.graph_plot import _circle_embedding, _line_embedding
    10231
    10332################################################################################
    10433#   Platonic Solids
  • sage/graphs/generators/random.py

    diff --git a/sage/graphs/generators/random.py b/sage/graphs/generators/random.py
    a b  
    22Random Graphs
    33==================
    44
    5 circle/line embeddings should not be here !
    6 
    7 Where the hell should InterverGraph be ? Is it listed at the right place ?
    8 
    95"""
    106###########################################################################
    117#
     
    2218from sage.graphs import graph
    2319from math import sin, cos, pi
    2420from sage.misc.randstate import current_randstate
    25 ####################
    26 # Helper functions #
    27 ####################
    28 
    29 def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
    30     r"""
    31     Set some vertices on a circle in the embedding of a graph G.
    32 
    33     This method modifies the graph's embedding so that the vertices
    34     listed in ``vertices`` appear in this ordering on a circle of given
    35     radius and center. The ``shift`` parameter is actually a rotation of
    36     the circle. A value of ``shift=1`` will replace in the drawing the
    37     `i`-th element of the list by the `(i-1)`-th. Non-integer values are
    38     admissible, and a value of `\alpha` corresponds to a rotation of the
    39     circle by an angle of `\alpha 2\pi/n` (where `n` is the number of
    40     vertices set on the circle).
    41 
    42     EXAMPLE::
    43 
    44         sage: from sage.graphs.graph_generators import _circle_embedding
    45         sage: g = graphs.CycleGraph(5)
    46         sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
    47         sage: g.show()
    48     """
    49     c_x, c_y = center
    50     n = len(vertices)
    51     d = g.get_pos()
    52     if d is None:
    53         d = {}
    54 
    55     for i,v in enumerate(vertices):
    56         i += shift
    57         v_x = c_x + radius * cos(2*i*pi / n)
    58         v_y = c_y + radius * sin(2*i*pi / n)
    59         d[v] = (v_x, v_y)
    60 
    61     g.set_pos(d)
    62 
    63 def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
    64     r"""
    65     Sets some vertices on a line in the embedding of a graph G.
    66 
    67     This method modifies the graph's embedding so that the vertices of
    68     ``vertices`` appear on a line, where the position of ``vertices[0]``
    69     is the pair ``first`` and the position of ``vertices[-1]`` is
    70     ``last``. The vertices are evenly spaced.
    71 
    72     EXAMPLE::
    73 
    74         sage: from sage.graphs.graph_generators import _line_embedding
    75         sage: g = graphs.PathGraph(5)
    76         sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
    77         sage: g.show()
    78     """
    79     n = len(vertices) - 1.
    80 
    81     fx, fy = first
    82     dx = (last[0] - first[0])/n
    83     dy = (last[1] - first[1])/n
    84 
    85     d = g.get_pos()
    86     if d is None:
    87         d = {}
    88 
    89     for v in vertices:
    90         d[v] = (fx, fy)
    91         fx += dx
    92         fy += dy
    93 
    9421
    9522################################################################################
    9623#   Random Graphs
  • sage/graphs/generators/smallgraphs.py

    diff --git a/sage/graphs/generators/smallgraphs.py b/sage/graphs/generators/smallgraphs.py
    a b  
    33==================
    44
    55Add naury graphs to the list
    6 Harary graph is not a small graph !
    7 circle/line embeddings should not be here !
    86Virer GraphGenerators() from the code
    97"""
    108
     
    2321from sage.graphs.graph import Graph
    2422from sage.graphs import graph
    2523from math import sin, cos, pi
    26 
    27 ####################
    28 # Helper functions #
    29 ####################
    30 
    31 def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
    32     r"""
    33     Set some vertices on a circle in the embedding of a graph G.
    34 
    35     This method modifies the graph's embedding so that the vertices
    36     listed in ``vertices`` appear in this ordering on a circle of given
    37     radius and center. The ``shift`` parameter is actually a rotation of
    38     the circle. A value of ``shift=1`` will replace in the drawing the
    39     `i`-th element of the list by the `(i-1)`-th. Non-integer values are
    40     admissible, and a value of `\alpha` corresponds to a rotation of the
    41     circle by an angle of `\alpha 2\pi/n` (where `n` is the number of
    42     vertices set on the circle).
    43 
    44     EXAMPLE::
    45 
    46         sage: from sage.graphs.graph_generators import _circle_embedding
    47         sage: g = graphs.CycleGraph(5)
    48         sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
    49         sage: g.show()
    50     """
    51     c_x, c_y = center
    52     n = len(vertices)
    53     d = g.get_pos()
    54     if d is None:
    55         d = {}
    56 
    57     for i,v in enumerate(vertices):
    58         i += shift
    59         v_x = c_x + radius * cos(2*i*pi / n)
    60         v_y = c_y + radius * sin(2*i*pi / n)
    61         d[v] = (v_x, v_y)
    62 
    63     g.set_pos(d)
    64 
    65 def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
    66     r"""
    67     Sets some vertices on a line in the embedding of a graph G.
    68 
    69     This method modifies the graph's embedding so that the vertices of
    70     ``vertices`` appear on a line, where the position of ``vertices[0]``
    71     is the pair ``first`` and the position of ``vertices[-1]`` is
    72     ``last``. The vertices are evenly spaced.
    73 
    74     EXAMPLE::
    75 
    76         sage: from sage.graphs.graph_generators import _line_embedding
    77         sage: g = graphs.PathGraph(5)
    78         sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
    79         sage: g.show()
    80     """
    81     n = len(vertices) - 1.
    82 
    83     fx, fy = first
    84     dx = (last[0] - first[0])/n
    85     dy = (last[1] - first[1])/n
    86 
    87     d = g.get_pos()
    88     if d is None:
    89         d = {}
    90 
    91     for v in vertices:
    92         d[v] = (fx, fy)
    93         fx += dx
    94         fy += dy
    95 
     24from sage.graphs.graph_plot import _circle_embedding, _line_embedding
    9625
    9726#######################################################################
    9827#   Named Graphs
    9928#######################################################################
    10029
    101 def HararyGraph( self, k, n ):
    102     r"""
    103     Returns the Harary graph on `n` vertices and connectivity `k`, where
    104     `2 \leq k < n`.
    105 
    106     A `k`-connected graph `G` on `n` vertices requires the minimum degree
    107     `\delta(G)\geq k`, so the minimum number of edges `G` should have is
    108     `\lceil kn/2\rceil`. Harary graphs achieve this lower bound, that is,
    109     Harary graphs are minimal `k`-connected graphs on `n` vertices.
    110 
    111     The construction provided uses the method CirculantGraph.  For more
    112     details, see the book D. B. West, Introduction to Graph Theory, 2nd
    113     Edition, Prentice Hall, 2001, p. 150--151; or the `MathWorld article on
    114     Harary graphs <http://mathworld.wolfram.com/HararyGraph.html>`_.
    115 
    116     EXAMPLES:
    117 
    118     Harary graphs `H_{k,n}`::
    119 
    120         sage: h = graphs.HararyGraph(5,9); h
    121         Harary graph 5, 9: Graph on 9 vertices
    122         sage: h.order()
    123         9
    124         sage: h.size()
    125         23
    126         sage: h.vertex_connectivity()
    127         5
    128 
    129     TESTS:
    130 
    131     Connectivity of some Harary graphs::
    132 
    133         sage: n=10
    134         sage: for k in range(2,n):
    135         ...       g = graphs.HararyGraph(k,n)
    136         ...       if k != g.vertex_connectivity():
    137         ...          print "Connectivity of Harary graphs not satisfied."
    138     """
    139     if k < 2:
    140         raise ValueError("Connectivity parameter k should be at least 2.")
    141     if k >= n:
    142         raise ValueError("Number of vertices n should be greater than k.")
    143 
    144     if k%2 == 0:
    145         G = self.CirculantGraph( n, range(1,k/2+1) )
    146     else:
    147         if n%2 == 0:
    148             G = self.CirculantGraph( n, range(1,(k-1)/2+1) )
    149             for i in range(n):
    150                 G.add_edge( i, (i+n/2)%n )
    151         else:
    152             G = self.HararyGraph( k-1, n )
    153             for i in range((n-1)/2+1):
    154                 G.add_edge( i, (i+(n-1)/2)%n )
    155     G.name('Harary graph {0}, {1}'.format(k,n))
    156     return G
    157 
    15830def HarriesGraph(self, embedding=1):
    15931    r"""
    16032    Returns the Harries Graph.
  • sage/graphs/graph_generators.py

    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    11# -*- coding: utf-8 -*-
    2 
    32r"""
    43Common graphs
    54
     
    7271- :meth:`HouseXGraph <GraphGenerators.HouseXGraph>`
    7372- :meth:`KrackhardtKiteGraph <GraphGenerators.KrackhardtKiteGraph>`
    7473- :meth:`LadderGraph <GraphGenerators.LadderGraph>`
    75 - :meth:`LCFGraph <GraphGenerators.LCFGraph>`
    7674- :meth:`LollipopGraph <GraphGenerators.LollipopGraph>`
    7775- :meth:`PathGraph <GraphGenerators.PathGraph>`
    7876- :meth:`StarGraph <GraphGenerators.StarGraph>`
     
    128126- :meth:`McGeeGraph <GraphGenerators.McGeeGraph>`
    129127- :meth:`MoebiusKantorGraph <GraphGenerators.MoebiusKantorGraph>`
    130128- :meth:`MoserSpindle <GraphGenerators.MoserSpindle>`
     129- :meth:`NauruGraph <GraphGenerators.NauruGraph>`
    131130- :meth:`PappusGraph <GraphGenerators.PappusGraph>`
    132131- :meth:`PetersenGraph <GraphGenerators.PetersenGraph>`
    133132- :meth:`ShrikhandeGraph <GraphGenerators.ShrikhandeGraph>`
     
    152151- :meth:`GeneralizedPetersenGraph <GraphGenerators.GeneralizedPetersenGraph>`
    153152- :meth:`HanoiTowerGraph <GraphGenerators.HanoiTowerGraph>`
    154153- :meth:`HyperStarGraph <GraphGenerators.HyperStarGraph>`
     154- :meth:`IntervalGraph <GraphGenerators.IntervalGraph>`
    155155- :meth:`KneserGraph <GraphGenerators.KneserGraph>`
    156156- :meth:`LCFGraph <GraphGenerators.LCFGraph>`
    157157- :meth:`MycielskiGraph <GraphGenerators.MycielskiGraph>`
     
    539539      of Algorithms*, Volume 26, Issue 2, February 1998, pages 306-324.
    540540    """
    541541
    542 ################################################################################
    543 #   Pseudofractal Graphs
    544 ################################################################################
    545 
    546     def DorogovtsevGoltsevMendesGraph(self, n):
    547         """
    548         Construct the n-th generation of the Dorogovtsev-Goltsev-Mendes
    549         graph.
    550 
    551         EXAMPLE::
    552 
    553             sage: G = graphs.DorogovtsevGoltsevMendesGraph(8)
    554             sage: G.size()
    555             6561
    556 
    557         REFERENCE:
    558 
    559         - [1] Dorogovtsev, S. N., Goltsev, A. V., and Mendes, J.
    560           F. F., Pseudofractal scale-free web, Phys. Rev. E 066122
    561           (2002).
    562         """
    563         import networkx
    564         return graph.Graph(networkx.dorogovtsev_goltsev_mendes_graph(n),\
    565                name="Dorogovtsev-Goltsev-Mendes Graph, %d-th generation"%n)
    566 
    567     def IntervalGraph(self,intervals):
    568         r"""
    569         Returns the graph corresponding to the given intervals.
    570 
    571         An interval graph is built from a list `(a_i,b_i)_{1\leq i \leq n}`
    572         of intervals : to each interval of the list is associated one
    573         vertex, two vertices being adjacent if the two corresponding
    574         (closed) intervals intersect.
    575 
    576         INPUT:
    577 
    578         - ``intervals`` -- the list of pairs `(a_i,b_i)`
    579           defining the graph.
    580 
    581         .. NOTE::
    582 
    583             * The vertices are named 0, 1, 2, and so on. The
    584               intervals used to create the graph are saved with the
    585               graph and can be recovered using ``get_vertex()`` or
    586               ``get_vertices()``.
    587 
    588             * The intervals `(a_i,b_i)` need not verify `a_i<b_i`.
    589 
    590         EXAMPLE:
    591 
    592         The following line creates the sequence of intervals
    593         `(i, i+2)` for i in `[0, ..., 8]`::
    594 
    595             sage: intervals = [(i,i+2) for i in range(9)]
    596 
    597         In the corresponding graph... ::
    598 
    599             sage: g = graphs.IntervalGraph(intervals)
    600             sage: g.get_vertex(3)
    601             (3, 5)
    602             sage: neigh = g.neighbors(3)
    603             sage: for v in neigh: print g.get_vertex(v)
    604             (1, 3)
    605             (2, 4)
    606             (4, 6)
    607             (5, 7)
    608 
    609         The is_interval() method verifies that this graph is an interval
    610         graph. ::
    611 
    612             sage: g.is_interval()
    613             True
    614 
    615         The intervals in the list need not be distinct. ::
    616        
    617             sage: intervals = [ (1,2), (1,2), (1,2), (2,3), (3,4) ]
    618             sage: g = graphs.IntervalGraph(intervals)
    619             sage: g.clique_maximum()
    620             [0, 1, 2, 3]
    621             sage: g.get_vertices()
    622             {0: (1, 2), 1: (1, 2), 2: (1, 2), 3: (2, 3), 4: (3, 4)}
    623 
    624         """
    625 
    626         n = len(intervals)
    627         g = graph.Graph(n)
    628 
    629         edges = []
    630 
    631         for i in range(n-1):
    632             I = intervals[i]
    633             for j in range(i+1,n):
    634                 J = intervals[j]
    635                 if max(I) < min(J) or max(J) < min(I): continue
    636                 edges.append((i,j))
    637                
    638         g.add_edges(edges)
    639 
    640         rep = dict( zip(range(n),intervals) )
    641         g.set_vertices(rep)
    642 
    643         return g
    644 
    645 
    646 
    647542###########################################################################
    648543#   Graph Iterators
    649544###########################################################################
    650    
     545
    651546    def __call__(self, vertices=None, property=lambda x: True, augment='edges',
    652547        size=None, deg_seq=None, degree_sequence=None, loops=False, implementation='c_graph',
    653548        sparse=True, copy = True):
     
    655550        Accesses the generator of isomorphism class representatives.
    656551        Iterates over distinct, exhaustive representatives. See the docstring
    657552        of this class for full documentation.
    658        
     553
    659554        EXAMPLES:
    660555
    661556        Print graphs on 3 or less vertices::
     
    1006901    CompleteBipartiteGraph = sage.graphs.generators.families.CompleteBipartiteGraph
    1007902    CompleteMultipartiteGraph = sage.graphs.generators.families.CompleteMultipartiteGraph
    1008903    CubeGraph = sage.graphs.generators.families.CubeGraph
     904    DorogovtsevGoltsevMendesGraph = sage.graphs.generators.families.DorogovtsevGoltsevMendesGraph
    1009905    FriendshipGraph = sage.graphs.generators.families.FriendshipGraph
    1010906    FuzzyBallGraph = sage.graphs.generators.families.FuzzyBallGraph
    1011907    FibonacciTree = sage.graphs.generators.families.FibonacciTree
    1012908    GeneralizedPetersenGraph = sage.graphs.generators.families.GeneralizedPetersenGraph
    1013909    HyperStarGraph = sage.graphs.generators.families.HyperStarGraph
     910    HararyGraph = sage.graphs.generators.families.HararyGraph
     911    IntervalGraph = sage.graphs.generators.families.IntervalGraph
    1014912    LCFGraph = sage.graphs.generators.families.LCFGraph
    1015913    NKStarGraph = sage.graphs.generators.families.NKStarGraph
    1016914    NStarGraph = sage.graphs.generators.families.NStarGraph
     
    1050948    GrotzschGraph = sage.graphs.generators.smallgraphs.GrotzschGraph
    1051949    HallJankoGraph = sage.graphs.generators.smallgraphs.HallJankoGraph
    1052950    HarriesGraph = sage.graphs.generators.smallgraphs.HarriesGraph
    1053     HararyGraph = sage.graphs.generators.smallgraphs.HararyGraph
    1054951    HarriesWongGraph = sage.graphs.generators.smallgraphs.HarriesWongGraph
    1055952    HeawoodGraph = sage.graphs.generators.smallgraphs.HeawoodGraph
    1056953    HerschelGraph = sage.graphs.generators.smallgraphs.HerschelGraph
     
    15471444
    15481445# Easy access to the graph generators from the command line:
    15491446graphs = GraphGenerators()
    1550 
    1551 
    1552 ####################
    1553 # Helper functions #
    1554 ####################
    1555 
    1556 def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
    1557     r"""
    1558     Set some vertices on a circle in the embedding of a graph G.
    1559 
    1560     This method modifies the graph's embedding so that the vertices
    1561     listed in ``vertices`` appear in this ordering on a circle of given
    1562     radius and center. The ``shift`` parameter is actually a rotation of
    1563     the circle. A value of ``shift=1`` will replace in the drawing the
    1564     `i`-th element of the list by the `(i-1)`-th. Non-integer values are
    1565     admissible, and a value of `\alpha` corresponds to a rotation of the
    1566     circle by an angle of `\alpha 2\pi/n` (where `n` is the number of
    1567     vertices set on the circle).
    1568 
    1569     EXAMPLE::
    1570 
    1571         sage: from sage.graphs.graph_generators import _circle_embedding
    1572         sage: g = graphs.CycleGraph(5)
    1573         sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
    1574         sage: g.show()
    1575     """
    1576     c_x, c_y = center
    1577     n = len(vertices)
    1578     d = g.get_pos()
    1579     if d is None:
    1580         d = {}
    1581 
    1582     for i,v in enumerate(vertices):
    1583         i += shift
    1584         v_x = c_x + radius * cos(2*i*pi / n)
    1585         v_y = c_y + radius * sin(2*i*pi / n)
    1586         d[v] = (v_x, v_y)
    1587 
    1588     g.set_pos(d)
    1589 
    1590 def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
    1591     r"""
    1592     Sets some vertices on a line in the embedding of a graph G.
    1593 
    1594     This method modifies the graph's embedding so that the vertices of
    1595     ``vertices`` appear on a line, where the position of ``vertices[0]``
    1596     is the pair ``first`` and the position of ``vertices[-1]`` is
    1597     ``last``. The vertices are evenly spaced.
    1598 
    1599     EXAMPLE::
    1600 
    1601         sage: from sage.graphs.graph_generators import _line_embedding
    1602         sage: g = graphs.PathGraph(5)
    1603         sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
    1604         sage: g.show()
    1605     """
    1606     n = len(vertices) - 1.
    1607 
    1608     fx, fy = first
    1609     dx = (last[0] - first[0])/n
    1610     dy = (last[1] - first[1])/n
    1611 
    1612     d = g.get_pos()
    1613     if d is None:
    1614         d = {}
    1615 
    1616     for v in vertices:
    1617         d[v] = (fx, fy)
    1618         fx += dx
    1619         fy += dy
  • sage/graphs/graph_plot.py

    diff --git a/sage/graphs/graph_plot.py b/sage/graphs/graph_plot.py
    a b  
    906906                        x = ox
    907907                obstruction[y] = x+1
    908908                continue
    909            
     909
    910910            t = C.pop()
    911911            pt = parent[t]
    912    
     912
    913913            ct = [u for u in T.neighbors(t) if u != pt]
    914914            for c in ct:
    915915                parent[c] = t
    916916            children[t] = ct
    917            
     917
    918918            stack.append([c for c in ct])
    919919            stick.append(t)
    920920
    921921        return pos
     922
     923####################
     924# Helper functions #
     925####################
     926
     927def _circle_embedding(g, vertices, center=(0, 0), radius=1, shift=0):
     928    r"""
     929    Set some vertices on a circle in the embedding of a graph G.
     930
     931    This method modifies the graph's embedding so that the vertices
     932    listed in ``vertices`` appear in this ordering on a circle of given
     933    radius and center. The ``shift`` parameter is actually a rotation of
     934    the circle. A value of ``shift=1`` will replace in the drawing the
     935    `i`-th element of the list by the `(i-1)`-th. Non-integer values are
     936    admissible, and a value of `\alpha` corresponds to a rotation of the
     937    circle by an angle of `\alpha 2\pi/n` (where `n` is the number of
     938    vertices set on the circle).
     939
     940    EXAMPLE::
     941
     942        sage: from sage.graphs.graph_plot import _circle_embedding
     943        sage: g = graphs.CycleGraph(5)
     944        sage: _circle_embedding(g, [0, 2, 4, 1, 3], radius=2, shift=.5)
     945        sage: g.show()
     946    """
     947    c_x, c_y = center
     948    n = len(vertices)
     949    d = g.get_pos()
     950    if d is None:
     951        d = {}
     952
     953    for i,v in enumerate(vertices):
     954        i += shift
     955        v_x = c_x + radius * cos(2*i*pi / n)
     956        v_y = c_y + radius * sin(2*i*pi / n)
     957        d[v] = (v_x, v_y)
     958
     959    g.set_pos(d)
     960
     961def _line_embedding(g, vertices, first=(0, 0), last=(0, 1)):
     962    r"""
     963    Sets some vertices on a line in the embedding of a graph G.
     964
     965    This method modifies the graph's embedding so that the vertices of
     966    ``vertices`` appear on a line, where the position of ``vertices[0]``
     967    is the pair ``first`` and the position of ``vertices[-1]`` is
     968    ``last``. The vertices are evenly spaced.
     969
     970    EXAMPLE::
     971
     972        sage: from sage.graphs.graph_plot import _line_embedding
     973        sage: g = graphs.PathGraph(5)
     974        sage: _line_embedding(g, [0, 2, 4, 1, 3], first=(-1, -1), last=(1, 1))
     975        sage: g.show()
     976    """
     977    n = len(vertices) - 1.
     978
     979    fx, fy = first
     980    dx = (last[0] - first[0])/n
     981    dy = (last[1] - first[1])/n
     982
     983    d = g.get_pos()
     984    if d is None:
     985        d = {}
     986
     987    for v in vertices:
     988        d[v] = (fx, fy)
     989        fx += dx
     990        fy += dy