Ticket #12385: trac_12385-all-simple-paths.3.patch

File trac_12385-all-simple-paths.3.patch, 19.3 KB (added by kini, 10 years ago)

apply to $SAGE_ROOT/devel/sage

  • sage/graphs/digraph.py

    # HG changeset patch
    # Parent 7f6b2f103a972f8cb6e21a269dc8b14690534ccc
    # User Keshav Kini <keshav.kini@gmail.com>
    # Date 1328014756 -28800
    
    documentation fixes
    
    diff --git a/sage/graphs/digraph.py b/sage/graphs/digraph.py
    a b  
    16981698           ending vertices of the paths. If None, then all vertices are
    16991699           allowed.
    17001700        -  ``simple`` - boolean (default: False). If set to True, then
    1701            only simple paths are considered. A path is simple if no
    1702            vertex occurs twice in it except possibly the first and last
    1703            ones.
     1701           only simple paths are considered. Simple paths are paths in
     1702           which no two arcs share a head or share a tail, i.e. every
     1703           vertex in the path is entered at most once and exited at most
     1704           once.
    17041705        -  ``max_length`` - non negative integer (default: None). The
    17051706           maximum length of the enumerated paths. If set to None, then
    17061707           all lengths are allowed.
     
    17321733            ['b', 'c', 'd', 'c', 'd']
    17331734            ['b', 'c', 'd', 'c', 'd', 'c']
    17341735
    1735         One may wish to enumerate simple paths, i.e. paths such that no
    1736         vertex occurs twice in it except possibly the first and last
    1737         one. The result is always finite but may be long to be
    1738         computed::
     1736        One may wish to enumerate simple paths, which are paths in which
     1737        no two arcs share a head or share a tail, i.e. every vertex in
     1738        the path is entered at most once and exited at most once. The
     1739        result is always finite but may take a long time to compute::
    17391740
    17401741            sage: pi = g._all_paths_iterator('a', simple=True)
    17411742            sage: list(pi)
     
    17961797
    17971798                # We try all possible extensions
    17981799                if simple:
    1799                     # We only keep simple extensions. One exception: when we
    1800                     # have found a simple cycle. In this case, we yield it
    1801                     # immediately, but don't consider it for further extension.
    1802                     # See trac #12385.
     1800                    # We only keep simple extensions. An extension is simple
     1801                    # iff the new vertex being entered has not previously
     1802                    # occurred in the path, or has occurred but only been
     1803                    # exited (i.e. is the first vertex in the path). In this
     1804                    # latter case we must not exit the new vertex again, so we
     1805                    # do not consider it for further extension, but just yield
     1806                    # it immediately. See trac #12385.
    18031807                    for neighbor in self.neighbor_out_iterator(path[-1]):
    18041808                        if neighbor not in path:
    18051809                            queue.append(path + [neighbor])
     
    18351839           the allowed ending vertices of the paths. If None,
    18361840           then all vertices are allowed.
    18371841        -  ``simple`` - boolean (default: False). If set to True,
    1838            then only simple paths are considered. A path is simple
    1839            if no vertex occurs twice in it except if the starting
    1840            and ending ones are equal.
     1842           then only simple paths are considered. These are paths in
     1843           which no two arcs share a head or share a tail, i.e. every
     1844           vertex in the path is entered at most once and exited at most
     1845           once.
    18411846        -  ``max_length`` - non negative integer (default: None).
    18421847           The maximum length of the enumerated paths. If set to None,
    18431848           then all lengths are allowed.
     
    18831888            ['a', 'a', 'a', 'a', 'a', 'b']
    18841889
    18851890        One may prefer to enumerate only simple paths (see
    1886         ``all_simple_paths(...)``)::
     1891        :meth:`all_simple_paths`)::
    18871892
    18881893            sage: pi = g.all_paths_iterator(simple=True)
    18891894            sage: list(pi)
     
    19511956                         max_length=None, trivial=False):
    19521957        r"""
    19531958        Returns a list of all the simple paths of self starting
    1954         with one of the given vertices. A path is simple if no vertex
    1955         occurs twice in it except possibly the starting and ending one.
    1956         The paths are enumerated in increasing length order.
     1959        with one of the given vertices. Simple paths are paths in which
     1960        no two arcs share a head or share a tail, i.e. every vertex in
     1961        the path is entered at most once and exited at most once.
    19571962
    19581963        INPUT:
    19591964
     
    21632168
    21642169        .. NOTE::
    21652170
    2166             See also ``all_simple_cycles(...)``.
     2171            See also :meth:`all_simple_cycles`.
    21672172
    21682173        AUTHOR:
    21692174
     
    22062211
    22072212            sage: it = g.all_cycles_iterator(max_length=3)
    22082213            sage: list(it)
    2209             [['a', 'a'], ['a', 'a', 'a'], ['c', 'd', 'c'], ['a', 'a', 'a', 'a']]
     2214            [['a', 'a'], ['a', 'a', 'a'], ['c', 'd', 'c'],
     2215             ['a', 'a', 'a', 'a']]
    22102216
    22112217        By default, cycles differing only by their starting point are not all
    22122218        enumerated, but this may be parametrized::
    22132219       
    22142220            sage: it = g.all_cycles_iterator(max_length=3, rooted=False)
    22152221            sage: list(it)
    2216             [['a', 'a'], ['a', 'a', 'a'], ['c', 'd', 'c'], ['a', 'a', 'a', 'a']]
     2222            [['a', 'a'], ['a', 'a', 'a'], ['c', 'd', 'c'],
     2223             ['a', 'a', 'a', 'a']]
    22172224            sage: it = g.all_cycles_iterator(max_length=3, rooted=True)
    22182225            sage: list(it)
    2219             [['a', 'a'], ['a', 'a', 'a'], ['c', 'd', 'c'], ['d', 'c', 'd'], ['a', 'a', 'a', 'a']]
     2226            [['a', 'a'], ['a', 'a', 'a'], ['c', 'd', 'c'], ['d', 'c', 'd'],
     2227             ['a', 'a', 'a', 'a']]
    22202228
    22212229        One may prefer to enumerate simple cycles, i.e. cycles such that the only
    22222230        vertex occuring twice in it is the starting and ending one (see also
    2223         ``all_simple_cycles(...)``::
     2231        :meth:`all_simple_cycles`)::
    22242232
    22252233            sage: it = g.all_cycles_iterator(simple=True)
    22262234            sage: list(it)
     
    22312239        """
    22322240        if starting_vertices is None:
    22332241            starting_vertices = self
    2234         # Since a cycle is always included in a given strongly connected component,
    2235         # we may remove edges from the graph
     2242        # Since a cycle is always included in a given strongly connected
     2243        # component, we may remove edges from the graph
    22362244        sccs = self.strongly_connected_components()
    22372245        d = {}
    22382246        for id, component in enumerate(sccs):
    22392247            for v in component:
    22402248                d[v] = id
    22412249        h = self.copy()
    2242         h.delete_edges([(u,v) for (u,v) in h.edge_iterator(labels=False) if d[u] != d[v]])
    2243         # We create one cycles iterator per vertex
    2244         # This is necessary if we want to iterate over cycles
    2245         # with increasing length
    2246         vertex_iterators = dict([(v, h._all_cycles_iterator_vertex(v, starting_vertices=starting_vertices, simple=simple, rooted=rooted, max_length=max_length, trivial=trivial, remove_acyclic_edges=False)) for v in starting_vertices])
     2250        h.delete_edges([ (u,v) for (u,v) in h.edge_iterator(labels=False)
     2251                if d[u] != d[v] ])
     2252        # We create one cycles iterator per vertex. This is necessary if we
     2253        # want to iterate over cycles with increasing length.
     2254        vertex_iterators = dict([(v, h._all_cycles_iterator_vertex( v
     2255                                        , starting_vertices=starting_vertices
     2256                                        , simple=simple
     2257                                        , rooted=rooted
     2258                                        , max_length=max_length
     2259                                        , trivial=trivial
     2260                                        , remove_acyclic_edges=False
     2261                                        )) for v in starting_vertices])
    22472262        cycles = []
    22482263        for vi in vertex_iterators.values():
    22492264            try:
     
    22592274            # We choose the shortest available cycle
    22602275            _, shortest_cycle = heappop(cycles)
    22612276            yield shortest_cycle
    2262             # We update the cycle iterator to its next available cycle if it exists
     2277            # We update the cycle iterator to its next available cycle if it
     2278            # exists
    22632279            try:
    22642280                cycle = vertex_iterators[shortest_cycle[0]].next()
    22652281                heappush(cycles, (len(cycle), cycle))
     
    22942310
    22952311        .. NOTE::
    22962312
    2297             Although the number of simple cycles of a finite graph
    2298             is always finite, computing all its cycle may take a very
    2299             long time.
     2313            Although the number of simple cycles of a finite graph is
     2314            always finite, computing all its cycles may take a very long
     2315            time.
    23002316
    23012317        EXAMPLES::
    23022318
     
    23082324
    23092325            sage: g = graphs.PetersenGraph().to_directed()
    23102326            sage: g.all_simple_cycles(max_length=4)
    2311             [[0, 1, 0], [0, 4, 0], [0, 5, 0], [1, 2, 1], [1, 6, 1], [2, 3, 2], [2, 7, 2], [3, 8, 3], [3, 4, 3], [4, 9, 4], [5, 8, 5], [5, 7, 5], [6, 8, 6], [6, 9, 6], [7, 9, 7]]
     2327            [[0, 1, 0], [0, 4, 0], [0, 5, 0], [1, 2, 1], [1, 6, 1], [2, 3, 2],
     2328             [2, 7, 2], [3, 8, 3], [3, 4, 3], [4, 9, 4], [5, 8, 5], [5, 7, 5],
     2329             [6, 8, 6], [6, 9, 6], [7, 9, 7]]
    23122330            sage: g.all_simple_cycles(max_length=6)
    2313             [[0, 1, 0], [0, 4, 0], [0, 5, 0], [1, 2, 1], [1, 6, 1], [2, 3, 2], [2, 7, 2], [3, 8, 3], [3, 4, 3], [4, 9, 4], [5, 8, 5], [5, 7, 5], [6, 8, 6], [6, 9, 6], [7, 9, 7], [0, 1, 2, 3, 4, 0], [0, 1, 2, 7, 5, 0], [0, 1, 6, 8, 5, 0], [0, 1, 6, 9, 4, 0], [0, 4, 9, 6, 1, 0], [0, 4, 9, 7, 5, 0], [0, 4, 3, 8, 5, 0], [0, 4, 3, 2, 1, 0], [0, 5, 8, 3, 4, 0], [0, 5, 8, 6, 1, 0], [0, 5, 7, 9, 4, 0], [0, 5, 7, 2, 1, 0], [1, 2, 3, 8, 6, 1], [1, 2, 7, 9, 6, 1], [1, 6, 8, 3, 2, 1], [1, 6, 9, 7, 2, 1], [2, 3, 8, 5, 7, 2], [2, 3, 4, 9, 7, 2], [2, 7, 9, 4, 3, 2], [2, 7, 5, 8, 3, 2], [3, 8, 6, 9, 4, 3], [3, 4, 9, 6, 8, 3], [5, 8, 6, 9, 7, 5], [5, 7, 9, 6, 8, 5], [0, 1, 2, 3, 8, 5, 0], [0, 1, 2, 7, 9, 4, 0], [0, 1, 6, 8, 3, 4, 0], [0, 1, 6, 9, 7, 5, 0], [0, 4, 9, 6, 8, 5, 0], [0, 4, 9, 7, 2, 1, 0], [0, 4, 3, 8, 6, 1, 0], [0, 4, 3, 2, 7, 5, 0], [0, 5, 8, 3, 2, 1, 0], [0, 5, 8, 6, 9, 4, 0], [0, 5, 7, 9, 6, 1, 0], [0, 5, 7, 2, 3, 4, 0], [1, 2, 3, 4, 9, 6, 1], [1, 2, 7, 5, 8, 6, 1], [1, 6, 8, 5, 7, 2, 1], [1, 6, 9, 4, 3, 2, 1], [2, 3, 8, 6, 9, 7, 2], [2, 7, 9, 6, 8, 3, 2], [3, 8, 5, 7, 9, 4, 3], [3, 4, 9, 7, 5, 8, 3]]
     2331            [[0, 1, 0], [0, 4, 0], [0, 5, 0], [1, 2, 1], [1, 6, 1], [2, 3, 2],
     2332             [2, 7, 2], [3, 8, 3], [3, 4, 3], [4, 9, 4], [5, 8, 5], [5, 7, 5],
     2333             [6, 8, 6], [6, 9, 6], [7, 9, 7], [0, 1, 2, 3, 4, 0],
     2334             [0, 1, 2, 7, 5, 0], [0, 1, 6, 8, 5, 0], [0, 1, 6, 9, 4, 0],
     2335             [0, 4, 9, 6, 1, 0], [0, 4, 9, 7, 5, 0], [0, 4, 3, 8, 5, 0],
     2336             [0, 4, 3, 2, 1, 0], [0, 5, 8, 3, 4, 0], [0, 5, 8, 6, 1, 0],
     2337             [0, 5, 7, 9, 4, 0], [0, 5, 7, 2, 1, 0], [1, 2, 3, 8, 6, 1],
     2338             [1, 2, 7, 9, 6, 1], [1, 6, 8, 3, 2, 1], [1, 6, 9, 7, 2, 1],
     2339             [2, 3, 8, 5, 7, 2], [2, 3, 4, 9, 7, 2], [2, 7, 9, 4, 3, 2],
     2340             [2, 7, 5, 8, 3, 2], [3, 8, 6, 9, 4, 3], [3, 4, 9, 6, 8, 3],
     2341             [5, 8, 6, 9, 7, 5], [5, 7, 9, 6, 8, 5], [0, 1, 2, 3, 8, 5, 0],
     2342             [0, 1, 2, 7, 9, 4, 0], [0, 1, 6, 8, 3, 4, 0],
     2343             [0, 1, 6, 9, 7, 5, 0], [0, 4, 9, 6, 8, 5, 0],
     2344             [0, 4, 9, 7, 2, 1, 0], [0, 4, 3, 8, 6, 1, 0],
     2345             [0, 4, 3, 2, 7, 5, 0], [0, 5, 8, 3, 2, 1, 0],
     2346             [0, 5, 8, 6, 9, 4, 0], [0, 5, 7, 9, 6, 1, 0],
     2347             [0, 5, 7, 2, 3, 4, 0], [1, 2, 3, 4, 9, 6, 1],
     2348             [1, 2, 7, 5, 8, 6, 1], [1, 6, 8, 5, 7, 2, 1],
     2349             [1, 6, 9, 4, 3, 2, 1], [2, 3, 8, 6, 9, 7, 2],
     2350             [2, 7, 9, 6, 8, 3, 2], [3, 8, 5, 7, 9, 4, 3],
     2351             [3, 4, 9, 7, 5, 8, 3]]
    23142352
    23152353        The complete graph (without loops) on `4` vertices::
    23162354
    23172355            sage: g = graphs.CompleteGraph(4).to_directed()
    23182356            sage: g.all_simple_cycles()
    2319             [[0, 1, 0], [0, 2, 0], [0, 3, 0], [1, 2, 1], [1, 3, 1], [2, 3, 2], [0, 1, 2, 0], [0, 1, 3, 0], [0, 2, 1, 0], [0, 2, 3, 0], [0, 3, 1, 0], [0, 3, 2, 0], [1, 2, 3, 1], [1, 3, 2, 1], [0, 1, 2, 3, 0], [0, 1, 3, 2, 0], [0, 2, 1, 3, 0], [0, 2, 3, 1, 0], [0, 3, 1, 2, 0], [0, 3, 2, 1, 0]]
     2357            [[0, 1, 0], [0, 2, 0], [0, 3, 0], [1, 2, 1], [1, 3, 1], [2, 3, 2],
     2358             [0, 1, 2, 0], [0, 1, 3, 0], [0, 2, 1, 0], [0, 2, 3, 0],
     2359             [0, 3, 1, 0], [0, 3, 2, 0], [1, 2, 3, 1], [1, 3, 2, 1],
     2360             [0, 1, 2, 3, 0], [0, 1, 3, 2, 0], [0, 2, 1, 3, 0],
     2361             [0, 2, 3, 1, 0], [0, 3, 1, 2, 0], [0, 3, 2, 1, 0]]
    23202362
    23212363        If the graph contains a large number of cycles, one can bound
    23222364        the length of the cycles, or simply restrict the possible
     
    23242366
    23252367            sage: g = graphs.CompleteGraph(20).to_directed()
    23262368            sage: g.all_simple_cycles(max_length=2)
    2327             [[0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 5, 0], [0, 6, 0], [0, 7, 0], [0, 8, 0], [0, 9, 0], [0, 10, 0], [0, 11, 0], [0, 12, 0], [0, 13, 0], [0, 14, 0], [0, 15, 0], [0, 16, 0], [0, 17, 0], [0, 18, 0], [0, 19, 0], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1], [1, 6, 1], [1, 7, 1], [1, 8, 1], [1, 9, 1], [1, 10, 1], [1, 11, 1], [1, 12, 1], [1, 13, 1], [1, 14, 1], [1, 15, 1], [1, 16, 1], [1, 17, 1], [1, 18, 1], [1, 19, 1], [2, 3, 2], [2, 4, 2], [2, 5, 2], [2, 6, 2], [2, 7, 2], [2, 8, 2], [2, 9, 2], [2, 10, 2], [2, 11, 2], [2, 12, 2], [2, 13, 2], [2, 14, 2], [2, 15, 2], [2, 16, 2], [2, 17, 2], [2, 18, 2], [2, 19, 2], [3, 4, 3], [3, 5, 3], [3, 6, 3], [3, 7, 3], [3, 8, 3], [3, 9, 3], [3, 10, 3], [3, 11, 3], [3, 12, 3], [3, 13, 3], [3, 14, 3], [3, 15, 3], [3, 16, 3], [3, 17, 3], [3, 18, 3], [3, 19, 3], [4, 5, 4], [4, 6, 4], [4, 7, 4], [4, 8, 4], [4, 9, 4], [4, 10, 4], [4, 11, 4], [4, 12, 4], [4, 13, 4], [4, 14, 4], [4, 15, 4], [4, 16, 4], [4, 17, 4], [4, 18, 4], [4, 19, 4], [5, 6, 5], [5, 7, 5], [5, 8, 5], [5, 9, 5], [5, 10, 5], [5, 11, 5], [5, 12, 5], [5, 13, 5], [5, 14, 5], [5, 15, 5], [5, 16, 5], [5, 17, 5], [5, 18, 5], [5, 19, 5], [6, 7, 6], [6, 8, 6], [6, 9, 6], [6, 10, 6], [6, 11, 6], [6, 12, 6], [6, 13, 6], [6, 14, 6], [6, 15, 6], [6, 16, 6], [6, 17, 6], [6, 18, 6], [6, 19, 6], [7, 8, 7], [7, 9, 7], [7, 10, 7], [7, 11, 7], [7, 12, 7], [7, 13, 7], [7, 14, 7], [7, 15, 7], [7, 16, 7], [7, 17, 7], [7, 18, 7], [7, 19, 7], [8, 9, 8], [8, 10, 8], [8, 11, 8], [8, 12, 8], [8, 13, 8], [8, 14, 8], [8, 15, 8], [8, 16, 8], [8, 17, 8], [8, 18, 8], [8, 19, 8], [9, 10, 9], [9, 11, 9], [9, 12, 9], [9, 13, 9], [9, 14, 9], [9, 15, 9], [9, 16, 9], [9, 17, 9], [9, 18, 9], [9, 19, 9], [10, 11, 10], [10, 12, 10], [10, 13, 10], [10, 14, 10], [10, 15, 10], [10, 16, 10], [10, 17, 10], [10, 18, 10], [10, 19, 10], [11, 12, 11], [11, 13, 11], [11, 14, 11], [11, 15, 11], [11, 16, 11], [11, 17, 11], [11, 18, 11], [11, 19, 11], [12, 13, 12], [12, 14, 12], [12, 15, 12], [12, 16, 12], [12, 17, 12], [12, 18, 12], [12, 19, 12], [13, 14, 13], [13, 15, 13], [13, 16, 13], [13, 17, 13], [13, 18, 13], [13, 19, 13], [14, 15, 14], [14, 16, 14], [14, 17, 14], [14, 18, 14], [14, 19, 14], [15, 16, 15], [15, 17, 15], [15, 18, 15], [15, 19, 15], [16, 17, 16], [16, 18, 16], [16, 19, 16], [17, 18, 17], [17, 19, 17], [18, 19, 18]]
     2369            [[0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 5, 0], [0, 6, 0],
     2370             [0, 7, 0], [0, 8, 0], [0, 9, 0], [0, 10, 0], [0, 11, 0],
     2371             [0, 12, 0], [0, 13, 0], [0, 14, 0], [0, 15, 0], [0, 16, 0],
     2372             [0, 17, 0], [0, 18, 0], [0, 19, 0], [1, 2, 1], [1, 3, 1],
     2373             [1, 4, 1], [1, 5, 1], [1, 6, 1], [1, 7, 1], [1, 8, 1], [1, 9, 1],
     2374             [1, 10, 1], [1, 11, 1], [1, 12, 1], [1, 13, 1], [1, 14, 1],
     2375             [1, 15, 1], [1, 16, 1], [1, 17, 1], [1, 18, 1], [1, 19, 1],
     2376             [2, 3, 2], [2, 4, 2], [2, 5, 2], [2, 6, 2], [2, 7, 2], [2, 8, 2],
     2377             [2, 9, 2], [2, 10, 2], [2, 11, 2], [2, 12, 2], [2, 13, 2],
     2378             [2, 14, 2], [2, 15, 2], [2, 16, 2], [2, 17, 2], [2, 18, 2],
     2379             [2, 19, 2], [3, 4, 3], [3, 5, 3], [3, 6, 3], [3, 7, 3], [3, 8, 3],
     2380             [3, 9, 3], [3, 10, 3], [3, 11, 3], [3, 12, 3], [3, 13, 3],
     2381             [3, 14, 3], [3, 15, 3], [3, 16, 3], [3, 17, 3], [3, 18, 3],
     2382             [3, 19, 3], [4, 5, 4], [4, 6, 4], [4, 7, 4], [4, 8, 4], [4, 9, 4],
     2383             [4, 10, 4], [4, 11, 4], [4, 12, 4], [4, 13, 4], [4, 14, 4],
     2384             [4, 15, 4], [4, 16, 4], [4, 17, 4], [4, 18, 4], [4, 19, 4],
     2385             [5, 6, 5], [5, 7, 5], [5, 8, 5], [5, 9, 5], [5, 10, 5],
     2386             [5, 11, 5], [5, 12, 5], [5, 13, 5], [5, 14, 5], [5, 15, 5],
     2387             [5, 16, 5], [5, 17, 5], [5, 18, 5], [5, 19, 5], [6, 7, 6],
     2388             [6, 8, 6], [6, 9, 6], [6, 10, 6], [6, 11, 6], [6, 12, 6],
     2389             [6, 13, 6], [6, 14, 6], [6, 15, 6], [6, 16, 6], [6, 17, 6],
     2390             [6, 18, 6], [6, 19, 6], [7, 8, 7], [7, 9, 7], [7, 10, 7],
     2391             [7, 11, 7], [7, 12, 7], [7, 13, 7], [7, 14, 7], [7, 15, 7],
     2392             [7, 16, 7], [7, 17, 7], [7, 18, 7], [7, 19, 7], [8, 9, 8],
     2393             [8, 10, 8], [8, 11, 8], [8, 12, 8], [8, 13, 8], [8, 14, 8],
     2394             [8, 15, 8], [8, 16, 8], [8, 17, 8], [8, 18, 8], [8, 19, 8],
     2395             [9, 10, 9], [9, 11, 9], [9, 12, 9], [9, 13, 9], [9, 14, 9],
     2396             [9, 15, 9], [9, 16, 9], [9, 17, 9], [9, 18, 9], [9, 19, 9],
     2397             [10, 11, 10], [10, 12, 10], [10, 13, 10], [10, 14, 10],
     2398             [10, 15, 10], [10, 16, 10], [10, 17, 10], [10, 18, 10],
     2399             [10, 19, 10], [11, 12, 11], [11, 13, 11], [11, 14, 11],
     2400             [11, 15, 11], [11, 16, 11], [11, 17, 11], [11, 18, 11],
     2401             [11, 19, 11], [12, 13, 12], [12, 14, 12], [12, 15, 12],
     2402             [12, 16, 12], [12, 17, 12], [12, 18, 12], [12, 19, 12],
     2403             [13, 14, 13], [13, 15, 13], [13, 16, 13], [13, 17, 13],
     2404             [13, 18, 13], [13, 19, 13], [14, 15, 14], [14, 16, 14],
     2405             [14, 17, 14], [14, 18, 14], [14, 19, 14], [15, 16, 15],
     2406             [15, 17, 15], [15, 18, 15], [15, 19, 15], [16, 17, 16],
     2407             [16, 18, 16], [16, 19, 16], [17, 18, 17], [17, 19, 17],
     2408             [18, 19, 18]]
    23282409            sage: g = graphs.CompleteGraph(20).to_directed()
    23292410            sage: g.all_simple_cycles(max_length=2, starting_vertices=[0])
    2330             [[0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 5, 0], [0, 6, 0], [0, 7, 0], [0, 8, 0], [0, 9, 0], [0, 10, 0], [0, 11, 0], [0, 12, 0], [0, 13, 0], [0, 14, 0], [0, 15, 0], [0, 16, 0], [0, 17, 0], [0, 18, 0], [0, 19, 0]]
     2411            [[0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 5, 0], [0, 6, 0],
     2412             [0, 7, 0], [0, 8, 0], [0, 9, 0], [0, 10, 0], [0, 11, 0],
     2413             [0, 12, 0], [0, 13, 0], [0, 14, 0], [0, 15, 0], [0, 16, 0],
     2414             [0, 17, 0], [0, 18, 0], [0, 19, 0]]
    23312415
    23322416        One may prefer to distinguish equivalent cycles having distinct
    23332417        starting vertices (compare the following examples)::
     
    23362420            sage: g.all_simple_cycles(max_length=2, rooted=False)
    23372421            [[0, 1, 0], [0, 2, 0], [0, 3, 0], [1, 2, 1], [1, 3, 1], [2, 3, 2]]
    23382422            sage: g.all_simple_cycles(max_length=2, rooted=True)
    2339             [[0, 1, 0], [0, 2, 0], [0, 3, 0], [1, 0, 1], [1, 2, 1], [1, 3, 1], [2, 0, 2], [2, 1, 2], [2, 3, 2], [3, 0, 3], [3, 1, 3], [3, 2, 3]]
     2423            [[0, 1, 0], [0, 2, 0], [0, 3, 0], [1, 0, 1], [1, 2, 1], [1, 3, 1],
     2424             [2, 0, 2], [2, 1, 2], [2, 3, 2], [3, 0, 3], [3, 1, 3], [3, 2, 3]]
    23402425        """
    23412426        return list(self.all_cycles_iterator(starting_vertices=starting_vertices, simple=True, rooted=rooted, max_length=max_length, trivial=trivial))
    23422427