4.0

4.0 | 6 ratings Rate this file 171 downloads (last 30 days) File Size: 2.96 KB File ID: #8808

"All Pairs Shortest Path" Graph Solver

by Michael Kleder

 

24 Oct 2005 (Updated 26 Dec 2007)

No BSD License  

Gives the shortest node-to-node distance along the edges of a graph for all node combinations.

Download Now | Watch this File

File Information
Description

ALLSPATH - solve the All Pairs Shortest Path problem

Rapidly returns the shortest node-to-node distance along the edges of a graph, for all nodes in the graph.

USAGE: B = allspath(A)

A = input distance matrix between nodes

B = shortest path distance matrix between all nodes

Notes:
(1) For a graph with n nodes, A is an n-by-n distance matrix giving the distances between adjacent nodes. Since the distance from point i to point j is the same as the distance from point j to point i, A must be a symmetric matrix
(2) The distance from a node to itself can either be entered as zero or infinity. (Either will produce a correct result.) This means that the diagonal elements of the matrix A must all be either zero or infinity.
(3) The distance between nodes that are not adjacent to each other must be entered as either zero or infinity. (Either will produce a correct result.) This means that the (i,j) and (j,i) elements of A, where i and j are non-adjacent nodes, must all be either zero or infinity.
(4) If the input graph is not "connected," meaning that some nodes cannot be reached from other nodes no matter how many edges are traversed, then the distances between nodes that cannot be connected will be returned as infinite.
(5) Distances between a node and itself are returned as zero.
(6) This function codifies an original algorithm created by the author.
(7) No warranties; use at your own risk.
(8) Written by Michael Kleder, October 2005.

Acknowledgements
This submission has inspired the following:
Advanced Dijkstra's Minimum Path Algorithm
MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (10)
09 Dec 2005 LIU Jerry

It is indeed useful for my research!

26 Apr 2006 giuseppe d

But what happens it the graph is not undirected? I think it doesn't work...

27 Apr 2006 giuseppe d

There are a limit whenever we have a large graph. Out of memory proble...
Somebody tried?
G

29 Jun 2006 Kyaw Tun

It give out of memory error even though my graph has only 702 nodes. :-)

16 Oct 2006 Dead Beat

Doesn't work, fails with a "??? Out of memory. Type HELP MEMORY for your options." even tho my graph has 600 nodes & I have 1GB of RAM!

26 Oct 2006 David Leamer

What a beautifully compact algorithm! Works fast for up to about 200-250 nodes. For more than that it works but uses a lot of memory. This is really*great for smallish (about 200 nodes) investigational type problems that I'm working on right now.

14 Apr 2007 John S

Works great for me, < 200-ish nodes. Thanks!

18 May 2007 Joseph Kirk

The example didn't work for me...
??? Undefined function or method 'pdist' for input arguments of type 'double'.
Do I need a special toolbox for this?

21 May 2007 The Author

Thank you. PDIST does require the Statistics Toolbox, so I have removed it from the example and uploaded a replacement submission where the example does not use PDIST.

23 May 2007 Joseph Kirk

Thank you for putting in the effort to update the file with the new example for those of us lacking the Statistics Toolbox. :)

However, I still had some difficulty testing it. References were made to variables 'a' and 'b' that did not exist. I was able to run the example when I added the following code after "% distance matrix:"

>> k=(1:10); a=k(ones(1,10),:); b=a';

Please login to add a comment or rating.
Updates
26 Oct 2005

typographical updates to comments and file exchange page

22 May 2007

Replaced a Statistics Toolbox function call from the provided example for use by users without the Statistics Toolbox.

26 Dec 2007

Fixed a bug in the example. (An index variable had been omitted. Thanks to Joseph Kirk for pointing out the bug.)

Tag Activity for this File
Tag Applied By Date/Time
optimization Michael Kleder 22 Oct 2008 08:04:20
graph Michael Kleder 22 Oct 2008 08:04:20
node Michael Kleder 22 Oct 2008 08:04:20
all pairs Michael Kleder 22 Oct 2008 08:04:20
shortest path Michael Kleder 22 Oct 2008 08:04:20
graph Michael J 23 Jan 2009 12:04:38
shortest path Michael J 23 Jan 2009 12:04:42
all pairs Michael J 23 Jan 2009 12:04:50
node Michael J 23 Jan 2009 12:04:51
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com