Ticket #10885: trac_10885-documentation.patch

File trac_10885-documentation.patch, 2.3 KB (added by ncohen, 10 years ago)
  • sage/graphs/base/c_graph.pyx

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1299851243 -28800
    # Node ID f6845ff13199ead24788ea586ec3f0749f7f51d9
    # Parent  189e11e80258728a10e0fa5f41dddb4a3c5a38b8
    trac 10885 -- Floyd-Warshall algorithm in Cython (documentation)
    
    diff -r 189e11e80258 -r f6845ff13199 sage/graphs/base/c_graph.pyx
    a b  
    28902890        for a total of `2^{34}` bytes or `16` gigabytes. Let us also remember
    28912891        that if the memory size is quadratic, the algorithm runs in cubic time.
    28922892
     2893    .. NOTE::
     2894
     2895        When ``paths = False`` the algorithm saves roughly half of the memory as
     2896        it does not have to maintain the matrix of predecessors. However,
     2897        setting ``distances=False`` produces no such effect as the algorithm can
     2898        not run without computing them. They will not be returned, but they will
     2899        be stored while the method is running.
     2900
    28932901    EXAMPLES:
    28942902
    28952903    Shortest paths in a small grid ::
     
    29172925        ...     p.insert(0,path[u][p[0]])
    29182926        sage: len(p) == dist[u][v] + 2
    29192927        True
     2928
     2929    Distances for all pairs of vertices in a diamond::
     2930
     2931        sage: g = graphs.DiamondGraph()
     2932        sage: floyd_warshall(g, paths = False, distances = True)
     2933        {0: {0: 0, 1: 1, 2: 1, 3: 2},
     2934         1: {0: 1, 1: 0, 2: 1, 3: 1},
     2935         2: {0: 1, 1: 1, 2: 0, 3: 1},
     2936         3: {0: 2, 1: 1, 2: 1, 3: 0}}
     2937
     2938    TESTS:
     2939
     2940    Too large graphs::
     2941
     2942        sage: from sage.graphs.base.c_graph import floyd_warshall
     2943        sage: floyd_warshall(Graph(65536))
     2944        Traceback (most recent call last):
     2945        ...
     2946        ValueError: The graph backend contains more than 65535 nodes
    29202947    """
     2948
    29212949    from sage.rings.infinity import Infinity
    29222950    cdef CGraph g = <CGraph> gg._backend._cg
    29232951
     
    29252953
    29262954    cdef int n = max(gverts) + 1
    29272955
    2928     if n > <unsigned short> -1:
    2929         raise ValueError("The graph backend contains more than "+(<unsigned short> -1)+" nodes")
     2956    if n >= <unsigned short> -1:
     2957        raise ValueError("The graph backend contains more than "+str(<unsigned short> -1)+" nodes")
    29302958
    29312959    # All this just creates two tables prec[n][n] and dist[n][n]
    29322960    cdef unsigned short * t_prec