<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>allPairsShortestPath -- computes lengths of shortest paths between all pairs in a directed graph</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_compare.html">next</a> | <a href="_adjacency__Matrix.html">previous</a> | <a href="_compare.html">forward</a> | <a href="_adjacency__Matrix.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <hr/> <div><h1>allPairsShortestPath -- computes lengths of shortest paths between all pairs in a directed graph</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>D = allPairsShortestPath(G)</tt><br/><tt>D = allPairsShortestPath(A)</tt></div> </dd></dl> </div> </li> <li><div class="single">Inputs:<ul><li><span><tt>G</tt>, <span>an object of class <a href="___Directed__Graph.html" title="a class for directed graphs">DirectedGraph</a></span></span></li> <li><span><tt>A</tt>, <span>a <a href="../../Macaulay2Doc/html/___Matrix.html">matrix</a></span>, adjacency matrix of a directed graph, whose (i,j) entry is the length of the directed edge from i to j and is infinity (1/0.) if there is no such directed edge.</span></li> </ul> </div> </li> <li><div class="single">Outputs:<ul><li><span><tt>D</tt>, <span>a <a href="../../Macaulay2Doc/html/___Matrix.html">matrix</a></span>, whose (i,j) entry is the length of the shortest path from i to j and is infinity if there is no directed path from i to j.</span></li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div><div>This function uses the Floyd-Warshall algorithm to compute the lengths of shortest paths between all pairs of vertices in a directed graph.</div> <table class="examples"><tr><td><pre>i1 : G = directedGraph( {a,b,c,d,e}, {(a,b),(b,c),(a,c),(a,d),(d,e)});</pre> </td></tr> <tr><td><pre>i2 : allPairsShortestPath(G) o2 = | 0 1 1 1 2 | | infinity 0 1 infinity infinity | | infinity infinity 0 infinity infinity | | infinity infinity infinity 0 1 | | infinity infinity infinity infinity 0 | 5 5 o2 : Matrix RR <--- RR 53 53</pre> </td></tr> <tr><td><pre>i3 : allPairsShortestPath(adjacencyMatrix(G)) o3 = | 0 1 1 1 2 | | infinity 0 1 infinity infinity | | infinity infinity 0 infinity infinity | | infinity infinity infinity 0 1 | | infinity infinity infinity infinity 0 | 5 5 o3 : Matrix RR <--- RR 53 53</pre> </td></tr> <tr><td><pre>i4 : A = matrix({{0,1,3,5},{1/0.,0,1,3},{1/0.,1/0.,0,1},{2,1/0.,1/0.,0}}) o4 = | 0 1 3 5 | | infinity 0 1 3 | | infinity infinity 0 1 | | 2 infinity infinity 0 | 4 4 o4 : Matrix RR <--- RR 53 53</pre> </td></tr> <tr><td><pre>i5 : allPairsShortestPath(A) o5 = | 0 1 2 3 | | 4 0 1 2 | | 3 4 0 1 | | 2 3 4 0 | 4 4 o5 : Matrix RR <--- RR 53 53</pre> </td></tr> </table> </div> </div> <div class="single"><h2>Caveat</h2> <div><div>Assume there is no negative cycles. Output matrix is over RR.</div> </div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="___Directed__Graph.html" title="a class for directed graphs">DirectedGraph</a> -- a class for directed graphs</span></li> <li><span><a href="_adjacency__Matrix.html" title="returns adjacency matrix of a directed graph">adjacencyMatrix</a> -- returns adjacency matrix of a directed graph</span></li> </ul> </div> <div class="waystouse"><h2>Ways to use <tt>allPairsShortestPath</tt> :</h2> <ul><li>allPairsShortestPath(DirectedGraph)</li> <li>allPairsShortestPath(Matrix)</li> </ul> </div> </div> </body> </html>