# HG changeset patch
# User Nathann Cohen
# 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/sage/graphs/base/c_graph.pyx Thu Mar 10 23:10:50 2011 +0100
+++ b/sage/graphs/base/c_graph.pyx Fri Mar 11 21:47:23 2011 +0800
@@ -2890,6 +2890,14 @@
for a total of `2^{34}` bytes or `16` gigabytes. Let us also remember
that if the memory size is quadratic, the algorithm runs in cubic time.
+ .. NOTE::
+
+ When ``paths = False`` the algorithm saves roughly half of the memory as
+ it does not have to maintain the matrix of predecessors. However,
+ setting ``distances=False`` produces no such effect as the algorithm can
+ not run without computing them. They will not be returned, but they will
+ be stored while the method is running.
+
EXAMPLES:
Shortest paths in a small grid ::
@@ -2917,7 +2925,27 @@
... p.insert(0,path[u][p[0]])
sage: len(p) == dist[u][v] + 2
True
+
+ Distances for all pairs of vertices in a diamond::
+
+ sage: g = graphs.DiamondGraph()
+ sage: floyd_warshall(g, paths = False, distances = True)
+ {0: {0: 0, 1: 1, 2: 1, 3: 2},
+ 1: {0: 1, 1: 0, 2: 1, 3: 1},
+ 2: {0: 1, 1: 1, 2: 0, 3: 1},
+ 3: {0: 2, 1: 1, 2: 1, 3: 0}}
+
+ TESTS:
+
+ Too large graphs::
+
+ sage: from sage.graphs.base.c_graph import floyd_warshall
+ sage: floyd_warshall(Graph(65536))
+ Traceback (most recent call last):
+ ...
+ ValueError: The graph backend contains more than 65535 nodes
"""
+
from sage.rings.infinity import Infinity
cdef CGraph g = gg._backend._cg
@@ -2925,8 +2953,8 @@
cdef int n = max(gverts) + 1
- if n > -1:
- raise ValueError("The graph backend contains more than "+( -1)+" nodes")
+ if n >= -1:
+ raise ValueError("The graph backend contains more than "+str( -1)+" nodes")
# All this just creates two tables prec[n][n] and dist[n][n]
cdef unsigned short * t_prec